public void BuyBook(BookProductDTO bookProductDTO, UserDTO userDTO) { var prod = _unitOfWork.ProductRepository.GetByID(bookProductDTO.Id); if (prod.Count > 0) { prod.Count--; var disc = prod.Discount ?? 0; SaleDTO sale = new SaleDTO() { ProductId = prod.BookId, UserId = userDTO.Id, TotalPrice = prod.SellingPrice - ((prod.SellingPrice * disc) / 100) }; _unitOfWork.SaleRepository.Insert(_mapper.Map <Sale>(sale)); _unitOfWork.Commit(); } }
public void ReservBook(BookProductDTO bookProductDTO, UserDTO userDTO) { var prod = _unitOfWork.ProductRepository.GetByID(bookProductDTO.Id); if (prod.Count > 0) { prod.Count--; var disc = prod.Discount ?? 0; ReservDTO reservDTO = new ReservDTO() { ProductId = prod.BookId, UserId = userDTO.Id, IsActive = true, }; _unitOfWork.ReservRepository.Insert(_mapper.Map <Reserv>(reservDTO)); _unitOfWork.Commit(); } }
public bool IsUserReservBook(BookProductDTO bookProductDTO, UserDTO userDTO) { var prod = _unitOfWork.ProductRepository.GetByID(bookProductDTO.Id); return(_unitOfWork.ReservRepository.Get(r => r.ProductId == prod.BookId && r.UserId == userDTO.Id && r.IsActive).Count() != 0); }