Ejemplo n.º 1
0
        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");
            }
        }
Ejemplo n.º 2
0
        // 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);
            }
        }
Ejemplo n.º 3
0
 public void EditPeople(PeopleInfo people)
 {
     db.Entry(people).State = EntityState.Modified;
     db.SaveChanges();
 }
Ejemplo n.º 4
0
 public void CreatePeople(PeopleInfo people)
 {
     people.PeopleId = Guid.NewGuid();
     db.PeopleInfo.Add(people);
     db.SaveChanges();
 }
Ejemplo n.º 5
0
        // 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);
            }
        }