Esempio n. 1
0
 public ActionResult Delete(PersonModel model, FormCollection formCollection)
 {
     if (ModelState.IsValid)
     {
         using (var db = new NespeDbContext())
         {
             var drc = db.PersonSet;
             var dr = (from t in drc where t.Id == model.Selected.Id select t).FirstOrDefault();
             if (dr == null)
             {
                 base.ModelState.AddModelError("Action.Delete.Invalid.Id", "Invalid Id");
                 return RedirectToAction("Index");
             }
             drc.Remove(dr);
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     return View(model);
 }
Esempio n. 2
0
 public ActionResult Create(RequestInfoModel model, FormCollection formCollection)
 {
     if (ModelState.IsValid)
     {
         using (var db = new NespeDbContext())
         {
             var drc = db.RequestInfoSet;
             var dr = (from t in drc where t.Name == model.Selected.Name select t).FirstOrDefault();
             if (dr != null && dr.Id > 0)
             {
                 return RedirectToAction("Edit", new { Id = dr.Id });
             }
             else
             {
                 drc.Add(model.Selected);
             }
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     return View(model);
 }
Esempio n. 3
0
        public ActionResult Edit(PersonModel model, FormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                using (var db = new NespeDbContext())
                {
                    var selected = model.Selected;
                    var drc = db.PersonSet;
                    //drc.Attach(model.Selected);
                    var dr = (from t in drc where t.Id == model.Selected.Id select t).FirstOrDefault();
                    if (dr != null)
                    {
                        dr.Copy(selected);
                        selected = dr;
                    }
                    else
                        drc.Add(selected);

                    db.SaveChanges();

                }
                return RedirectToAction("Index");
            }
            return View(model);
        }
 public ActionResult Create(PersonDepartmentModel model, FormCollection formCollection)
 {
     if (ModelState.IsValid)
     {
         using (var db = new NespeDbContext())
         {
             var drc = db.PersonDepartmentSet;
             var selected = model.Selected;
             var dr = (from t in drc where t.Person_Id == selected.Person_Id && t.Department_Id == selected.Department_Id select t).FirstOrDefault();
             if (dr != null && dr.Id > 0)
             {
                 return RedirectToAction("Edit", new { Id = dr.Id });
             }
             else
             {
                 Bind(selected, db);
                 drc.Add(selected);
             }
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     return View(model);
 }
        public ActionResult Edit(PersonDepartmentModel model, FormCollection formCollection)
        {
            var selected = model.Selected;
            using (var db = new NespeDbContext())
            {
                Bind(selected, db);

                if (ModelState.IsValid)
                {

                    var drc = db.PersonDepartmentSet;
                    //drc.Attach(model.Selected);
                    var dr = Get(model.Selected.Id, db);
                    if (dr != null)
                    {
                        dr.Copy(selected);
                        selected = dr;
                    }
                    else
                        drc.Add(selected);

                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            return View(model);
        }