예제 #1
0
        public static PropertyRE GetPropertyRE(int id)
        {
            PropertyRE propertyre = db.Properties.Find(id);

            if (propertyre == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(propertyre);
        }
예제 #2
0
        public async Task <HttpResponseMessage> EditPropertyREAsync(int id, PropertyRE propertyRE,
                                                                    CancellationToken cancelToken = default(CancellationToken))
        //public HttpResponseMessage EditPropertyRE(int id, PropertyRE propertyRE)
        {
            var uri = Util.getServiceUri("Properties" + "/" + id + "/edit");

            using (HttpClient httpClient = new HttpClient())
            {
                var response = await httpClient.PutAsJsonAsync(uri, propertyRE, cancelToken);

                return(response.EnsureSuccessStatusCode());
            }
        }
예제 #3
0
        //public async Task<HttpResponseMessage> PostPropertyREAsync(PropertyRE propertyRE,
        public async Task <PropertyRE> PostPropertyREAsync(PropertyRE propertyRE,

                                                           CancellationToken cancelToken = default(CancellationToken))
        {
            var uri = Util.getServiceUri("Properties" + "/add");

            using (HttpClient httpClient = new HttpClient())
            {
                var response = await httpClient.PostAsJsonAsync(uri, propertyRE);

                //return response.EnsureSuccessStatusCode();
                return(await response.Content.ReadAsAsync <PropertyRE>());
            }
        }
예제 #4
0
        public async Task <IHttpActionResult> Property(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            PropertyRE property = await db.Properties.FindAsync(id);

            if (property == null)
            {
                return(NotFound());
            }

            return(Ok(property));
        }
예제 #5
0
        public async Task <IHttpActionResult> DeletePropertyRE(int id)
        {
            PropertyRE propertyRE = await db.Properties.FindAsync(id);

            if (propertyRE == null)
            {
                return(NotFound());
            }

            db.Properties.Remove(propertyRE);
            await db.SaveChangesAsync();

            Hub.Clients.All.deleteItem(id);                             // Notify the connected clients

            return(Ok(propertyRE));
        }
예제 #6
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));
        }
예제 #7
0
        public async Task <ActionResult> Create([Bind(Include = "PropertyREId,PropertyTypeId,CommunityId,OwnerID,Description,PropertyTypeSub,Location,Price")] PropertyRE propertyRE)
        {
            /* This is an example of the magic of model binding, that is-
             * - An HTML form has been posted back in
             * - The system knows what a call object is
             * - Maps HTML form data (using Name attribute of an 'input' element, for example) to a call object
             *
             * Watch "Developing ASP.NET MVC 4 Applications: (03) Developing MVC 4 Controllers". Jump to Time: 24:30
             */
            /*
             * Model binder refers to the ASP.NET MVC functionality that makes it easier for you to work with data submitted by a form;
             * a model binder converts posted form values to CLR types and passes them to the action method in parameters.
             * In this case, the model binder instantiates a propertyRE entity for you using property values from the Form collection
             * See: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application#overpost
             */
            try
            {
                if (ModelState.IsValid)
                {
                    var propertyservice = new PropertyService();
                    var res             = await propertyservice.PostPropertyREAsync(propertyRE);

                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /* dex */)

            /*
             * See http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application#overpost
             */
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            ViewBag.CommunityId    = new SelectList(db.Communities, "CommunityId", "Name", propertyRE.CommunityId);
            ViewBag.OwnerID        = new SelectList(db.Owners, "OwnerID", "Name", propertyRE.OwnerID);
            ViewBag.PropertyTypeId = new SelectList(db.PropertyTypes, "PropertyTypeId", "Name", propertyRE.PropertyTypeId);
            return(View(propertyRE));
        }
예제 #8
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));
        }
예제 #9
0
        public async Task <ActionResult> Edit([Bind(Include = "PropertyREId,PropertyTypeId,CommunityId,OwnerID,Description,PropertyTypeSub,Location,Price")] PropertyRE propertyRE)
        // public async Task<ActionResult> Edit(int? id, byte[] rowVersion) // New procedure
        {
            /* New procedure
             * string[] fieldsToBind = new string[] { "PropertyREId", "PropertyTypeId", "CommunityId", "OwnerID", "Description", "PropertyTypeSub", "Location,Price" };
             *
             * if (id == null)
             * {
             *  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             * }*/

            if (ModelState.IsValid)
            {
                var propertyservice = new PropertyService();
                var res             = await propertyservice.EditPropertyREAsync(propertyRE.PropertyREId, propertyRE);;
                return(RedirectToAction("Index"));
            }
            ViewBag.CommunityId    = new SelectList(db.Communities.OrderBy(x => x.Name), "CommunityId", "Name", propertyRE.CommunityId);
            ViewBag.OwnerID        = new SelectList(db.Owners.OrderBy(x => x.Name), "OwnerID", "Name", propertyRE.OwnerID);
            ViewBag.PropertyTypeId = new SelectList(db.PropertyTypes.OrderBy(x => x.Name), "PropertyTypeId", "Name", propertyRE.PropertyTypeId);

            return(View(propertyRE));
        }