Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }