public JsonResult GetUserInfo(EPortal.Models.UserInfo Userinfo) { //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; UserList UserinfoUser = new UserList(); using (EPortalEntities entity = new EPortalEntities()) { UserinfoUser = (from o in entity.UserInfoes where o.Id == Userinfo.Id && o.OrganizationID == orgid select new UserList { Id = o.Id, Code = o.Code, Name = o.Name, LogInId = o.LogInId, IsApplicant = o.IsApplicant.Value, MobileNo = o.MobileNo, Email = o.Email, Operation = "Edit", DateOfBirth = o.DateOfBirth.Value, ImageUrl = "/Home/GetFile?fileid=" + o.Id }).FirstOrDefault(); } return(Json(UserinfoUser, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteUser(EPortal.Models.UserInfo Userinfo) { //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; string errormsg = string.Empty; int result = 0; // validation = EPortal.Utility.Utility.ValidateProperty(orgdata.Code, "Required"); using (EPortalEntities entity = new EPortalEntities()) { var checkreferance = (from r in entity.ApplicantTests where r.OrganizationID == orgid && r.ApplicantId == Userinfo.Id select r).FirstOrDefault(); if (checkreferance != null) { errormsg = "Operation conflict:Operation cannot be performed.Record already in Used."; } else { entity.Entry(Userinfo).State = System.Data.Entity.EntityState.Deleted; result = entity.SaveChanges(); } } return(Json(new { result = result > 0 ? true : false, errormsg = errormsg }, JsonRequestBehavior.AllowGet)); }
public JsonResult ChangePassword(changePassword password) { string orgid = User.OrgId.ToString(); string userid = User.UserId.ToString(); int result = 0; string msg = ""; bool sendmailper = false; EPortal.Models.UserInfo model = null; using (EPortalEntities entity = new EPortalEntities()) { model = (from u in entity.UserInfoes where u.OrganizationID == orgid && u.Id == userid select u).FirstOrDefault(); if (model != null) { if (model.UserPassword == password.oldpassword) { model.UserPassword = password.newpassword; entity.Entry(model).State = System.Data.Entity.EntityState.Modified; result = entity.SaveChanges(); if (result > 0) { var checkformail = (from mc in entity.EMailConfigurations where mc.OrganizationId == orgid select mc).FirstOrDefault(); if (checkformail != null) { if (checkformail.AfterChangePasswordMail == true) { sendmailper = true; } } } } else { msg = "Please enter valid current password."; } } } if (sendmailper == true && (model.Email != null || model.Email != "")) { string body = "Hi " + model.Name + ",just now your password is change.if not you ,please contact us."; string heading = model.Name + " your password change"; bool sendmail = SendMail(model.Email, heading, body, null); } return(Json(new { result = result > 0 ? true : false, msg = msg }, JsonRequestBehavior.AllowGet)); }
public JsonResult ActivateUser(string Userid) { int result = 0; string msg = string.Empty; //string orgid = Session["OrgId"].ToString(); string orgid = User.OrgId; EPortal.Models.UserRole Userrole = null; EPortal.Models.UserInfo userinfo = null; using (EPortalEntities entity = new EPortalEntities()) { Userrole = (from us in entity.UserRoles where us.OrganizationID == orgid && us.UserId == Userid select us).FirstOrDefault(); userinfo = (from u in entity.UserInfoes where u.OrganizationID == orgid && u.Id == Userid select u).FirstOrDefault(); if (userinfo != null) { if (userinfo.NoOfLogin.HasValue && userinfo.NoOfLogin.Value == 1) { userinfo.NoOfLogin = null; entity.Entry(userinfo).State = System.Data.Entity.EntityState.Modified; } } if (Userrole != null) { Userrole.RowState = true; entity.Entry(Userrole).State = System.Data.Entity.EntityState.Modified; result = entity.SaveChanges(); } else { msg = "Please assign role for selected user."; } } return(Json(new { result = result > 0 ? true : false, msg = msg }, 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 ActionResult LostPasswordCheck(EPortal.Models.UserInfo lostpassword) { return(Json(true, 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)); }