public IActionResult CreateCustomer(CustomerDto customerDto) { var customer = _mapper.Map <CustomerDto, Customer>(customerDto); _context.Customers.Add(customer); _context.SaveChanges(); customerDto.Id = customer.Id; return(Created(new Uri(Request.Path + customer.Id, UriKind.Relative), customerDto)); }
public IActionResult CreateMovie(MovieDto movieDto) { var movie = _mapper.Map <MovieDto, Movie>(movieDto); _context.Add(movie); _context.SaveChanges(); movieDto.Id = movie.Id; return(Created(new Uri(Request.Path + movie.Id, UriKind.Relative), movieDto)); }
public IActionResult Save(Movie movie) { if (!ModelState.IsValid) { var viewModel = new MovieFormViewModel(movie) { Genres = _context.Genres.ToList() }; return(View("MovieForm", viewModel)); } if (movie.Id == 0) { _context.Movies.Add(movie); } else { var movieInDb = _context.Movies.Single(m => m.Id == movie.Id); movieInDb.Name = movie.Name; movieInDb.ReleaseDate = movie.ReleaseDate; movieInDb.GenreId = movie.GenreId; movieInDb.NumberInStock = movie.NumberInStock; } _context.SaveChanges(); return(RedirectToAction("Index", "Movies")); }
public IActionResult Save(Customer customer) { if (!ModelState.IsValid) { var viewModel = new CustomerFormViewModel { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return(View("CustomerForm", viewModel)); } if (customer.Id == 0) { _context.Customers.Add(customer); } else { var customerInDb = _context.Customers.Single(c => c.Id == customer.Id); customerInDb.Name = customer.Name; customerInDb.Birthdate = customer.Birthdate; customerInDb.MembershipTypeId = customer.MembershipTypeId; customerInDb.IsSubscribedToNewsLetter = customer.IsSubscribedToNewsLetter; } _context.SaveChanges(); return(RedirectToAction("Index", "Customers")); }
public void DeleteRoom(int roomId) { Room dbEntry = context.Rooms .FirstOrDefault(data => data.Id == roomId); if (dbEntry != null) { context.Rooms.Remove(dbEntry); context.SaveChanges(); } }
public void DeleteRanking(string playerId) { var dbEntries = context.Rankings .Where(ranking => ranking.UserId == playerId); foreach (var entity in dbEntries) { if (entity != null) { context.Rankings.Remove(entity); } } context.SaveChanges(); }