public ObjectResponse <bool> AddRental(int clientId, int copyId) { try { var copy = _copiesLogic.GetCopy(x => x.copy_id == copyId && x.available.Value == true); if (!copy.Success) { return(new ObjectResponse <bool> { Success = false, Error = "Copy Does not Exist In Shop" }); } var rental = new rental { client_id = clientId, copy_id = copyId, date_of_rental = DateTime.Now }; _unitOfWork.RentalsRepository.Add(rental); var result = _copiesLogic.AddOrUpdate(copy.Data.Id, copy.Data.Movie.Id, false); return(result.Success ? new ObjectResponse <bool> { Success = true, Data = true } : new ObjectResponse <bool> { Success = false, Error = result.Error, Info = result.Info }); } catch (Exception ex) { return(new ObjectResponse <bool> { Success = false, Error = ex.GetBaseException().Message, Info = DB_SAVE_ERROR }); } }
private ObjectResponse <int> AddMovieCopy(movy movie) { var movieCopy = _copiesLogic.GetLastCopy(); if (!movieCopy.Success) { return(new ObjectResponse <int> { Success = false, Error = movieCopy.Error, Info = movieCopy.Info }); } var copyId = (movieCopy.Data?.Id + 1) ?? 1; var addCopyResult = _copiesLogic.AddOrUpdate(copyId, movie.movie_id, true); return(addCopyResult.Success ? new ObjectResponse <int> { Success = true, Data = copyId } : new ObjectResponse <int> { Success = false, Error = addCopyResult.Error, Info = addCopyResult.Info }); }