public ActionResult Create(PeopleInfo people) { try { if (ModelState.IsValid) { log.Debug("Start create people"); dbManager.CreatePeople(people); log.Debug("Save: Ok"); return RedirectToAction("Index"); } ModelState.AddModelError("", "Model error" ); return View(people); } catch (Exception exception) { log.Error(string.Format("Save: Fail; Exception message:{0}", exception.Message)); return RedirectToAction("Error500", "Error"); } }
// POST api/HomeApi public HttpResponseMessage PostPeopleInfo(PeopleInfo peopleinfo) { if (ModelState.IsValid) { peopleinfo.PeopleId = Guid.NewGuid(); db.PeopleInfo.Add(peopleinfo); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, peopleinfo); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = peopleinfo.PeopleId })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public void EditPeople(PeopleInfo people) { db.Entry(people).State = EntityState.Modified; db.SaveChanges(); }
public void CreatePeople(PeopleInfo people) { people.PeopleId = Guid.NewGuid(); db.PeopleInfo.Add(people); db.SaveChanges(); }
// PUT api/HomeApi/5 public HttpResponseMessage PutPeopleInfo(Guid id, PeopleInfo peopleinfo) { if (ModelState.IsValid && id == peopleinfo.PeopleId) { db.Entry(peopleinfo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }