Beispiel #1
0
        public bool CheckSecurity(string pagename)
        {
            string orgid       = User.OrgId;
            string roleid      = User.RoleId;
            bool   returnvalue = false;

            using (EPortalEntities entity = new EPortalEntities())
            {
                EPortal.Models.Page pagesobj = (from p in entity.Pages
                                                where p.Code == pagename
                                                select p).FirstOrDefault();
                if (pagesobj != null)
                {
                    EPortal.Models.Previleage prevobj = (from pre in entity.Previleages
                                                         where pre.PageId == pagesobj.Id &&
                                                         pre.OrganizationID == orgid &&
                                                         pre.RoleId == roleid
                                                         select pre).FirstOrDefault();
                    if (prevobj != null)
                    {
                        returnvalue = true;
                    }
                }
            }

            return(returnvalue);
        }
        public JsonResult SavePrivileges(List <ModuleNameList> moduleprevlist, string roleid)
        {
            int result = 0;
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;

            EPortal.Models.Previleage prev = null;
            using (EPortalEntities entity = new EPortalEntities())
            {
                foreach (ModuleNameList item in moduleprevlist)
                {
                    foreach (ModulePagelist modulepagelistitem in item.modulepagelist)
                    {
                        EPortal.Models.Previleage forupdaterecord = null;
                        forupdaterecord = (from p in entity.Previleages
                                           where p.RoleId == roleid &&
                                           p.PageId == modulepagelistitem.Id
                                           select p).FirstOrDefault();
                        if (forupdaterecord == null)
                        {
                            prev                = new Previleage();
                            prev.Id             = Guid.NewGuid().ToString();
                            prev.RoleId         = roleid;
                            prev.PageId         = modulepagelistitem.Id;
                            prev.OrganizationID = orgid;
                            prev.OperationId    = string.Empty;
                            prev.CreateDateTime = System.DateTime.Now;
                            prev.RowState       = true;
                            prev.PCreate        = modulepagelistitem.Create;
                            prev.PUpdate        = modulepagelistitem.Update;
                            prev.PDelete        = modulepagelistitem.Delete;
                            prev.PView          = modulepagelistitem.View;

                            entity.Entry(prev).State = System.Data.Entity.EntityState.Added;
                            entity.Previleages.Add(prev);
                        }
                        else
                        {
                            forupdaterecord.PCreate             = modulepagelistitem.Create;
                            forupdaterecord.PUpdate             = modulepagelistitem.Update;
                            forupdaterecord.PDelete             = modulepagelistitem.Delete;
                            forupdaterecord.PView               = modulepagelistitem.View;
                            entity.Entry(forupdaterecord).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                }
                try
                {
                    result = entity.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }

            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
        public JsonResult fileUpload(HttpPostedFileBase filedata)
        {
            EPortal.Models.Previleage        Previleageforadmin     = null;
            EPortal.Models.UserRole          Userroleforadmin       = new UserRole();
            List <EPortal.Models.Previleage> Previleageforadminlist = new List <Previleage>();
            List <EPortal.Models.Page>       getPage = new List <Page>();


            string errormsg      = string.Empty;
            int    resultforsave = 0;
            var    data          = Request.Files[0];
            bool   fileerror     = false;

            if (!Request.Files[0].ContentType.Contains("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
            {
                errormsg  = "Please select Excel file only.";
                fileerror = true;
            }
            if (fileerror == false)
            {
                #region Excel FIle upload
                //string orgid = Session["OrgId"].ToString();

                string orgid = User.OrgId;

                string path = string.Empty;
                //FileStream stream = new FileStream(data.FileName, FileMode.Open, FileAccess.Read);
                Excel.IExcelDataReader excelReader;
                excelReader = Excel.ExcelReaderFactory.CreateOpenXmlReader(data.InputStream);
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet result = excelReader.AsDataSet();
                List <EPortal.Models.UserInfo> useinfolist = new List <UserInfo>();
                EPortal.Models.UserInfo        useinfo     = null;

                using (EPortalEntities entity = new EPortalEntities())
                {
                    if (result.Tables.Count > 0)
                    {
                        foreach (var item in result.Tables[0].Rows)
                        {
                            string loginid = ((System.Data.DataRow)item).ItemArray[2].ToString();
                            string code    = ((System.Data.DataRow)item).ItemArray[0].ToString();

                            var checkexist = (from u in entity.UserInfoes
                                              where u.OrganizationID == orgid &&
                                              (u.LogInId == loginid || u.Code == code)
                                              select u).ToList();
                            if (checkexist.Count() > 0)
                            {
                                errormsg = "One or more User already exist with same Details.";
                                break;
                            }
                            if (!EmailValidate(((System.Data.DataRow)item).ItemArray[4].ToString()))
                            {
                                errormsg = "One or more User have invalid emailid.";
                                break;
                            }
                            if (errormsg == "")
                            {
                                useinfo         = new UserInfo();
                                useinfo.Id      = Guid.NewGuid().ToString();
                                useinfo.Code    = ((System.Data.DataRow)item).ItemArray[0].ToString();
                                useinfo.Name    = ((System.Data.DataRow)item).ItemArray[1].ToString();
                                useinfo.LogInId = loginid;
                                DateTime password = Convert.ToDateTime(((System.Data.DataRow)item).ItemArray[3].ToString());
                                useinfo.UserPassword   = loginid;
                                useinfo.DateOfBirth    = Convert.ToDateTime(((System.Data.DataRow)item).ItemArray[3].ToString());
                                useinfo.OrganizationID = orgid;
                                useinfo.RowState       = true;
                                useinfo.CreateDateTime = System.DateTime.Now;
                                useinfo.Email          = ((System.Data.DataRow)item).ItemArray[4].ToString();
                                useinfo.IsApplicant    = Convert.ToBoolean(Convert.ToInt16(((System.Data.DataRow)item).ItemArray[5].ToString()));
                                useinfo.MobileNo       = null;
                                useinfo.PhotoPath      = null;
                                useinfo.NoOfLogin      = null;



                                if (Convert.ToBoolean(Convert.ToInt16(((System.Data.DataRow)item).ItemArray[5].ToString())))
                                {
                                    useinfo.UserType = "40";
                                    #region For Applicant
                                    var roleid = (from r in entity.RoleMasters
                                                  where r.OrganizationID == orgid &&
                                                  r.Code == "Applicant"
                                                  select r).FirstOrDefault();

                                    Userroleforadmin                = new UserRole();
                                    Userroleforadmin.Id             = Guid.NewGuid().ToString();
                                    Userroleforadmin.UserId         = useinfo.Id;
                                    Userroleforadmin.RoleId         = roleid.Id;
                                    Userroleforadmin.OrganizationID = orgid;
                                    Userroleforadmin.RowState       = true;
                                    Userroleforadmin.CreateDateTime = System.DateTime.Now;
                                    entity.UserRoles.Add(Userroleforadmin);


                                    var checkroleexist = (from r in entity.Previleages
                                                          where r.OrganizationID == orgid &&
                                                          r.RoleId == roleid.Id
                                                          select r).ToList();

                                    if (checkroleexist.Count() == 0)
                                    {
                                        #region Get All Page
                                        getPage = (from p in entity.Pages
                                                   where p.Code != "Organization" &&
                                                   p.ForAdmin == false
                                                   select p).ToList();
                                        if (getPage.Count() > 0)
                                        {
                                            foreach (Page itemp in getPage)
                                            {
                                                Previleageforadmin                = new Previleage();
                                                Previleageforadmin.Id             = Guid.NewGuid().ToString();
                                                Previleageforadmin.RoleId         = roleid.Id;
                                                Previleageforadmin.PageId         = itemp.Id;
                                                Previleageforadmin.OperationId    = string.Empty;
                                                Previleageforadmin.PCreate        = true;
                                                Previleageforadmin.PUpdate        = true;
                                                Previleageforadmin.PDelete        = true;
                                                Previleageforadmin.PView          = true;
                                                Previleageforadmin.OrganizationID = orgid;
                                                Previleageforadmin.RowState       = true;
                                                Previleageforadmin.CreateDateTime = System.DateTime.Now;
                                                Previleageforadminlist.Add(Previleageforadmin);
                                            }
                                        }
                                        #endregion

                                        foreach (Previleage itempre in Previleageforadminlist)
                                        {
                                            entity.Entry(itempre).State = System.Data.Entity.EntityState.Added;
                                            entity.Previleages.Add(itempre);
                                        }
                                    }
                                    #endregion
                                }
                                entity.Entry(useinfo).State = System.Data.Entity.EntityState.Added;
                                entity.UserInfoes.Add(useinfo);
                            }
                        }
                    }
                    else
                    {
                        errormsg = "Selected file is empty.No Data found.";
                    }

                    if (errormsg == string.Empty)
                    {
                        try
                        {
                            resultforsave = entity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                #endregion
            }
            return(Json(new { result = resultforsave > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveUser(EPortal.Models.UserInfo UserInfo)
        {
            string errormsg = "";
            int    result   = 0;
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;



            #region Operation save

            EPortal.Models.Previleage        Previleageforadmin     = null;
            EPortal.Models.UserRole          Userroleforadmin       = new UserRole();
            List <EPortal.Models.Previleage> Previleageforadminlist = new List <Previleage>();
            List <EPortal.Models.Page>       getPage = new List <Page>();



            using (EPortalEntities entity = new EPortalEntities())
            {
                if (UserInfo.Operation == "Create")
                {
                    var checkforloginid = (from u in entity.UserInfoes
                                           where u.OrganizationID == orgid &&
                                           (u.LogInId == UserInfo.LogInId || u.Code == UserInfo.Code)
                                           select u).FirstOrDefault();
                    if (checkforloginid == null)
                    {
                        UserInfo.Id             = Guid.NewGuid().ToString();
                        UserInfo.OrganizationID = orgid;
                        UserInfo.RowState       = true;
                        UserInfo.CreateDateTime = System.DateTime.Now;
                        // string password = UserInfo.DateOfBirth.Value.Day + "-" + UserInfo.DateOfBirth.Value.Month + "-" + UserInfo.DateOfBirth.Value.Year;
                        UserInfo.UserPassword = UserInfo.LogInId;
                        UserInfo.IsApplicant  = UserInfo.IsApplicant;
                        UserInfo.MobileNo     = null;
                        if (UserInfo.Email == null || UserInfo.Email == "")
                        {
                            UserInfo.Email = null;
                        }
                        else
                        {
                            UserInfo.Email = UserInfo.Email;
                        }

                        UserInfo.PhotoPath           = null;
                        UserInfo.NoOfLogin           = null;
                        UserInfo.UserType            = "40";
                        entity.Entry(UserInfo).State = System.Data.Entity.EntityState.Added;
                        entity.UserInfoes.Add(UserInfo);

                        if (UserInfo.IsApplicant == true)
                        {
                            try
                            {
                                #region For Applicant
                                var roleid = (from r in entity.RoleMasters
                                              where r.OrganizationID == orgid &&
                                              r.Code == "Applicant"
                                              select r).FirstOrDefault();

                                Userroleforadmin                = new UserRole();
                                Userroleforadmin.Id             = Guid.NewGuid().ToString();
                                Userroleforadmin.UserId         = UserInfo.Id;
                                Userroleforadmin.RoleId         = roleid.Id;
                                Userroleforadmin.OrganizationID = orgid;
                                Userroleforadmin.RowState       = true;
                                Userroleforadmin.CreateDateTime = System.DateTime.Now;
                                entity.UserRoles.Add(Userroleforadmin);


                                var checkroleexist = (from r in entity.Previleages
                                                      where r.OrganizationID == orgid &&
                                                      r.RoleId == roleid.Id
                                                      select r).ToList();

                                if (checkroleexist.Count() == 0)
                                {
                                    #region Get All Page

                                    var getorgpage = (from p in entity.OrganizationPages
                                                      where p.OrganizationID == orgid
                                                      select p).ToList();

                                    getPage = (from p in entity.Pages
                                               where p.Code != "Organization" &&
                                               p.ForAdmin == false
                                               select p).ToList();
                                    if (getPage.Count() > 0)
                                    {
                                        foreach (var item in getorgpage)
                                        {
                                            Previleageforadmin                = new Previleage();
                                            Previleageforadmin.Id             = Guid.NewGuid().ToString();
                                            Previleageforadmin.RoleId         = roleid.Id;
                                            Previleageforadmin.PageId         = item.PageId;
                                            Previleageforadmin.OperationId    = string.Empty;
                                            Previleageforadmin.PCreate        = true;
                                            Previleageforadmin.PUpdate        = true;
                                            Previleageforadmin.PDelete        = true;
                                            Previleageforadmin.PView          = true;
                                            Previleageforadmin.OrganizationID = orgid;
                                            Previleageforadmin.RowState       = true;
                                            Previleageforadmin.CreateDateTime = System.DateTime.Now;
                                            Previleageforadminlist.Add(Previleageforadmin);
                                        }
                                    }
                                    #endregion

                                    foreach (Previleage item in Previleageforadminlist)
                                    {
                                        entity.Entry(item).State = System.Data.Entity.EntityState.Added;
                                        entity.Previleages.Add(item);
                                    }
                                }
                                #endregion
                            }
                            catch (Exception ex)
                            {
                                errormsg = ex.Message;
                            }
                        }
                    }
                    else
                    {
                        errormsg = "User already exist with same details.";
                    }
                    try
                    {
                        if (errormsg == "")
                        {
                            result = entity.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        errormsg = ex.Message;
                    }
                }
                else
                {
                    EPortal.Models.UserInfo usedata = (from o in entity.UserInfoes
                                                       where o.OrganizationID == orgid &&
                                                       o.Id == UserInfo.Id
                                                       select o
                                                       ).FirstOrDefault();
                    usedata.Code                = UserInfo.Code;
                    usedata.Name                = UserInfo.Name;
                    usedata.LogInId             = UserInfo.LogInId;
                    usedata.IsApplicant         = UserInfo.IsApplicant;
                    usedata.MobileNo            = UserInfo.MobileNo;
                    usedata.Email               = UserInfo.Email;
                    entity.Entry(usedata).State = System.Data.Entity.EntityState.Modified;
                    try
                    {
                        result = entity.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        errormsg = ex.Message;
                    }
                }
            }
            #endregion


            #region Send Mail
            if (UserInfo.Operation == "Create" && (UserInfo.Email != null || UserInfo.Email != ""))
            {
                bool sendmailper = false;
                using (EPortalEntities entity = new EPortalEntities())
                {
                    var checkformail = (from mc in entity.EMailConfigurations
                                        where mc.OrganizationId == orgid
                                        select mc).FirstOrDefault();
                    if (checkformail != null)
                    {
                        if (checkformail.UserCreationMail == true)
                        {
                            sendmailper = true;
                        }
                    }
                }
                if (sendmailper == true)
                {
                    string body     = "please find your UserName and Password below for E-Assessment.in ,UserName:"******" and Password :"******"";
                    string heading  = "Applicant " + UserInfo.Name + " created";
                    bool   sendmail = homecontroller.SendMail(UserInfo.Email, heading, body, null);
                }
            }
            #endregion


            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg, id = UserInfo.Id }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveOrganization(EPortal.Models.Organization orgdata)
        {
            string errormsg = "";
            int    result   = 0;

            if ((orgdata.Code != "" || orgdata.Code != null) && (orgdata.Name != "" || orgdata.Name != null))
            {
                // validation = EPortal.Utility.Utility.ValidateProperty(orgdata.Code, "Required");
                EPortal.Models.RoleMaster        roleadmin              = new RoleMaster();
                EPortal.Models.RoleMaster        roleapplicant          = new RoleMaster();
                EPortal.Models.UserInfo          Userforadmin           = new UserInfo();
                EPortal.Models.UserRole          Userroleforadmin       = new UserRole();
                EPortal.Models.Previleage        Previleageforadmin     = null;
                List <EPortal.Models.Previleage> Previleageforadminlist = new List <Previleage>();
                List <EPortal.Models.Page>       getPage = new List <Page>();



                using (EPortalEntities entity = new EPortalEntities())
                {
                    if (orgdata.Operation == "Create")
                    {
                        orgdata.Id = Guid.NewGuid().ToString();

                        #region Create AdminUser for This Organization
                        roleadmin.Id             = Guid.NewGuid().ToString();
                        roleadmin.Code           = "admin";
                        roleadmin.Name           = "admin";
                        roleadmin.OrganizationID = orgdata.Id;
                        roleadmin.RowState       = true;
                        roleadmin.CreateDateTime = System.DateTime.Now;



                        #region Create ROle for This User
                        roleapplicant.Id             = Guid.NewGuid().ToString();
                        roleapplicant.Code           = "Applicant";
                        roleapplicant.Name           = "Applicant";
                        roleapplicant.OrganizationID = orgdata.Id;
                        roleapplicant.RowState       = true;
                        roleapplicant.CreateDateTime = System.DateTime.Now;



                        #endregion

                        Userforadmin.Id             = Guid.NewGuid().ToString();
                        Userforadmin.Code           = "Admin";
                        Userforadmin.Name           = "Admin";
                        Userforadmin.LogInId        = "admin";
                        Userforadmin.UserPassword   = "******";
                        Userforadmin.UserType       = "50";
                        Userforadmin.OrganizationID = orgdata.Id;
                        Userforadmin.RowState       = true;
                        Userforadmin.CreateDateTime = System.DateTime.Now;

                        Userroleforadmin.Id             = Guid.NewGuid().ToString();
                        Userroleforadmin.UserId         = Userforadmin.Id;
                        Userroleforadmin.RoleId         = roleadmin.Id;
                        Userroleforadmin.OrganizationID = orgdata.Id;
                        Userroleforadmin.RowState       = true;
                        Userroleforadmin.CreateDateTime = System.DateTime.Now;



                        #endregion

                        #region Get All Page
                        getPage = (from p in entity.Pages
                                   where p.Code != "Organization" &&
                                   p.ForAdmin == true
                                   select p).ToList();
                        if (getPage.Count() > 0)
                        {
                            //foreach (Page item in getPage)
                            //{
                            //    Previleageforadmin = new Previleage();
                            //    Previleageforadmin.Id = Guid.NewGuid().ToString();
                            //    Previleageforadmin.RoleId = roleadmin.Id;
                            //    Previleageforadmin.PageId = item.Id;
                            //    Previleageforadmin.OperationId = string.Empty;
                            //    Previleageforadmin.PCreate = true;
                            //    Previleageforadmin.PUpdate = true;
                            //    Previleageforadmin.PDelete = true;
                            //    Previleageforadmin.PView = true;
                            //    Previleageforadmin.OrganizationID = orgdata.Id;
                            //    Previleageforadmin.RowState = true;
                            //    Previleageforadmin.CreateDateTime = System.DateTime.Now;
                            //    Previleageforadminlist.Add(Previleageforadmin);
                            //}
                        }
                        #endregion

                        entity.Entry(orgdata).State          = System.Data.Entity.EntityState.Added;
                        entity.Entry(roleadmin).State        = System.Data.Entity.EntityState.Added;
                        entity.Entry(roleapplicant).State    = System.Data.Entity.EntityState.Added;
                        entity.Entry(Userforadmin).State     = System.Data.Entity.EntityState.Added;
                        entity.Entry(Userroleforadmin).State = System.Data.Entity.EntityState.Added;

                        entity.Organizations.Add(orgdata);
                        entity.RoleMasters.Add(roleadmin);
                        entity.RoleMasters.Add(roleapplicant);
                        entity.UserInfoes.Add(Userforadmin);
                        entity.UserRoles.Add(Userroleforadmin);
                        //foreach (Previleage item in Previleageforadminlist)
                        //{
                        //    entity.Entry(item).State = System.Data.Entity.EntityState.Added;
                        //    entity.Previleages.Add(item);
                        //}
                        try
                        {
                            result = entity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        orgdata.Code      = orgdata.Code;
                        orgdata.Name      = orgdata.Name;
                        orgdata.ContactNo = orgdata.ContactNo;
                        orgdata.ESTDate   = orgdata.ESTDate;
                        orgdata.PhoneNo   = orgdata.PhoneNo;
                        orgdata.Email     = orgdata.Email;
                        orgdata.Address   = orgdata.Address;
                        orgdata.Country   = orgdata.Country;
                        orgdata.OrgState  = orgdata.OrgState;
                        orgdata.Location  = orgdata.Location;
                        orgdata.Pin       = orgdata.Pin;

                        entity.Entry(orgdata).State = System.Data.Entity.EntityState.Modified;
                        result = entity.SaveChanges();
                    }
                }
            }
            else
            {
                if (orgdata.Code != "" || orgdata.Code != null)
                {
                    errormsg = "Please enter Code.";
                }
                if (orgdata.Name != "" || orgdata.Name != null)
                {
                    errormsg = "Please enter Name.";
                }
            }

            return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult OrganizationSave(List <ModuleNameList> moduleprevlist, string orgid)
        {
            EPortal.Models.OrganizationPage orgpage            = null;
            EPortal.Models.Previleage       Previleageforadmin = null;
            int result = 0;

            using (EPortalEntities entity = new EPortalEntities())
            {
                foreach (var module in moduleprevlist)
                {
                    foreach (var modulepage in module.modulepagelist)
                    {
                        var checkexistornot = (from op in entity.OrganizationPages
                                               where op.OrganizationID == orgid &&
                                               op.PageId == modulepage.Id
                                               select op).FirstOrDefault();
                        string code = string.Empty;
                        if (module.Code == "OrganizationSetup" || module.Code == "UserManagement" || module.Code == "SchoolSetup" || module.Code == "Fee")
                        {
                            code = "Admin";
                        }
                        else
                        {
                            code = "Applicant";
                        }
                        var getroleid = (from r in entity.RoleMasters
                                         where r.OrganizationID == orgid &&
                                         r.Code == code
                                         select r).FirstOrDefault();
                        if (checkexistornot != null)
                        {
                            if (modulepage.Create == false)
                            {
                                entity.Entry(checkexistornot).State = System.Data.Entity.EntityState.Deleted;


                                if (getroleid != null)
                                {
                                    var prev = (from p in entity.Previleages
                                                where p.OrganizationID == orgid &&
                                                p.PageId == modulepage.Id &&
                                                p.RoleId == getroleid.Id
                                                select p).FirstOrDefault();
                                    if (prev != null)
                                    {
                                        entity.Entry(checkexistornot).State = System.Data.Entity.EntityState.Deleted;
                                    }
                                }
                            }
                            else
                            {
                                entity.Entry(checkexistornot).State = System.Data.Entity.EntityState.Modified;
                            }
                        }
                        else
                        {
                            if (modulepage.Create == true)
                            {
                                orgpage                     = new OrganizationPage();
                                orgpage.Id                  = Guid.NewGuid().ToString();
                                orgpage.OrganizationID      = orgid;
                                orgpage.PageId              = modulepage.Id;
                                orgpage.CreateDateTime      = System.DateTime.Now;
                                orgpage.RowState            = true;
                                entity.Entry(orgpage).State = System.Data.Entity.EntityState.Added;

                                Previleageforadmin                     = new Previleage();
                                Previleageforadmin.Id                  = Guid.NewGuid().ToString();
                                Previleageforadmin.RoleId              = getroleid.Id;
                                Previleageforadmin.PageId              = modulepage.Id;
                                Previleageforadmin.OperationId         = string.Empty;
                                Previleageforadmin.PCreate             = true;
                                Previleageforadmin.PUpdate             = true;
                                Previleageforadmin.PDelete             = true;
                                Previleageforadmin.PView               = true;
                                Previleageforadmin.OrganizationID      = orgid;
                                Previleageforadmin.RowState            = true;
                                Previleageforadmin.CreateDateTime      = System.DateTime.Now;
                                entity.Entry(Previleageforadmin).State = System.Data.Entity.EntityState.Added;
                                entity.Previleages.Add(Previleageforadmin);
                            }
                        }
                    }
                }
                result = entity.SaveChanges();
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }