Exemplo n.º 1
0
 public IActionResult Post([FromBody] RentalBO rentalbo)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(facade.RentalServices.Create(rentalbo)));
 }
Exemplo n.º 2
0
 public RentalBO Add(RentalBO rental)
 {
     using (var uow = _facade.UnitOfWork)
     {
         var rentalEntity = uow.RentalRepository.Add(conv.Convert(rental));
         uow.Complete();
         return(conv.Convert(rentalEntity));
     }
 }
Exemplo n.º 3
0
 internal Rental convert(RentalBO rental)
 {
     return(new Rental()
     {
         Id = rental.Id,
         From = rental.From,
         To = rental.To
     });
 }
Exemplo n.º 4
0
 public RentalBO Create(RentalBO Ren)
 {
     using (var uow = _facade.UnitOfWork)
     {
         var rentalEntity = uow.RentalRepository.Create(conv.Convert(Ren));
         uow.Complete();
         return(conv.Convert(rentalEntity));
     }
 }
Exemplo n.º 5
0
        public IActionResult Post([FromBody] RentalBO Ren)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var Rental = facade.RentalService.Create(Ren);

            return(Ok(Rental));
        }
Exemplo n.º 6
0
 public Rental Convert(RentalBO rental)
 {
     return(new Rental()
     {
         RentalId = rental.Id,
         DeliveryDate = rental.DeliveryDate,
         OrderDate = rental.OrderDate,
         MovieID = rental.MovieID
     });
 }
 public IActionResult Put(int id, [FromBody] RentalBO rental)
 {
     try
     {
         return(Ok(_facade.RentalService.Update(rental)));
     }
     catch (Exception)
     {
         return(BadRequest($"Couldn't update the rental with the id {rental.Id}."));
     }
 }
Exemplo n.º 8
0
 public RentalBO Create(RentalBO rental)
 {
     if (rental == null)
     {
         return(null);
     }
     using (var unitOfWork = _facade.UnitOfWork)
     {
         var createdRental = unitOfWork.RentalRepository.Create(_converter.Convert(rental));
         unitOfWork.Complete();
         return(_converter.Convert(createdRental));
     }
 }
Exemplo n.º 9
0
 internal Rental Convert(RentalBO Ren)
 {
     if (Ren == null)
     {
         return(null);
     }
     return(new Rental()
     {
         Id = Ren.Id,
         From = Ren.From,
         To = Ren.To,
         Video = new VideoConverter().Convert(Ren.Video)
     });
 }
Exemplo n.º 10
0
 public IActionResult Put(int id, [FromBody] RentalBO rentalbo)
 {
     if (id != rentalbo.Id)
     {
         return(StatusCode(405, "Path id does not match rental ID json object"));
     }
     try
     {
         return(Ok(facade.RentalServices.Update(rentalbo)));
     }
     catch (InvalidOperationException e)
     {
         return(StatusCode(404, e.Message));
     }
 }
Exemplo n.º 11
0
 public RentalBO Update(RentalBO rental)
 {
     using (var uow = _facade.UniteOfWork)
     {
         var rentalEntity = uow.RentalRepository.Get(rental.Id);
         if (rentalEntity == null)
         {
             throw new InvalidOperationException("rental not found");
         }
         rentalEntity.From = rentalEntity.From;
         rentalEntity.To   = rentalEntity.To;
         uow.Complete();
         return(conv.convert(rentalEntity));
     }
 }
Exemplo n.º 12
0
 public IActionResult Put(int id, [FromBody] RentalBO rental)
 {
     if (id != rental.Id)
     {
         return(BadRequest("Path ID does not match video ID in JSON object."));
     }
     try
     {
         return(Ok(facade.RentalService.Update(rental)));
     }
     catch (InvalidOperationException e)
     {
         return(StatusCode(404, e.Message));
     }
 }
Exemplo n.º 13
0
 public IActionResult Put(int id, [FromBody] RentalBO Ren)
 {
     if (id != Ren.Id)
     {
         return(BadRequest("Path id does not match rental Id in json"));
     }
     try
     {
         var rental = facade.RentalService.Update(Ren);
         return(Ok(rental));
     }
     catch (InvalidOperationException e)
     {
         return(StatusCode(404, e.Message));
     }
 }
Exemplo n.º 14
0
 public IActionResult Put(int id, [FromBody] RentalBO rental)
 {
     if (id != rental.Id)
     {
         return(BadRequest("Path id does not match a movie"));
     }
     try
     {
         var rentalUpdated = facade.RentalService.Update(rental);
         return(Ok(rentalUpdated));
     }
     catch (InvalidOperationException e)
     {
         return(StatusCode(404, e.Message));
     }
 }
        public Rental Convert(RentalBO rental)
        {
            if (rental == null)
            {
                return(null);
            }

            return(new Rental
            {
                Id = rental.Id,
                From = rental.From,
                To = rental.To,
                UserId = rental.UserId,
                VideoId = rental.VideoId
            });
        }
Exemplo n.º 16
0
        public RentalBO Update(RentalBO rentalToUpdate)
        {
            using (var unitOfWork = _facade.UnitOfWork)
            {
                var rental = unitOfWork.RentalRepository.GetById(rentalToUpdate.Id);
                if (rental == null)
                {
                    return(null);
                }

                rental.From = rentalToUpdate.From;
                rental.To   = rentalToUpdate.To;
                unitOfWork.RentalRepository.Update(rental);
                return(_converter.Convert(rental));
            }
        }
Exemplo n.º 17
0
        public IActionResult Post([FromBody] RentalBO rental)
        {
            if (!TryValidateModel(rental))
            {
                return(BadRequest(ModelState.IsValid));
            }
            var rent = facade.RentalService.Add(rental);

            if (rent != null)
            {
                return(Ok(rent));
            }
            else
            {
                return(BadRequest("ID already exists."));
            }
        }
Exemplo n.º 18
0
 internal Rental Convert(RentalBO rental)
 {
     if (rental != null)
     {
         return(new Rental()
         {
             Id = rental.Id,
             RentalDate = rental.RentalDate,
             DeliveryDate = rental.DeliveryDate,
             VideoId = rental.VideoId
         });
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 19
0
        public RentalBO Update(RentalBO rental)
        {
            using (var uow = _facade.UnitOfWork)
            {
                var rentalEntity = uow.RentalRepository.Get(rental.Id);
                if (rentalEntity == null)
                {
                    throw new InvalidOperationException("Rental not found");
                }
                rentalEntity.DeliveryDate = rental.DeliveryDate;
                rentalEntity.OrderDate    = rental.OrderDate;
                rentalEntity.MovieID      = rentalEntity.MovieID;
                uow.Complete();


                rentalEntity.Movie = uow.MovieRepository.Get(rentalEntity.MovieID);
                return(conv.Convert(rentalEntity));
            }
        }
Exemplo n.º 20
0
 public RentalBO Update(RentalBO rental)
 {
     using (var uow = _facade.UnitOfWork)
     {
         var RentalEntity = uow.RentalRepository.Get(rental.Id);
         if (RentalEntity != null)
         {
             uow.RentalRepository.Get(RentalEntity.Id).DeliveryDate = rental.DeliveryDate;
             uow.RentalRepository.Get(RentalEntity.Id).RentalDate   = rental.RentalDate;
             uow.RentalRepository.Get(RentalEntity.Id).VideoId      = rental.VideoId;
             uow.Complete();
             RentalEntity.Video = uow.VideoRepository.Get(RentalEntity.VideoId);
             return(conv.Convert(RentalEntity));
         }
         else
         {
             throw new InvalidOperationException("Rental not found.");
         }
     }
 }