public ActionResult Login() { Utility utility = new Utility(); UserServiceModel dbUser = new UserServiceModel(); if (Membership.GetUser("admin") == null) { MembershipCreateStatus status; // Generate a new 12-character password with 1 non-alphanumeric character. //y0t(9ci&xUn^ string password = utility.GetUniqueKey(8); //Membership.GeneratePassword(8, 0); // string password = "******"; SMIM_UserMst_ST userentity = new SMIM_UserMst_ST(); userentity.UserName = "******"; userentity.UserTypeId = 1;//db.HRMS_UserType_ST.Where(x => x.Description == "Admin").Select(x => x.UserTypeId).FirstOrDefault(); userentity.FirstName = "admin"; userentity.LastName = "admin"; userentity.Email = "*****@*****.**"; userentity.CreateOn = System.DateTime.Now; userentity.CreatedBy = 0; dbUser.InsertUser(userentity); MembershipUser newUser = Membership.CreateUser("admin", password, "admin", "ok", "ok", true, out status); utility.sendMail("*****@*****.**", "Admin Credential", "Admin User created successfully<br/> Password is " + password); } return(View()); }
public ActionResult User(SMIM_UserMst_ST User) { try { string strMessage = ""; bool _success = false; if (User.UserId > 0) { utility.IsSpecifed <SMIM_UserMst_ST>(User); int maxValue = dbUser.UpdateUser(User); if (maxValue > 0) { strMessage = "Record successfully updated."; _success = true; } else { strMessage = "Application server error."; } } else { string password = new Utility().GetUniqueKey(8); //Membership.CreateUser(User.UserName, password); MembershipCreateStatus status; utility.IsSpecifed <SMIM_UserMst_ST>(User); int maxValue = dbUser.InsertUser(User); User.UserId = maxValue; if (maxValue > 0) { MembershipUser newUser = Membership.CreateUser(User.UserName, password, User.UserName, "ok", "ok", true, out status); strMessage = "Record successfully saved. Password for User '" + User.UserName + "' is " + password + ""; _success = true; } else { strMessage = "Application server error."; } } return(Json(new { success = _success, response = strMessage })); } catch (Exception ex) { Log.LogWrite(ex.Message, "User Insert/Edit", ex); return(Json(new { success = false, response = ex.Message.ToString() })); } }
public ActionResult Company(int?user, int?OrgId, int?CompanyId, CompanyDetail tt) { try { if (tt.CompanyID > 0) { SMSA_CompanyMst_ST Comp = dbUser.GetCompanyById(tt.CompanyID); #region Organization for each company if (tt.POrgId.HasValue && tt.POrgId > 0) { #region Organization SMSA_Organization_ST reqCompOrg = dbUser.GetOrganizationById(tt.OrgID); reqCompOrg.OrgType = tt.OrgType; reqCompOrg.SaleAccId = tt.SaleAccId; reqCompOrg.SaleAccIdSpecified = true; reqCompOrg.Description = reqCompOrg.UserName == "Org" + Comp.UserName ? tt.CompanyName : reqCompOrg.Description; dbUser.UpdateOrganization(reqCompOrg); Comp.OrgID = tt.POrgId.Value; Comp.OrgIDSpecified = true; #endregion } else { var lstOrg = dbUser.GetAllOrganization(); var reqOrgDefault = lstOrg.Where(x => x.UserName == "Org" + tt.UserName).FirstOrDefault(); if (reqOrgDefault != null) { #region Organization SMSA_Organization_ST reqCompOrg = dbUser.GetOrganizationById(reqOrgDefault.OrgID); reqCompOrg.OrgType = tt.OrgType; reqCompOrg.SaleAccId = tt.SaleAccId; reqCompOrg.SaleAccIdSpecified = true; reqCompOrg.Description = reqCompOrg.UserName == "Org" + Comp.UserName ? tt.CompanyName : reqCompOrg.Description; dbUser.UpdateOrganization(reqCompOrg); Comp.OrgID = reqOrgDefault.OrgID; Comp.OrgIDSpecified = true; #endregion } else { SMSA_Organization_ST org = new WPSService.SMSA_Organization_ST(); org.OrgType = tt.OrgType; org.SaleAccId = tt.SubAgentId > 0 ? tt.SubAgentId : tt.AgentId > 0 ? tt.AgentId : org.SaleAccId; org.SaleAccIdSpecified = true; org.Status = "A"; org.UserName = "******" + tt.UserName; org.CreatedBy = user; org.CreatedBySpecified = true; org.CreatedOn = DateTime.Now; org.CreatedOnSpecified = true; org.Description = tt.CompanyName; tt.POrgId = dbUser.InsertOrganization(org); Comp.OrgID = tt.POrgId.Value; Comp.OrgIDSpecified = true; if (Membership.GetUser(org.UserName) == null) { MembershipCreateStatus status; // Generate a new 12-character password with 1 non-alphanumeric character. //y0t(9ci&xUn^ string password = org.UserName + "123"; // utility.GetUniqueKey(8);//Membership.GeneratePassword(8, 0); // string password = "******"; MembershipUser newUser = Membership.CreateUser(org.UserName, password, org.UserName, "ok", "ok", true, out status); UserServiceClass.SMIM_UserMst_ST User = new UserServiceClass.SMIM_UserMst_ST(); User.UserId = 0; User.UserName = org.UserName; User.Email = tt.Email; User.FirstName = tt.ContactPerson; User.OrgId = tt.POrgId.Value; utility.IsSpecifed <UserServiceClass.SMIM_UserMst_ST>(User); int maxValue = db.InsertUser(User); } } } #endregion #region Company Comp.SMSA_Organization_ST = null; Comp.Address = tt.Address; Comp.CompanyName = tt.CompanyName; Comp.ContactPerson = tt.ContactPerson; Comp.Email = tt.Email; Comp.EstID = tt.EstID; Comp.IsActive = "Y"; Comp.IsApproved = "Y"; Comp.logoPath = tt.logoPath; Comp.Mobile = tt.Mobile; Comp.Phone = tt.Phone; Comp.SaleAccIdSpecified = true; if (tt.SubAgentId > 0) { Comp.SaleAccId = tt.SubAgentId; } else if (tt.AgentId > 0) { Comp.SaleAccId = tt.AgentId; } else { Comp.SaleAccId = null; } Comp.ModifyBy = user; Comp.ModifyBySpecified = true; Comp.ModifyOn = DateTime.Now; Comp.ModifyOnSpecified = true; dbUser.UpdateCompany(Comp); #endregion #region Activity Log SMSA_Logs_HI log = new SMSA_Logs_HI(); utility.IsSpecifed <SMSA_Logs_HI>(log); log.ActivityBy = user.Value; log.ActivityDesc = "Edit Company Details"; log.ActivityOn = DateTime.Now; log.ActivityType = "U"; log.ColumnId = tt.CompanyID; dbUser.AddActivityLog(log); #endregion //#region Organization //SMSA_Organization_ST reqOrg = dbUser.GetOrganizationById(tt.OrgID); //reqOrg.OrgType = tt.OrgType; //reqOrg.SaleAccId = tt.SaleAccId; //reqOrg.SaleAccIdSpecified = true; //reqOrg.Description = reqOrg.UserName == "Org" + Comp.UserName ? tt.CompanyName : reqOrg.Description; //dbUser.UpdateOrganization(reqOrg); //#endregion return(Json(new { success = true, response = "Company updated successfully." })); } else { #region Organization for each company if (tt.POrgId.HasValue && tt.POrgId > 0) { /*Organization laready defined and this company is part of group of companies*/ } else { SMSA_Organization_ST org = new WPSService.SMSA_Organization_ST(); org.OrgType = tt.OrgType; org.SaleAccId = tt.SubAgentId > 0 ? tt.SubAgentId : tt.AgentId > 0 ? tt.AgentId : org.SaleAccId; org.SaleAccIdSpecified = true; org.Status = "A"; org.UserName = "******" + tt.UserName; org.CreatedBy = user; org.CreatedBySpecified = true; org.CreatedOn = DateTime.Now; org.CreatedOnSpecified = true; org.Description = tt.CompanyName; tt.POrgId = dbUser.InsertOrganization(org); if (Membership.GetUser(org.UserName) == null) { MembershipCreateStatus status; // Generate a new 12-character password with 1 non-alphanumeric character. //y0t(9ci&xUn^ string password = org.UserName + "123"; //utility.GetUniqueKey(8);//Membership.GeneratePassword(8, 0); // string password = "******"; MembershipUser newUser = Membership.CreateUser(org.UserName, password, org.UserName, "ok", "ok", true, out status); UserServiceClass.SMIM_UserMst_ST User = new UserServiceClass.SMIM_UserMst_ST(); User.UserId = 0; User.UserName = org.UserName; User.Email = tt.Email; User.FirstName = tt.ContactPerson; User.OrgId = tt.POrgId.Value; utility.IsSpecifed <UserServiceClass.SMIM_UserMst_ST>(User); int maxValue = db.InsertUser(User); } } #endregion #region Company Insertion SMSA_CompanyMst_ST Comp = new SMSA_CompanyMst_ST(); Comp.OrgID = tt.POrgId.Value; Comp.OrgIDSpecified = true; Comp.Address = tt.Address; Comp.CompanyName = tt.CompanyName; Comp.ContactPerson = tt.ContactPerson; Comp.CreatedBy = user; Comp.CreatedBySpecified = true; Comp.CreatedOn = DateTime.Now; Comp.CreatedOnSpecified = true; Comp.Email = tt.Email; Comp.EstID = tt.EstID; Comp.IsActive = "Y"; Comp.IsApproved = "Y"; Comp.logoPath = tt.logoPath; Comp.Mobile = tt.Mobile; Comp.Phone = tt.Phone; Comp.SaleAccId = tt.SubAgentId > 0 ? tt.SubAgentId : tt.AgentId > 0 ? tt.AgentId : Comp.SaleAccId; Comp.SaleAccIdSpecified = true; Comp.UserName = tt.UserName; int rtn = dbUser.InsertCompany(Comp); #region Activity Log SMSA_Logs_HI log = new SMSA_Logs_HI(); utility.IsSpecifed <SMSA_Logs_HI>(log); log.ActivityBy = user.Value; log.ActivityDesc = "Add New Company"; log.ActivityOn = DateTime.Now; log.ActivityType = "I"; log.ColumnId = rtn; dbUser.AddActivityLog(log); #endregion if (rtn > 0) { if (Membership.GetUser(tt.UserName) == null) { MembershipCreateStatus status; // Generate a new 12-character password with 1 non-alphanumeric character. //y0t(9ci&xUn^ string password = tt.UserName + "123"; //utility.GetUniqueKey(8);//Membership.GeneratePassword(8, 0); // string password = "******"; MembershipUser newUser = Membership.CreateUser(tt.UserName, password, tt.UserName, "ok", "ok", true, out status); UserServiceClass.SMIM_UserMst_ST User = new UserServiceClass.SMIM_UserMst_ST(); User.UserId = 0; User.UserName = tt.UserName; User.Email = tt.Email; User.FirstName = tt.ContactPerson; User.OrgId = tt.POrgId.Value; User.CompanyId = rtn; utility.IsSpecifed <UserServiceClass.SMIM_UserMst_ST>(User); int maxValue = db.InsertUser(User); } return(Json(new { success = true, response = "Company registered successfully." })); } else if (rtn == 0) { return(Json(new { success = false, response = "Company already registered." })); } #endregion } } catch (Exception) { throw; } var req = tt; return(View(tt)); }