public IActionResult Post([FromBody] BORental rent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(facade.RentalService.Create(rent))); }
public BORental Create(BORental rent) { using (var uow = facade.UnitOfWork) { var rentalEntity = uow.RentalRepository.Create(conv.Convert(rent)); uow.Complete(); return(conv.Convert(rentalEntity)); } }
/// <summary> /// Sending/saving data to database. /// </summary> /// <returns>The convert.</returns> /// <param name="gen">Gen.</param> internal Rental Convert(BORental rent) { if (rent == null) { return(null); } return(new Rental() { Id = rent.Id, DeliveryDate = rent.DeliveryDate, RentalDate = rent.RentalDate, // Video = new VideoConverter().Convert(rent.Video), VideoId = rent.VideoId }); }
public IActionResult Put(int id, [FromBody] BORental rent) { if (id != rent.Id) { return(StatusCode(405, "Path Id didn't match the Customer's Id in json object")); } try { var rental = facade.RentalService.Update(rent); return(Ok(rental)); } catch (Exception e) { return(StatusCode(404, e.Message)); } }
public BORental Update(BORental rent) { using (var uow = facade.UnitOfWork) { var rentalEntity = uow.RentalRepository.Get(rent.Id); if (rentalEntity == null) { throw new InvalidOperationException("Rental not found"); } rentalEntity.DeliveryDate = rent.DeliveryDate; rentalEntity.RentalDate = rent.RentalDate; rentalEntity.VideoId = rent.VideoId; uow.Complete(); // BLL choice -- "If we want to get all the information of the Video" rentalEntity.Video = uow.VideoRepository.Get(rentalEntity.VideoId); return(conv.Convert(rentalEntity)); } }