Exemplo n.º 1
0
 public IActionResult Post([FromBody] BORental rent)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(facade.RentalService.Create(rent)));
 }
Exemplo n.º 2
0
 public BORental Create(BORental rent)
 {
     using (var uow = facade.UnitOfWork)
     {
         var rentalEntity = uow.RentalRepository.Create(conv.Convert(rent));
         uow.Complete();
         return(conv.Convert(rentalEntity));
     }
 }
Exemplo n.º 3
0
 /// <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
     });
 }
Exemplo n.º 4
0
 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));
     }
 }
Exemplo n.º 5
0
        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));
            }
        }