Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Create()
- {
- return View();
- }
- [HttpPost]
- public ActionResult Create(FormCollection collection)
- {
- try
- {
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- public class UserMasterRepository : IUserMasterRepository
- {
- private List<UserMaster> users = new List<UserMaster>();
- string connectionstring = @"Data Source="";Initial
- Catalog=DI;User ID=ma;Password=***********";
- public UserMaster Add(UserMaster item)
- {
- using (SqlConnection sqlCon = new SqlConnection(connectionstring))
- {
- sqlCon.Open();
- string query = "INSERT INTO Product (@ID,@Name,@City,@Address)
- Values(ID,Name,City,Address)";
- for (int i = 0; i <= 100; i++)
- {
- SqlCommand sqlcmd = new SqlCommand(query, sqlCon);
- sqlcmd.Parameters.Add("@ID", SqlDbType.Int).Value = i;
- sqlcmd.Parameters.Add("@Name", SqlDbType.VarChar,
- 100).Value = "newride";
- sqlcmd.Parameters.Add("@City", SqlDbType.VarChar,
- 100).Value = "newride";
- sqlcmd.Parameters.Add("@Address", SqlDbType.VarChar,
- 100).Value = "USA";
- sqlcmd.ExecuteNonQuery();
- }
- return item;
- }
- public static void RegisterRoutes(RouteCollection routes)
- {
- routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "User", action = "Index", id =
- UrlParameter.Optional }
- );
- }
- public static class UnityConfig
- {
- public static Type IUserRepository { get; private set; }
- public static void RegisterComponents()
- {
- var container = new UnityContainer();
- container.RegisterType<IUserMasterRepository,
- UserMasterRepository>
- ();
- DependencyResolver.SetResolver(new
- UnityDependencyResolver(container));
- }}
- public interface IUserMasterRepository
- {
- IEnumerable<UserMaster> GetAll();
- UserMaster Get(int id);
- UserMaster Add(UserMaster item);
- bool Update(UserMaster item);
- bool Delete(int id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement