Esempio n. 1
0
 public void InsertOrUpdate(Individual individual)
 {
     if (individual.Id == default(int)) {
         // New entity
         context.Individuals.Add(individual);
     } else {
         // Existing entity
         context.Entry(individual).State = EntityState.Modified;
     }
 }
Esempio n. 2
0
        public ActionResult Create(Individual individual)
        {
            if (ModelState.IsValid)
            {
                db.Individuals.Add(individual);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(individual);
        }
        public HttpResponseMessage Put(Individual individual)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Esempio n. 4
0
 public ActionResult Edit(Individual individual)
 {
     if (ModelState.IsValid)
     {
         db.Entry(individual).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(individual);
 }