Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. public ActionResult Create()
  2. {
  3. return View();
  4. }
  5. [HttpPost]
  6.  
  7. public ActionResult Create(FormCollection collection)
  8. {
  9. try
  10. {
  11. return RedirectToAction("Index");
  12. }
  13. catch
  14. {
  15. return View();
  16. }
  17. }
  18.  
  19. public class UserMasterRepository : IUserMasterRepository
  20. {
  21. private List<UserMaster> users = new List<UserMaster>();
  22. string connectionstring = @"Data Source="";Initial
  23. Catalog=DI;User ID=ma;Password=***********";
  24.  
  25. public UserMaster Add(UserMaster item)
  26. {
  27. using (SqlConnection sqlCon = new SqlConnection(connectionstring))
  28. {
  29. sqlCon.Open();
  30.  
  31. string query = "INSERT INTO Product (@ID,@Name,@City,@Address)
  32. Values(ID,Name,City,Address)";
  33.  
  34.  
  35. for (int i = 0; i <= 100; i++)
  36. {
  37. SqlCommand sqlcmd = new SqlCommand(query, sqlCon);
  38. sqlcmd.Parameters.Add("@ID", SqlDbType.Int).Value = i;
  39. sqlcmd.Parameters.Add("@Name", SqlDbType.VarChar,
  40. 100).Value = "newride";
  41. sqlcmd.Parameters.Add("@City", SqlDbType.VarChar,
  42. 100).Value = "newride";
  43. sqlcmd.Parameters.Add("@Address", SqlDbType.VarChar,
  44. 100).Value = "USA";
  45. sqlcmd.ExecuteNonQuery();
  46.  
  47. }
  48. return item;
  49. }
  50.  
  51. public static void RegisterRoutes(RouteCollection routes)
  52. {
  53. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  54.  
  55. routes.MapRoute(
  56. name: "Default",
  57. url: "{controller}/{action}/{id}",
  58. defaults: new { controller = "User", action = "Index", id =
  59. UrlParameter.Optional }
  60. );
  61. }
  62.  
  63. public static class UnityConfig
  64. {
  65. public static Type IUserRepository { get; private set; }
  66.  
  67. public static void RegisterComponents()
  68. {
  69. var container = new UnityContainer();
  70.  
  71. container.RegisterType<IUserMasterRepository,
  72. UserMasterRepository>
  73. ();
  74. DependencyResolver.SetResolver(new
  75. UnityDependencyResolver(container));
  76. }}
  77.  
  78. public interface IUserMasterRepository
  79. {
  80. IEnumerable<UserMaster> GetAll();
  81. UserMaster Get(int id);
  82. UserMaster Add(UserMaster item);
  83. bool Update(UserMaster item);
  84. bool Delete(int id);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement