Esempio n. 1
0
        public ActionResult Create(AboutMe aboutme)
        {
            if (ModelState.IsValid)
            {
                db.AboutMes.Add(aboutme);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(aboutme);
        }
        // POST api/AboutMeAPI
        public HttpResponseMessage PostAboutMe(AboutMe aboutme)
        {
            if (ModelState.IsValid)
            {
                db.AboutMes.Add(aboutme);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, aboutme);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = aboutme.AboutMeId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Esempio n. 3
0
 public ActionResult Edit(AboutMe aboutme)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aboutme).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(aboutme);
 }
        // PUT api/AboutMeAPI/5
        public HttpResponseMessage PutAboutMe(int id, AboutMe aboutme)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != aboutme.AboutMeId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }