public JsonResult GetOrganizationInfo(EPortal.Models.Organization orginfo) { OrgList org = new OrgList(); using (EPortalEntities entity = new EPortalEntities()) { org = (from o in entity.Organizations where o.Id == orginfo.Id select new OrgList { Id = o.Id, Code = o.Code, Name = o.Name, ContactNo = o.ContactNo, Email = o.Email, ESTDate = o.ESTDate, PhoneNo = o.PhoneNo, Address = o.Address, Location = o.Location, OrgState = o.OrgState, Country = o.Country, Pin = o.Pin, Operation = "Edit", ImageUrl = "/Home/GetOrgLogo?orgid=" + o.Id }).FirstOrDefault(); } return(Json(org, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteOrganization(EPortal.Models.Organization orgdata) { int result = 0; // validation = EPortal.Utility.Utility.ValidateProperty(orgdata.Code, "Required"); using (EPortalEntities entity = new EPortalEntities()) { entity.Entry(orgdata).State = System.Data.Entity.EntityState.Deleted; result = entity.SaveChanges(); } return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet)); }
public ActionResult Login(EPortal.Models.UserInfo Userinfo) { if (Userinfo == null) { throw new ArgumentNullException(nameof(Userinfo)); } JavaScriptSerializer serializer = new JavaScriptSerializer(); EPortal.Models.Organization org = null; EPortal.Models.UserInfo Userdata = null; EPortal.Models.UserRole Userrole = null; bool sendmailper = false; using (EPortalEntities entity = new EPortalEntities()) { try { org = (from o in entity.Organizations where o.Code == Userinfo.OrganizationName select o).FirstOrDefault(); } catch (Exception) { } if (org != null) { Userdata = (from u in entity.UserInfoes where u.OrganizationID == org.Id && u.LogInId == Userinfo.LogInId && u.UserPassword == Userinfo.UserPassword select u).FirstOrDefault(); if (Userdata != null) { Userrole = (from ro in entity.UserRoles where ro.OrganizationID == org.Id && ro.UserId == Userdata.Id && ro.RowState == true select ro).FirstOrDefault(); } var checkformail = (from mc in entity.EMailConfigurations where mc.OrganizationId == org.Id select mc).FirstOrDefault(); if (checkformail != null) { if (checkformail.AfterLoginMail == true) { sendmailper = true; } } } } if (Userdata != null && Userrole != null) { CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); //FormsAuthentication.SetAuthCookie(Userdata.LogInId, true); serializeModel.OrgId = org.Id; //Session["OrgId"] = org.Id; // Session["OrgName"] = org.Name; serializeModel.OrgName = org.Name; //Session["UserId"] = Userdata.Id; serializeModel.UserId = Userdata.Id; //Session["UserName"] = Userdata.Name; serializeModel.UserName = Userdata.Name; //Session["ISApplicant"] = Userdata.IsApplicant; serializeModel.ISApplicant = Userdata.IsApplicant.ToString(); if (Userrole != null) { //Session["RoleId"] = Userrole.RoleId; serializeModel.RoleId = Userrole.RoleId; } string userData = serializer.Serialize(serializeModel); //FormsAuthentication.SetAuthCookie(Userdata.LogInId, true); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, Userinfo.LogInId, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData.ToString(), FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(GetAuthTicket(GetAuthTicket1(authTicket: authTicket))); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, GetEncTicket(encTicket)); Response.Cookies.Add(cookie: faCookie); int cookieSize = Encoding.UTF8.GetByteCount(faCookie.Values.ToString()); if (sendmailper == true) { //getting client ip address string ipAddress = Request.UserHostAddress.ToString(); //getting client browser name string browserName = Request.Browser.Browser.ToString(); //getting client browser version string body = "Hi,Just now someone login to youe acocunt with IP:" + ipAddress + ",Browser:" + browserName + Request.Browser.Version.ToString() + ",If not you please contact us."; string heading = "User login Details:"; if (Userdata.Email != null || Userdata.Email != "") { bool sendmail = SendMail(Userdata.Email, heading, body, null); } } //var log = new logWriter("Login Successful for user:"******"UserHome")); } else { Session["InvalidUser"] = true; return(Redirect("/Home/Index")); } }
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 GetprivilegeInfo(EPortal.Models.Organization org) { string orgid = org.Id; List <OrganizationPageList> organpagelist = new List <OrganizationPageList>(); List <ModuleNameList> listmodule = new List <ModuleNameList>(); using (EPortalEntities entity = new EPortalEntities()) { organpagelist = (from m in entity.Modules join mp in entity.ModulePages on m.Id equals mp.ModuleId join p in entity.Pages on mp.PageId equals p.Id join op in entity.OrganizationPages on new { Orgid = orgid, pageid = p.Id } equals new { Orgid = op.OrganizationID, pageid = op.PageId } into j1 from op in j1.DefaultIfEmpty() where m.SequenceNo != null select new OrganizationPageList { ModuleidId = m.Id, ModuleCode = m.Code, ModuleName = m.Name, moduleseq = m.SequenceNo, PageId = p.Id, PageCode = p.Code, pageName = p.Name, pageseq = p.SequenceNo, PageSelected = op == null ? false : true }).ToList(); if (organpagelist.Count() > 0) { listmodule = (from m in organpagelist group m by new { sequ = m.moduleseq, moduleid = m.ModuleidId, modulecode = m.ModuleCode, modulename = m.ModuleName } into j1 select new ModuleNameList { Id = j1.Key.moduleid, Code = j1.Key.modulecode, Name = j1.Key.modulename, SequenceNo = j1.Key.sequ, modulepagelist = (from pa in organpagelist where pa.ModuleidId == j1.Key.moduleid select new ModulePagelist { Id = pa.PageId, Code = pa.PageCode, Name = pa.pageName, SequenceNo = pa.pageseq, Create = pa.PageSelected }).OrderBy(x => x.SequenceNo).ToList() }).OrderBy(x => x.SequenceNo).ToList(); } } return(Json(listmodule, JsonRequestBehavior.AllowGet)); }