public IActionResult Rent(RentDto rent) { var result = _rentalService.Rent(rent); if (result.Success) { return(Ok(result)); } return(BadRequest(result.Message)); }
public async Task <RentDto> Update(long id, RentDto dto) { var rent = Mapper.Map <Rent>(dto); if (_unitOfWork.RentRepository.Update(rent)) { await _unitOfWork.Save(); } return(Mapper.Map <RentDto>(rent)); }
public async Task <RentDto> Create(RentDto dto) { await Check(dto); var rent = Mapper.Map <Rent>(dto); await InternalCreate(dto, rent); return(Mapper.Map <RentDto>(rent)); }
public IResult Rent(RentDto rentDto) { IResult result = BusinessRules.Run(CheckDate(rentDto.CarId), CheckFindexPoint(rentDto.CustomerId)); if (result != null) { return(result); } return(new SuccessResult()); }
public ActionResult Get([FromQuery] RentDto dto) { try { var consoles = getRent.Execute(dto); return(Ok(consoles)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public void Create_SubscriberNull_ShouldThrowRentNotHasBookOrSubscriberException() { var rent = new RentDto() { Id = Random.Next(int.MaxValue), Count = 55, IsActive = true, Book = Mapper.Map <BookDto>(DefaultData.Books.ClrVia), Date = DateTime.Now }; Assert.Throws <RentNotHasBookOrSubscriberException>(async() => await RentsService.Create(rent)); }
private async Task ThrowIfCountOfReservedMoreOrEqualCountOfBook(RentDto dto) { var rents = await _unitOfWork.RentRepository.GetAllAsync(new List <Expression <Func <Rent, bool> > >() { x => x.Book.Id == dto.Book.Id }, null, $"{nameof(Rent.Book)}"); var reserved = rents.Sum(x => x.Count); if ((reserved + dto.Count) > dto.Book.Count) { throw new NotHasAvailableBooksCountException(); } }
public MappingProfile() { ApplyMappingsFromAssembly(Assembly.GetExecutingAssembly()); CarDto.Mapping(this); CarDetailVm.Mapping(this); AccountDetailVm.Mapping(this); PhotoDto.Mapping(this); TransmissionDto.Mapping(this); CarTypeDto.Mapping(this); ColorDto.Mapping(this); CityDto.Mapping(this); LocationDto.Mapping(this); RentDto.Mapping(this); }
public void Create_CountMoreCountOfBooks_ShouldThrownRentCountMoreCountOfBookException() { var rent = new RentDto() { Id = Random.Next(int.MaxValue), Count = DefaultData.Books.ClrVia.Count + 1, IsActive = true, Book = Mapper.Map <BookDto>(DefaultData.Books.ClrVia), Subscriber = Mapper.Map <SubscriberDto>(DefaultData.Subscribers.Maslov), Date = DateTime.Now }; Assert.Throws <RentCountMoreCountOfBookException>(async() => await RentsService.Create(rent)); }
public IActionResult Post([FromBody] RentDto request) { try { addRent.Execute(request); return(StatusCode(201)); } catch (AlreadyExistsEx ex) { return(StatusCode(409, ex.Message)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task <ActionResult> Post([FromBody] RentDto rent) { try { var newRent = new Rent { BookId = Convert.ToInt32(rent.BookId), UserId = Convert.ToInt32(rent.UserId) }; db.Add(newRent); await db.SaveChangesAsync();//INSERT INTO return(Ok()); } catch (Exception e) { return(View(e)); } }
public void Create_BookNotHasAvailableCount_ShouldThrownBookNotHasAvailableCountException() { var book = Books.First(); var reserved = Rents.Where(x => x.Book.Id == book.Id).Sum(x => x.Count); Rents.Add(new Rent(book, Subscribers.First(), book.Count - reserved) { Id = Random.Next(int.MaxValue), Date = DateTime.Now, }); var dto = new RentDto() { Subscriber = Mapper.Map <SubscriberDto>(Subscribers.First()), Book = Mapper.Map <BookDto>(book), Count = 1, Date = DateTime.Now, }; Assert.Throws <NotHasAvailableBooksCountException>(async() => await RentsService.Create(dto)); }
public IActionResult AddRent([FromBody] RentDto rentFromBody) { if (!_userService.CheckIfUserExists(rentFromBody.BorrowerId) || !_offerService.CheckIfOfferExists(rentFromBody.OfferId)) { return(NotFound()); } //if(!_rentService.CheckIfUserHasEnoughPoints(rentFromBody.BorrowerId)) //{ // return BadRequest("Niewystarczająca ilość punktów na zrealizowanie wypożyczenia."); //} if (!_offerService.CheckIfOfferIsActive(rentFromBody.OfferId)) { return(BadRequest("Oferta nieaktywna.")); } _rentService.AddRent(rentFromBody); return(NoContent()); }
public IActionResult UpdateRent([FromBody] RentDto rent) { _rentService.UpdateRent(rent); return(Json(JsonResultData.Success())); }
public async Task <RentDto> Put(long id, RentDto dto) { return(await _rentsService.Update(id, dto)); }
public async Task <RentDto> Post(RentDto dto) { return(await _rentsService.Create(dto)); }
public static void UpdateRent(RentDto updateRent) { HttpClientExtenction.PostData(updateRent, string.Concat(_baseRentUrl, _updateRent)); }