Beispiel #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());
     }
 }
Beispiel #2
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));
     }
 }