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); } }
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); }
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); }
public async Task <bool> AddAsync(CancellationToken cancellationToken, PenaltyDto penaltyDto) { try { var penalty = penaltyDto.ToEntity(); await _repository.AddAsync(penalty, cancellationToken); return(true); } catch { return(false); } }
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)); }
/// <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("---------------------"); }
public void Save(PenaltyDto PenaltyDto, Login userLogin) { var dbPenalty = Mapper.Map <MST_PENALTY>(PenaltyDto); _uow.GetGenericRepository <MST_PENALTY>().InsertOrUpdate(dbPenalty, userLogin, Enums.MenuList.MasterPenalty); }
public void Save(PenaltyDto PenaltyDto) { var dbPenalty = Mapper.Map <MST_PENALTY>(PenaltyDto); _uow.GetGenericRepository <MST_PENALTY>().InsertOrUpdate(dbPenalty); }
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"); } }
public bool PayPenalty(PenaltyDto Penalty) { _dblibrary.PayPenalty(Penalty.Id); return(true); }