public IActionResult Add(Apartment apartment) { var result = _customerService.Add(apartment); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public HttpResponseMessage Create(HttpRequestMessage request, ApartmentViewModel apartmentViewModel) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var newApartment = new Apartment(); newApartment.UpdateApartment(apartmentViewModel); newApartment.CreatedDate = DateTime.Now; newApartment.CreatedBy = "Administrator"; _apartmentService.Add(newApartment); _apartmentService.SaveChanges(); var responseData = Mapper.Map <Apartment, ApartmentViewModel>(newApartment); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }