Exemplo n.º 1
0
 public ActionResult Edit(Usergroup model, Guid?[] formlist, Guid?[] DelList)
 {
     if (GlobalClass.SystemSession)
     {
         Usergroup abm = db.Usergroup.Find(model.UserGroupKey);
         abm.GroupName = model.GroupName;
         abm.GroupID   = model.GroupID;
         db.SaveChanges();
         if (formlist == null)
         {
         }
         else
         {
             if (formlist.Count() > 0)
             {
                 foreach (var item in formlist)
                 {
                     db = new HasanHoutoneEntities();
                     Forms f = db.Forms.Find(item);
                     CheckForModule(f.ModuleID, model.UserGroupKey);
                     UserGroupForm obj = new UserGroupForm();
                     obj.CompanyKey       = GlobalClass.Company.CompanyKey;
                     obj.ModuleKey        = f.ModuleID;
                     obj.UserGroupKey     = abm.UserGroupKey;
                     obj.UserGroupFormKey = Guid.NewGuid();
                     obj.FormKey          = item;
                     db.UserGroupForm.Add(obj);
                     db.SaveChanges();
                 }
             }
         }
         if (DelList == null)
         {
         }
         else
         {
             if (DelList.Count() > 0)
             {
                 foreach (var item in DelList)
                 {
                     db = new HasanHoutoneEntities();
                     UserGroupForm f = db.UserGroupForm.Find(item);
                     CheckForModuleBeforDelete(f);
                     db.UserGroupForm.Remove(f);
                     db.SaveChanges();
                 }
             }
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         Exception e = new Exception("Sorry, your Session has Expired");
         return(View("Error", new HandleErrorInfo(e, "UserHome", "Logout")));
     }
 }
Exemplo n.º 2
0
        private void AddModulesToCompany(Forms obj, Guid id)
        {
            var t = from x in db.CompanyModule where x.ModuleKey == obj.ModuleID && x.CompanyKey == id select x;

            if (!(t.Count() > 0))
            {
                db = new HasanHoutoneEntities();
                CompanyModule a = new CompanyModule();
                a.CompanyModuleID = Guid.NewGuid();
                a.CompanyKey      = id;
                a.ModuleKey       = obj.ModuleID;
                db.CompanyModule.Add(a);
                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private void CheckForModuleBeforDelete(UserGroupForm f)
        {
            HasanHoutoneEntities ac = new HasanHoutoneEntities();
            var temp = from x in ac.UserGroupForm where x.UserGroupKey == f.UserGroupKey && x.ModuleKey == f.ModuleKey && x.CompanyKey == GlobalClass.Company.CompanyKey select x;

            if (temp.Count() > 0)
            {
            }
            else
            {
                UserGroupModule obj = db.UserGroupModule.FirstOrDefault(x => x.UserGroupKey == f.UserGroupKey && x.ModuleKey == f.ModuleKey && x.CompanyKey == GlobalClass.Company.CompanyKey);
                ac.UserGroupModule.Remove(obj);
                ac.SaveChanges();
            }
        }
Exemplo n.º 4
0
 public ActionResult Delete(Guid?id)
 {
     if (GlobalClass.SystemSession)
     {
         Usergroup company = db.Usergroup.Find(id);
         var       temp    = from x in db.UserGroupForm where x.UserGroupKey == id select x;
         var       temp2   = from x in db.UserGroupModule where x.UserGroupKey == id select x;
         var       temp3   = from x in db.StaffList where x.Usergr == id select x;
         if (temp.Count() > 0)
         {
             foreach (var a in temp)
             {
                 HasanHoutoneEntities ac   = new HasanHoutoneEntities();
                 UserGroupForm        form = db.UserGroupForm.Find(a.UserGroupFormKey);
                 ac.UserGroupForm.Remove(form);
                 ac.SaveChanges();
             }
         }
         if (temp3.Count() > 0)
         {
             foreach (var a in temp3)
             {
                 HasanHoutoneEntities ac   = new HasanHoutoneEntities();
                 StaffList            form = db.StaffList.Find(a.PersonnelKey);
                 form.Usergr = null;
                 ac.SaveChanges();
             }
         }
         if (temp2.Count() > 0)
         {
             foreach (var a in temp2)
             {
                 HasanHoutoneEntities ac   = new HasanHoutoneEntities();
                 UserGroupModule      form = db.UserGroupModule.Find(a.UserGroupModuleKey);
                 ac.UserGroupModule.Remove(form);
                 ac.SaveChanges();
             }
         }
         db.Usergroup.Remove(company);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         Exception e = new Exception("Sorry, your Session has Expired");
         return(View("Error", new HandleErrorInfo(e, "UserHome", "Logout")));
     }
 }
Exemplo n.º 5
0
        private void CheckForModule(Guid moduleID, Guid UserGroupKey)
        {
            HasanHoutoneEntities ac = new HasanHoutoneEntities();
            var temp = from x in ac.UserGroupModule where x.UserGroupKey == UserGroupKey && x.ModuleKey == moduleID && x.CompanyKey == GlobalClass.Company.CompanyKey select x;

            if (temp.Count() > 0)
            {
            }
            else
            {
                UserGroupModule obj = new UserGroupModule();
                obj.CompanyKey         = GlobalClass.Company.CompanyKey;
                obj.ModuleKey          = moduleID;
                obj.UserGroupKey       = UserGroupKey;
                obj.UserGroupModuleKey = Guid.NewGuid();
                ac.UserGroupModule.Add(obj);
                ac.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public ActionResult ConpanyUserAcess(Company model, Guid?[] unformlist, Guid?[] formlist)
        {
            if (GlobalClass.MasterSession)
            {
                if (unformlist == null)
                {
                }
                else
                {
                    if (unformlist.Count() > 0)
                    {
                        foreach (var temp in unformlist)
                        {
                            db = new HasanHoutoneEntities();
                            CompanyForm a         = db.CompanyForm.Find(temp);
                            Guid?       comkey    = a.CompanyKey;
                            Guid?       moduleKey = a.ModuleKey;
                            Guid?       formKey   = a.FormKey;
                            db.CompanyForm.Remove(a);
                            db.SaveChanges();
                            CheckCompanyForModule(comkey, moduleKey);

                            db = new HasanHoutoneEntities();
                            var fg = from m in db.UserGroupForm where m.FormKey == formKey && m.CompanyKey == comkey select m;
                            if (fg.Count() > 0)
                            {
                                foreach (var item in fg)
                                {
                                    HasanHoutoneEntities nr = new HasanHoutoneEntities();
                                    UserGroupForm        b  = nr.UserGroupForm.SingleOrDefault(m => m.UserGroupFormKey == item.UserGroupFormKey);
                                    Guid k  = (Guid)b.ModuleKey;
                                    Guid uk = (Guid)b.UserGroupKey;
                                    nr.UserGroupForm.Remove(b);
                                    nr.SaveChanges();
                                    CheckUserGroupForModule(k, uk);
                                }
                            }
                        }
                    }
                }
                if (formlist == null)
                {
                }
                else
                {
                    if (formlist.Count() > 0)
                    {
                        foreach (var temp in formlist)
                        {
                            db = new HasanHoutoneEntities();
                            Forms o = db.Forms.Find(temp);
                            AddModulesToCompany(o, model.CompanyKey);
                            CompanyForm a = new CompanyForm();
                            a.CompanyFormKey = Guid.NewGuid();
                            a.FormKey        = temp;
                            a.CompanyKey     = model.CompanyKey;
                            a.ModuleKey      = o.ModuleID;
                            db.CompanyForm.Add(a);
                            db.SaveChanges();
                        }
                    }
                }
                model = db.Company.Find(model.CompanyKey);
                ViewBag.CompanyKey = new SelectList(db.Company, "CompanyKey", "CompanyName", model.CompanyKey);
                return(View(model));
            }
            else
            {
                Exception e = new Exception("Session Expired");
                return(View("Error", new HandleErrorInfo(e, "AdminLogin", "UserHome")));
            }
        }