public async Task AddOrUpdate(RentalFormViewModel obj) { obj.UserId = "001122"; var moviesRental = new List <MovieRental>(); foreach (var item in obj.MovieRentals.Where(x => x.Rental == true)) { moviesRental.Add(new MovieRental() { MovieId = item.Id, RentalId = obj.Id }); } var itemAdd = new Rental() { Id = obj.Id, DateRental = DateTime.Now, UserId = obj.UserId, MovieRentals = moviesRental }; if (itemAdd.Id == 0) { itemAdd.DateRental = DateTime.Now; await _base_repository_rental.Add(itemAdd); } else { await _base_repository_rental.Update(itemAdd); } }
public async Task <IActionResult> CreateOrUpdate(Genre model) { if (model.Id != 0) { await _base_repository.Update(model); } else { model.DateCreated = DateTime.Now; await _base_repository.Add(model); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Put([FromBody] Event item) { try { var getItem = await _eventRepository.GetById(item.Id); if (getItem != null) { await _eventRepository.Update(item); return(Ok()); } return(NotFound()); } catch (Exception ex) { _logger.LogError(ex, $"{LocalLog}[Put][Item: {JsonConvert.SerializeObject(item)}]"); throw ex; } }
public async Task <ActionResult> Put([FromBody] EventUser item) { try { var result = await _eventUserRepository.GetAll( f => f.Where(x => x.EventId == item.EventId && x.UserId == item.UserId) ); if (result.Any()) { await _eventUserRepository.Update(item); return(Ok()); } return(NotFound()); } catch (Exception ex) { _logger.LogError(ex, $"{LocalLog}[Put][Item: {JsonConvert.SerializeObject(item)}]"); throw ex; } }