Beispiel #1
0
        public async Task <IHttpActionResult> PutSugerirPOI(int id, SugerirPOI sugerirPOI)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sugerirPOI.SugerirPoiID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SugerirPOIExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PutCategoria(int id, Categoria categoria)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categoria.CategoriaID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoriaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
 public ActionResult Delete(int id)
 {
     try
     {
         POI poiToDelete = new POI()
         {
             PoiID = id
         };
         db.Entry(poiToDelete).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         return(RedirectToAction("Delete", new { id = id, saveChangesError = true }));
     }
     return(RedirectToAction("Index"));
 }
        public async Task <ActionResult> Edit([Bind(Include = "LocalID,GPS_Lat,GPS_Long,Nome")] Local local)
        {
            if (ModelState.IsValid)
            {
                db.Entry(local).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(local));
        }
Beispiel #5
0
        public async Task <ActionResult> Edit([Bind(Include = "PointOfInterestID,Nome,Descricao,LocalID,Criador")] PointOfInterest pointOfInterest)
        {
            if (ModelState.IsValid)
            {
                db.Entry(pointOfInterest).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.LocalID = new SelectList(db.Locals, "LocalID", "Nome", pointOfInterest.LocalID);
            return(View(pointOfInterest));
        }
Beispiel #6
0
        public IHttpActionResult PutPOI(int id, POIDTOReceive poiDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != poiDTO.PoiID)
            {
                return(BadRequest());
            }

            POI poi = db.POIs.Find(id);

            //if (poi.CheckNotOwner(User.Identity.GetUserId()))
            //{
            //    return StatusCode(HttpStatusCode.Unauthorized);
            //}

            copyToDto(poi, poiDTO);
            db.Entry(poi).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!POIExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutPointOfInterest(int id, PointOfInterest pointOfInterest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pointOfInterest.PointOfInterestID)
            {
                return(BadRequest());
            }

            if (!pointOfInterest.Criador.Id.Equals(User.Identity.GetUserId()))
            {
                return(Unauthorized());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PointOfInterestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }