public async Task <ReservationVm> ReserveAsync(ReservationDto reservationDto) { var reservation = await _context.Reservations.FirstOrDefaultAsync(r => r.DeansOfficeId == reservationDto.DeansOfficeId && r.Date == reservationDto.Date); if (reservation == null) { throw new Exception("Reservation with given Date and DeansOfficeId not found."); } if (reservation.StudentId != null) { throw new Exception("This date is already reserved."); } var now = DateTime.Now; if (reservation.Date < now) { throw new Exception("Cannot reserve old slots."); } reservation.StudentId = reservationDto.StudentId; reservation.OperationName = reservationDto.OperationName; await _context.SaveChangesAsync(); return(_mapper.Map <Reservation, ReservationVm>(reservation)); }
public async Task <IActionResult> PutDeansOffice(Guid id, DeansOffice deansOffice) { if (id != deansOffice.Id) { return(BadRequest()); } _context.Entry(deansOffice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeansOfficeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <Department> AddDepartmentAsync(CreateDepartmentDto departmentDto) { var department = _mapper.Map <Department>(departmentDto); _context.Departments.Add(department); await _context.SaveChangesAsync(); return(department); }