예제 #1
0
        public ActionResult Create([Bind(Include = "Nome")] Percurso percurso)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Percursos.Add(percurso);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /* dex */)
            {
                //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.");
            }

            return(View(percurso));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "Nome,Descricao,LocalID,CategoriaID,duracaoVisita")] POI pOI)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.POIs.Add(pOI);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.LocalID     = new SelectList(db.Locals, "LocalID", "LocalID");
                ViewBag.CategoriaID = new SelectList(db.Categorias, "CategoriaID", "nome");
            }
            catch (DataException /* dex */)
            {
                //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.");
            }

            return(View(pOI));
        }
예제 #3
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));
        }
예제 #4
0
        public IHttpActionResult PostHashtag(Hashtag hashtag, List <int> poi)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Hashtag hashtagUpdate = db.Hashtags.Find(hashtag.ID);

            atualizarPoiDoHashTag(hashtagUpdate, poi);
            db.Hashtags.Add(hashtag);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = hashtag.ID }, hashtag));
        }