public async Task <Apartment> RemoveGuest(Apartment apartment, EmployeeTravel employeeTravel) { apartment.EmployeeTravels.Remove(employeeTravel); await appDbContext.SaveChangesAsync(); return(apartment); }
public async Task <EmployeeTravel> Create(EmployeeTravel entity) { appDbContext.Entry(entity.Employee).State = EntityState.Unchanged; appDbContext.EmployeeTravel.Add(entity); await appDbContext.SaveChangesAsync(); return(entity); }
public async Task Delete(EmployeeTravel entity) { var traveler = appDbContext.EmployeeTravel.Single(x => x.Id == entity.Id); appDbContext.EmployeeTravel.Remove(traveler); await appDbContext.SaveChangesAsync(); }
public async Task Update(EmployeeTravel entity) { var employeetravel = appDbContext.EmployeeTravel.Single(x => x.Id == entity.Id); employeetravel.Travel = entity.Travel; employeetravel.Employee = entity.Employee; employeetravel.Confirm = entity.Confirm; await appDbContext.SaveChangesAsync(); }
public async Task <ActionResult <Travel> > CreateEmployeeTravel([FromBody] CreateEmployeeTravelRequest request) { try { if (!await _employeeTravelRepository.CheckTravelsByEmployeeId(request.EmployeeId, request.TravelId)) { return(Conflict(" This employee already has this trip ")); } var employeeTravel = new EmployeeTravel { Employee = await _employeeRepository.FindById(request.EmployeeId), Travel = await _travelRepository.FindByIdWithOrganizedBy(request.TravelId), Confirm = request.Confirm, }; if (request.NeedApartment) { var _employeeTravel = await _employeeTravelRepository.Create(employeeTravel); var _office = await _officeRepository.FindById(_employeeTravel.Travel.TravelTo.Id); await _apartmentRepository.AddGuest(await _apartmentRepository.FindById(_office.OfficeApartment.Id), _employeeTravel); return(Ok()); } else { return(Ok(await _employeeTravelRepository.Create(employeeTravel))); } } catch (ArgumentException e) { return(Conflict(e.Message)); } }