public async Task <ActionResult <Apartment> > AddGuest(int id, [FromBody] AddGuestRequest request)
        {
            try
            {
                var apartment = await _apartmentRepository.FindById(id);

                var employeeTravel = await _employeeTravelRepository.FindById(request.EmployeeTravelId);

                return(Ok(await _apartmentRepository.AddGuest(apartment, employeeTravel)));
            }
            catch (ArgumentException)
            {
                return(Conflict());
            }
        }
Exemple #2
0
        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));
            }
        }