public IActionResult register(User user) { if (ModelState.IsValid) { // If a User exists with provided email if (db.Users.Any(u => u.Email == user.Email)) { // Manually add a ModelState error to the Email field, with provided // error message ModelState.AddModelError("Email", "Email already in use!"); // You may consider returning to the View at this point return(View()); } PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); db.Users.Add(user); db.SaveChanges(); User Userdb = db.Users.FirstOrDefault(u => u.Email == user.Email); HttpContext.Session.SetInt32("User", Userdb.UserId); HttpContext.Session.SetString("PassH", Userdb.Password); return(RedirectToAction("success")); } return(View()); }
public IHttpActionResult CreateMovie(MovieDto movDto) { if (!ModelState.IsValid) { return(BadRequest()); } var mov = Mapper.Map <MovieDto, Movie>(movDto); _context.Movies.Add(mov); _context.SaveChanges(); movDto.id = mov.id; return(Created(new Uri(Request.RequestUri + "/" + mov.id), movDto)); }
public IHttpActionResult CreateCustumer(CustomerDto customer) { if (!ModelState.IsValid) { return(BadRequest()); } var cust = Mapper.Map <CustomerDto, Customer>(customer); _context.Customers.Add(cust); _context.SaveChanges(); customer.id = cust.id; return(Created(Request.RequestUri + "/" + customer.id, customer)); }
public ActionResult Save(ManageMoviesViewModel MovieVM) { var gen = _context.Genre.ToList(); var mov = MovieVM.movie; var vm = new ManageMoviesViewModel { movie = mov, Genres = gen }; if (!ModelState.IsValid) { if (MovieVM.movie.id == 0) { vm.movie.id = 0; return(View("Add", vm)); } else { return(View("Edit", vm)); } } if (MovieVM.movie.id == 0) { _context.Movies.Add(MovieVM.movie); } else { var oldMovie = _context.Movies.Single(m => m.id == MovieVM.movie.id); //oldMovie.name = MovieVM.Movie.name; //oldMovie.releaseDate = MovieVM.Movie.releaseDate; //oldMovie.stock = MovieVM.Movie.stock; //oldMovie.genre = MovieVM.Movie.genre; oldMovie = MovieVM.movie; } _context.SaveChanges(); return(RedirectToAction("Index", "Movie")); }
public ActionResult Save(ManageCustomerViewModel cust) { var customer = cust.Customer; var mem = _context.MembershipType.ToList(); var vm = new ManageCustomerViewModel { Customer = customer, MembershipTypes = mem }; if (!ModelState.IsValid) { if (cust.Customer.id == 0) { return(View("Add", vm)); } else { return(View("Edit", vm)); } } if (cust.Customer.id == 0) { _context.Customers.Add(cust.Customer); } else { var oldCust = _context.Customers.Single(c => c.id == cust.Customer.id); //oldCust.name = cust.Customer.name; //oldCust.isSubscribed = cust.Customer.isSubscribed; //oldCust.birthdate = cust.Customer.birthdate; //oldCust.MembershipType = cust.Customer.MembershipType; oldCust = cust.Customer; } _context.SaveChanges(); return(RedirectToAction("Index", "Customer")); }