public ActionResult Create(long Person_Id, long Department_Id)
 {
     var model = new PersonDepartmentModel { Selected = new PersonDepartment { Person_Id = Person_Id, Department_Id = Department_Id } };
     using (var db = new NespeDbContext()) {
         Bind(model.Selected, db);
     }
     return View(model);
 }
        public ActionResult Create()
        {
            using (var db = new NespeDbContext())
            {
                var drc = db.DepartmentSet;

                var model = new DepartmentModel { Selected = new Department { }};
                model.Items = (from t in drc select t).ToList();
                return View(model);
            }
        }
 public ActionResult Delete(long Id)
 {
     using (var db = new NespeDbContext())
     {
         var drc = db.PersonSet;
         var dr = (from t in drc where t.Id == Id select t).FirstOrDefault();
         if (dr == null)
         {
             base.ModelState.AddModelError("Action.Delete.Invalid.Id", "Invalid Id");
             return RedirectToAction("Index");
         }
         var model = new PersonModel { Selected = dr };
         return View(model);
     }
 }
 public ActionResult AddDepartment(long Id, long Department_Id)
 {
     using (var db = new NespeDbContext())
     {
         var drc = db.PersonDepartmentSet;
         var dr = Get(Id, db);
         if (dr == null)
         {
             base.ModelState.AddModelError("Action.Details.Invalid.Id", "Invalid Id");
             return RedirectToAction("Index");
         }
         var model = new PersonDepartmentModel { Selected = dr };
         Bind(model.Selected, db);
         return View(model);
     }
 }
 public ActionResult Delete(RequestInfoModel model, FormCollection formCollection)
 {
     if (ModelState.IsValid)
     {
         using (var db = new NespeDbContext())
         {
             var drc = db.RequestInfoSet;
             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");
             }
         }
         return RedirectToAction("Index");
     }
     return View(model);
 }
        public ActionResult AddDepartment(PersonDepartmentModel model, FormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                using (var db = new NespeDbContext())
                {
                    var drc = db.PersonDepartmentSet;
                    var dr = (from t in drc where t.Id == model.Selected.Id select t).FirstOrDefault();
                    if (dr == null)
                    {
                        base.ModelState.AddModelError("Action.Details.Invalid.Id", "Invalid Id");
                        return RedirectToAction("Index");
                    }
                    model.Selected = dr;
                }

            }
            return View(model);
        }
 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);
 }
 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);
 }
        //
        // GET: /Person/
        public ActionResult Index()
        {
            using (var db = new NespeDbContext())
            {
                var drc = db.PersonSet;
                var model = new PersonModel { };

                model.Items = (from t in drc select t).ToList();
                return View(model);
            }
        }
Exemple #10
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 Details(long Id)
 {
     using (var db = new NespeDbContext())
     {
         var drc = db.DepartmentSet;
         var dr = (from t in drc where t.Id == Id select t).FirstOrDefault();
         if (dr == null)
         {
             base.ModelState.AddModelError("Action.Details.Invalid.Id", "Invalid Id");
             return RedirectToAction("Index");
         }
         var model = new DepartmentModel { Selected = dr };
         model.Items = (from t in drc select t).ToList();
         return View(model);
     }
 }
        //
        // GET: /Person/
        public ActionResult Index()
        {
            using (var db = new NespeDbContext())
            {
                var drc = db.PersonDepartmentSet;
                var model = new PersonDepartmentModel { };

                model.Items = Query(db).ToList();
                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);
        }
Exemple #14
0
        public ActionResult Details(long Id)
        {
            using (var db = new NespeDbContext())
            {
                var drc = db.PersonSet;
                var dr = (from t in drc where t.Id == Id select t).FirstOrDefault();
                if (dr == null)
                {
                    base.ModelState.AddModelError("Action.Details.Invalid.Id", "Invalid Id");
                    return RedirectToAction("Index");
                }
                var model = new PersonModel { Selected = dr };
                model.DepartmentModel = new PersonDepartmentModel
                {
                    Items = (from t in db.PersonDepartmentSet
                                                  where t.Person_Id == Id select t).ToList()
                };
                var q = (from o in (from t in db.DepartmentSet select t).Except((from t in model.DepartmentModel.Items select t.Department)) select o);
                foreach(var o in q)
                    model.DepartmentModel.Items.Add(new PersonDepartment { Person=dr, Department=o});

                return View(model);
            }
        }
 private IQueryable<PersonDepartment> Query(NespeDbContext db)
 {
     var drc = db.PersonDepartmentSet;
         //return (from t in drc from p in db.PersonSet from d in db.DepartmentSet where d.Id == t.Department_Id && p.Id == t.Person_Id select Normalize(t, p, d));
         //return (from t in drc from p in db.PersonSet from d in db.DepartmentSet where d.Id == t.Department_Id && p.Id == t.Person_Id select (tl, pl, dl)=> t);
         return (from t in drc select t);
 }
 private PersonDepartment Get(long Id, NespeDbContext db)
 {
     return (from t in Query(db) where t.Id == Id select t).FirstOrDefault();
 }
 private void Bind(PersonDepartment selected, NespeDbContext db)
 {
     selected.Person = (from t in db.PersonSet where t.Id == selected.Person_Id select t).FirstOrDefault();
     selected.Department = (from t in db.DepartmentSet where t.Id == selected.Department_Id select t).FirstOrDefault();
 }
 private IQueryable<Department> listDepartment()
 {
     using(var db=new NespeDbContext()){
         var r=(from t in db.DepartmentSet select t);
         return r;
     }
 }
        public ActionResult Details(PersonDepartmentModel model, FormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                using (var db = new NespeDbContext())
                {
                    var drc = db.PersonDepartmentSet;
                    var dr = Get(model.Selected.Id, db);
                    if (dr == null)
                    {
                        base.ModelState.AddModelError("Action.Details.Invalid.Id", "Invalid Id");
                        return RedirectToAction("Index");
                    }
                    model.Selected = dr;
                }

            }
            return View(model);
        }