public PenaltyDto ReturnBook(string Username, string BookName, DateTime returnDate)
        {
            BookingDto    NewBookingDto = this.GetBooking(Username, BookName);
            BookingEntity bookingEntity = new BookingEntity();

            bookingEntity.BookId             = NewBookingDto.BookId;
            bookingEntity.EndBookingDate     = NewBookingDto.EndBookingDate;
            bookingEntity.LibraryAppUsername = NewBookingDto.LibraryAppUsername;
            bookingEntity.StartBookingDate   = NewBookingDto.StartBookingDate;
            _dblibrary.ReturnBook(bookingEntity);

            if (NewBookingDto.EndBookingDate < returnDate)
            {
                PenaltyEntity penalty = new PenaltyEntity();
                penalty.BookingId          = bookingEntity.Id;
                penalty.BookId             = bookingEntity.BookId;
                penalty.LibraryAppUsername = bookingEntity.LibraryAppUsername;
                _dblibrary.CreatePenalty(penalty);

                PenaltyDto penaltyDto = new PenaltyDto();
                penaltyDto.Id                 = penalty.Id;
                penaltyDto.BookId             = penalty.BookId;
                penaltyDto.BookingId          = penalty.BookingId;
                penaltyDto.LibraryAppUsername = penalty.LibraryAppUsername;
                return(penaltyDto);
            }
            else
            {
                _dblibrary.ReturnBook(bookingEntity);
                return(null);
            }
        }
Example #2
0
        public async Task <IActionResult> PostAsync([FromBody] PenaltyDto penaltyDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(penaltyDto));
            }

            return(Created("", await _penaltyService.CreateAsync(HttpContext.User.GetAccountId(), penaltyDto)));
        }
        public PenaltyDto GetPenalty(string username, string bookTitle)
        {
            PenaltyEntity penaltyEntity = _dblibrary.GetPenalty(username, bookTitle);
            PenaltyDto    PenaltyDto    = new PenaltyDto();

            PenaltyDto.BookId             = penaltyEntity.BookId;
            PenaltyDto.BookingId          = penaltyEntity.BookingId;
            PenaltyDto.Id                 = penaltyEntity.Id;
            PenaltyDto.LibraryAppUsername = penaltyEntity.LibraryAppUsername;
            return(PenaltyDto);
        }
Example #4
0
        public async Task <IActionResult> GetAsync(int id)
        {
            PenaltyDto penalty = await _penaltyService.GetByIdAsync(id);

            if (penalty == null)
            {
                return(NotFound(id));
            }

            return(Json(penalty));
        }
        public async Task <PenaltyDto> CreateAsync(int creatorId, PenaltyDto dto)
        {
            dto.CreatorId = creatorId;
            dto.Date      = DateTime.Now;
            PenaltyModel model = _mapper.Map <PenaltyDto, PenaltyModel>(dto);
            await _unitOfWork.PenaltiesRepository.InsertAsync(model);

            await _unitOfWork.SaveAsync();

            return(dto);
        }
        public async Task <PenaltyDto> UpdateAsync(int id, PenaltyDto dto)
        {
            dto.Account   = null;
            dto.Character = null;
            dto.Creator   = null;
            PenaltyModel model = await _unitOfWork.PenaltiesRepository.GetAsync(id);

            _mapper.Map(dto, model);
            await _unitOfWork.SaveAsync();

            return(dto);
        }
Example #7
0
        public async Task <bool> AddAsync(CancellationToken cancellationToken, PenaltyDto penaltyDto)
        {
            try
            {
                var penalty = penaltyDto.ToEntity();
                await _repository.AddAsync(penalty, cancellationToken);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #8
0
        public async Task <IActionResult> PutAsync([FromRoute] int id, [FromBody] PenaltyDto penaltyDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(penaltyDto));
            }

            PenaltyDto penalty = await _penaltyService.UpdateAsync(id, penaltyDto);

            if (penalty == null)
            {
                return(NotFound(id));
            }

            return(Json(penalty));
        }
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        private void PayPenaltyOp() 
        {
            LibraryAppUserDto libUserDto = new LibraryAppUserDto();
            BookDto bookDto;
            string inputLine = string.Empty;
            Console.TreatControlCAsInput = false;
            do
            {
                Console.WriteLine("Introduzca el usuario: ");
                inputLine = Console.ReadLine();
                libUserDto = _userService.GetUser(inputLine);
                if (libUserDto == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Nombre de usuario no válido");
                    Console.ForegroundColor = ConsoleColor.White;
                }

            } while (libUserDto == null);

            do
            {
                Console.WriteLine("Introduzca el libro: ");
                inputLine = Console.ReadLine();
                bookDto = _libService.GetBook(inputLine);
                if (bookDto == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Nombre de libro no válido");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            } while (bookDto == null);

            try
            {
                PenaltyDto penalty = _libService.GetPenalty(libUserDto.Username, bookDto.BookTitle);
                Console.TreatControlCAsInput = true;
                Console.WriteLine("¿Confirma que desea cancelar la multa? (Y/N)");
                ConsoleKeyInfo cki;
                cki = Console.ReadKey(true);

                if (cki.Key.ToString().ToLower() == "y")
                {
                    _libService.PayPenalty(penalty);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Se ha realizadp el pago correctamente");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else if (cki.Key.ToString().ToLower() == "n")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Ha decidido no cancelar la multa... allá usted");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            catch 
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No se ha cancelado la multa");
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.WriteLine("---------------------");

        }
Example #10
0
        public void Save(PenaltyDto PenaltyDto, Login userLogin)
        {
            var dbPenalty = Mapper.Map <MST_PENALTY>(PenaltyDto);

            _uow.GetGenericRepository <MST_PENALTY>().InsertOrUpdate(dbPenalty, userLogin, Enums.MenuList.MasterPenalty);
        }
Example #11
0
        public void Save(PenaltyDto PenaltyDto)
        {
            var dbPenalty = Mapper.Map <MST_PENALTY>(PenaltyDto);

            _uow.GetGenericRepository <MST_PENALTY>().InsertOrUpdate(dbPenalty);
        }
Example #12
0
        public async Task <string> EditAsync(CancellationToken cancellationToken, int penaltyId, PenaltyDto penaltyDto)
        {
            try
            {
                var model = await _repository.Table.Where(c => c.Id == penaltyId).SingleOrDefaultAsync(cancellationToken);

                if (model == null)
                {
                    return("NotFound");
                }
                var res = penaltyDto.ToEntity(model);
                await _repository.UpdateAsync(res, cancellationToken);

                return("Ok");
            }
            catch
            {
                return("Bad");
            }
        }
Example #13
0
 public bool PayPenalty(PenaltyDto Penalty)
 {
     _dblibrary.PayPenalty(Penalty.Id);
     return(true);
 }