public object CreateDataShapedObject(DAO.Business business, List <string> lstOfFields) { if (!lstOfFields.Any()) { return(business); } else { // create a new ExpandoObject & dynamically create the properties for this object ExpandoObject objectToReturn = new ExpandoObject(); foreach (var field in lstOfFields) { // need to include public and instance, b/c specifying a binding flag overwrites the // already-existing binding flags. var fieldValue = business.GetType() .GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) .GetValue(business, null); // add the field to the ExpandoObject ((IDictionary <String, Object>)objectToReturn).Add(field, fieldValue); } return(objectToReturn); } }
public IHttpActionResult Put(int id, [FromBody] DAO.Business business) { try { if (business == null) { return(BadRequest()); } //map var bc = _businessFactory.CreateBusiness(business); var result = _repository.UpdateBusiness(bc); if (result.Status == BookingRepositoryActionStatus.Updated) { // map to dao var updatedBusiness = _businessFactory.CreateBusiness(result.Entity); return(Ok(updatedBusiness)); } else if (result.Status == BookingRepositoryActionStatus.NotFound) { return(NotFound()); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }
public Business CreateBusiness(DAO.Business business) { return(new Business() { id = business.Id, BusinessName = business.BusinessName, BusinessType = business.BusinessType, Description = business.Description, BusinessCategoryId = business.BusinessCategoryId, LastUpdate = business.LastUpdate, DateCreated = business.DateCreated, openingHour = business.openingHour, ClosingHour = business.ClosingHour, CustomerId = business.CustomerId, Addresses = business.Addresses == null ? new List <Address>() : business.Addresses.Select(a => addressFactory.CreateAddress(a)).ToList(), Services = business.Services == null ? new List <Service>() : business.Services.Select(a => serviceFactory.CreateService(a)).ToList() }); }
public IHttpActionResult Post([FromBody] DAO.Business business) { try { if (business == null) { return(BadRequest()); } // map var b = _businessFactory.CreateBusiness(business); var result = _repository.InsertBusiness(b); if (result.Status == BookingRepositoryActionStatus.Created) { // map to dto var newB = _businessFactory.CreateBusiness(result.Entity); return(Created <DAO.Business>(Request.RequestUri + "/" + newB.Id.ToString(), newB)); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }