示例#1
0
        public ActionResult Create(Student studentObj)
        {
            dbContext.Student.Add(studentObj);
            dbContext.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#2
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());
     }
 }
示例#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());
            }
        }
示例#4
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());
            }
        }