public async Task <ActionResult <Apartment> > CreateApartment([FromBody] CreateApartmentRequest request) { try { var apartment = new Apartment { Title = request.Title, Address = request.Address, FitsPeople = request.FitsPeople, EmployeeTravels = new List <EmployeeTravel>() }; return(Ok(await _apartmentRepository.Create(apartment))); } catch (ArgumentException) { return(Conflict()); } }
public async Task <ActionResult <Apartment> > UpdateApartment(int id, [FromBody] CreateApartmentRequest request) { try { var apartment = await _apartmentRepository.FindById(id); if (request.Title != null) { apartment.Title = request.Title; } if (request.Address != null) { apartment.Address = request.Address; } if (request.FitsPeople >= 0) { apartment.FitsPeople = request.FitsPeople; } if (request.Version != null) { apartment.Version = request.Version; } await _apartmentRepository.Update(apartment); return(Ok(await _apartmentRepository.FindById(id))); } catch (ArgumentException e) { return(Conflict(e.Message)); } catch (InvalidOperationException) { return(NotFound()); } catch (DbUpdateConcurrencyException ex) { return(Conflict(ex)); } }