public ActionResult Create(Student studentObj) { dbContext.Student.Add(studentObj); dbContext.SaveChanges(); return(RedirectToAction("Index")); }
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()); } }
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()); } }
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()); } }