Пример #1
0
        public ActionResult Create(Location location)
        {
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(location);
        }
Пример #2
0
        // POST api/Locations
        public HttpResponseMessage PostLocation(Location location)
        {
            if (ModelState.IsValid)
            {

                // FromText(point shit here). Right after the if statement verifying model.stateisvalid or something like that

                // var test = location.Latitude;

                location.GeoLocation = DbGeography.FromText("POINT(" + location.Longitude + "  " + location.Latitude + ")");

                db.Locations.Add(location);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, location);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = location.Id }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Пример #3
0
 public ActionResult Edit(Location location)
 {
     if (ModelState.IsValid)
     {
         db.Entry(location).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(location);
 }
Пример #4
0
        // PUT api/Locations/5
        public HttpResponseMessage PutLocation(int id, Location location)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != location.Id)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(location).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }