public async Task <IHttpActionResult> PropertyDTO(int?id) { if (id == null) { return(BadRequest()); } PropertyREDTO property = await db.Properties.Include(b => b.Community).Include(b => b.Owner) .Where(b => b.PropertyREId == id) .Select(AsPropertyREDTO) .FirstOrDefaultAsync(); if (property == null) { return(NotFound()); } return(Ok(property)); }
public async Task <IHttpActionResult> PostPropertyRE(PropertyRE propertyRE) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Properties.Add(propertyRE); await db.SaveChangesAsync(); PropertyREDTO propertyREDTO = db.Properties.Include(b => b.Community).Include(b => b.Owner).Include(b => b.PropertyType) .Where(b => b.PropertyREId == propertyRE.PropertyREId) .Select(AsPropertyREDTO) .FirstOrDefault(); Hub.Clients.All.updateItem(propertyREDTO); // Notify the connected clients // Return the new item, inside a 201 response (i.e., HttpStatusCode.Created) return(CreatedAtRoute("DefaultApi", new { id = propertyRE.PropertyREId }, propertyRE)); }
public async Task <IHttpActionResult> PutPropertyRE(int id, PropertyRE propertyRE) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != propertyRE.PropertyREId) { return(BadRequest()); } db.Entry(propertyRE).State = EntityState.Modified; try { await db.SaveChangesAsync(); PropertyREDTO propertyREDTO = db.Properties.Include(b => b.Community).Include(b => b.Owner).Include(b => b.PropertyType) .Where(b => b.PropertyREId == id) .Select(AsPropertyREDTO) .FirstOrDefault(); Hub.Clients.All.updateItem(propertyREDTO); // Notify the connected clients } catch (DbUpdateConcurrencyException) { if (!PropertyREExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }