public bool CancelReservation(string id, string roleName)
        {
            Reservation reservation = _reservationsRepository.GetReservation(id);

            if (reservation == null)
            {
                return(false);
            }
            if (reservation.IsCancelled)
            {
                //TODO: Better response
                return(false);
            }
            //TODO: Check penalties and date of reservation if user is client
            if (roleName == "Client")
            {
                DateTime timeNow           = DateTime.Now;
                WorkDay  workDay           = _workDaysService.GetWorkDay(reservation.WorkDayId);
                DateTime dateOfReservation = workDay.Date;
                if (CheckPenalties(timeNow, dateOfReservation) + reservation.StartHour < 24)
                {
                    ClientAccount client = _accountsService.GetClientAccount(reservation.Account.Id);
                    client.Penalty += 1;
                    _accountsService.UpdateClientAccountPenalties(client);
                    reservation.Account = client;
                }
            }
            reservation.IsCancelled = true;
            return(_reservationsRepository.UpdateReservation(reservation));
        }
Exemplo n.º 2
0
 public IActionResult Get()
 {
     try
     {
         List <Reservation>    reservations = _reservationService.GetReservations();
         List <ReservationDto> result       = new List <ReservationDto>();
         foreach (Reservation res in reservations)
         {
             WorkDay        workDay = _workDaysService.GetWorkDay(res.WorkDayId);
             ReservationDto dto     = _mapper.Map <ReservationDto>(
                 res, opt =>
             {
                 opt.Items["workDay"] = workDay;
             });
             result.Add(dto);
         }
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Exemplo n.º 3
0
 public IActionResult GetWorkDayById(string id)
 {
     try
     {
         WorkDay w = _workDaysService.GetWorkDay(id);
         if (w == null)
         {
             return(NotFound("Work day with id not found"));
         }
         return(Ok(_mapper.Map <WorkDayDto>(w)));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }