예제 #1
0
        public IActionResult Rent(RentDto rent)
        {
            var result = _rentalService.Rent(rent);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result.Message));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        public IResult Rent(RentDto rentDto)
        {
            IResult result = BusinessRules.Run(CheckDate(rentDto.CarId), CheckFindexPoint(rentDto.CustomerId));

            if (result != null)
            {
                return(result);
            }

            return(new SuccessResult());
        }
예제 #5
0
 public ActionResult Get([FromQuery] RentDto dto)
 {
     try
     {
         var consoles = getRent.Execute(dto);
         return(Ok(consoles));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
예제 #6
0
        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));
        }
예제 #7
0
        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);
 }
예제 #9
0
        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));
        }
예제 #10
0
 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));
     }
 }
예제 #11
0
    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));
        }
    }
예제 #12
0
        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));
        }
예제 #13
0
        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());
        }
예제 #14
0
 public IActionResult UpdateRent([FromBody] RentDto rent)
 {
     _rentService.UpdateRent(rent);
     return(Json(JsonResultData.Success()));
 }
예제 #15
0
 public async Task <RentDto> Put(long id, RentDto dto)
 {
     return(await _rentsService.Update(id, dto));
 }
예제 #16
0
 public async Task <RentDto> Post(RentDto dto)
 {
     return(await _rentsService.Create(dto));
 }
예제 #17
0
 public static void UpdateRent(RentDto updateRent)
 {
     HttpClientExtenction.PostData(updateRent, string.Concat(_baseRentUrl, _updateRent));
 }