Ejemplo n.º 1
0
 public ActionResult Create(LearningMVCWithCF.Models.User userDetails)
 {
     try
     {
         using (var dbContext = new MVCDBContext())
         {
             var user = new User();
             if (userDetails != null)
             {
                 user.UserId      = userDetails.UserId;
                 user.FirstName   = userDetails.FirstName;
                 user.LastName    = userDetails.LastName;
                 user.Address     = userDetails.Address;
                 user.PhoneNo     = userDetails.PhoneNo;
                 user.EMail       = userDetails.EMail;
                 user.Company     = userDetails.Company;
                 user.Designation = userDetails.Designation;
             }
             dbContext.Users.Add(user);
             dbContext.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
     }
     catch (Exception)
     {
         return(View());
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Get Action for index
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     using (var dbContext = new MVCDBContext())
     {
         var userList = from user in dbContext.Users select user;
         var users    = new List <LearningMVCWithCF.Models.User>();
         if (userList.Any())
         {
             foreach (var user in userList)
             {
                 users.Add(new LearningMVCWithCF.Models.User()
                 {
                     UserId = user.UserId, Address = user.Address, Company = user.Company, FirstName = user.FirstName, LastName = user.LastName, Designation = user.Designation, EMail = user.EMail, PhoneNo = user.PhoneNo
                 });
             }
         }
         ViewBag.FirstName     = "My First Name";
         ViewData["FirstName"] = "My First Name";
         if (TempData.Any())
         {
             var tempData = TempData["TempData Name"];
         }
         return(View(users));
     }
 }
Ejemplo n.º 3
0
        public ActionResult Edit(int?id, User userDetails)
        {
            TempData["TempData Name"] = "Akhil";

            try
            {
                using (var dbContext = new MVCDBContext())
                {
                    var user = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
                    if (user != null)
                    {
                        user.FirstName   = userDetails.FirstName;
                        user.LastName    = userDetails.LastName;
                        user.Address     = userDetails.Address;
                        user.PhoneNo     = userDetails.PhoneNo;
                        user.EMail       = userDetails.EMail;
                        user.Company     = userDetails.Company;
                        user.Designation = userDetails.Designation;
                        dbContext.SaveChanges();
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Get Action for Delete
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Delete(int?id)
 {
     using (var dbContext = new MVCDBContext())
     {
         var user        = new LearningMVCWithCF.Models.User();
         var userDetails = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
         if (userDetails != null)
         {
             user.FirstName   = userDetails.FirstName;
             user.LastName    = userDetails.LastName;
             user.Address     = userDetails.Address;
             user.PhoneNo     = userDetails.PhoneNo;
             user.EMail       = userDetails.EMail;
             user.Company     = userDetails.Company;
             user.Designation = userDetails.Designation;
         }
         return(View(user));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Delete(int?id, User userDetails)
        {
            try
            {
                using (var dbContext = new MVCDBContext())
                {
                    var user = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
                    if (user != null)
                    {
                        dbContext.Users.Add(user);
                        dbContext.SaveChanges();
                    }

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }