private LoginModel AuthenticateLogin(LoginModel model) { try { model.ResponseCode = 99; Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AuthenticateUser(model.UserName); if (employeeMaster != null) { string passowrd = employeeMaster.Password; string userId = employeeMaster.UserId.ToString(); if (passowrd.Equals(model.Password.Trim().EncodePasswordToBase64())) { model.Name = employeeMaster.EmployeeName + " (" + employeeMaster.EmployeeCode + ")"; model.UserId = Convert.ToInt32(userId); model.ResponseCode = 200; model.Message = "Success"; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); } else { model.Message = "Invalid username/password."; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.WrongPassword; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Invalid username/password."; auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } catch (Exception ex) { new Logger().LogException(ex, "AuthenticateLogin"); model.Message = ex.Message; } return(model); }
private AuthorizationModel IsAuthorized(int employeeId, string utilityCode) { AuthorizationModel model = new AuthorizationModel(); Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); DataTable dtEmployee = objEmployeeMaster.EmployeeMaster_ById(new Entity.HR.EmployeeMaster() { EmployeeMasterId = employeeId }); if (dtEmployee.AsEnumerable().Any()) { employeeMaster = objEmployeeMaster.AuthenticateUser(dtEmployee.Rows[0]["EmployeeCode"].ToString()); } if (employeeMaster != null) { string[] roles = employeeMaster.Roles.Split(','); model.ReturnValue = roles.Contains(utilityCode); } else { model.ReturnValue = false; } return(model); }
private List <Models.StockSnapModel> GetStockSnaps(int employeeId, string itemName) { List <Models.StockSnapModel> model = new List <StockSnapModel>(); Business.Inventory.Stock objStock = new Business.Inventory.Stock(); string name = (string.IsNullOrEmpty(itemName.Trim())) ? string.Empty : itemName.Trim(); Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); DataTable dtEmployee = objEmployeeMaster.EmployeeMaster_ById(new Entity.HR.EmployeeMaster() { EmployeeMasterId = employeeId }); if (dtEmployee.AsEnumerable().Any()) { employeeMaster = objEmployeeMaster.AuthenticateUser(dtEmployee.Rows[0]["EmployeeCode"].ToString()); } if (employeeMaster != null) { string[] roles = employeeMaster.Roles.Split(','); if (roles.Contains(Entity.HR.Utility.STOCK_LOOKUP)) { DataTable response = objStock.GetStockSnap(itemName); if (response != null && response.AsEnumerable().Any()) { foreach (DataRow dr in response.Rows) { model.Add(new Models.StockSnapModel { AssetLocationId = dr["AssetLocationId"].ToString(), ItemId = dr["ItemId"].ToString(), ItemType = dr["ItemType"].ToString(), Location = string.Format("Location: {0}", dr["Location"].ToString()), Quantity = string.Format("Quantity: {0}", dr["Quantity"].ToString()), ItemName = (Convert.ToInt32(dr["ItemType"].ToString()) == (int)ItemType.Product) ? string.Format("Product Name: {0}", dr["ProductName"].ToString()) : string.Format("Spare Name: {0}", dr["SpareName"].ToString()), }); } } } else { } } return(model); }
private void UserLogin() { try { Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AuthenticateUser(txtUserName.Text); if (employeeMaster != null) { string passowrd = employeeMaster.Password; string userId = employeeMaster.UserId.ToString(); if (employeeMaster.IsActive && passowrd.Equals(txtPassword.Text.Trim().EncodePasswordToBase64())) { if (employeeMaster.IsLoginActive) { string roles = employeeMaster.Roles; string userSettings = new Business.Settings.UserSettings().GetByUserId(Convert.ToInt32(userId)).Tables[0].Rows[0]["UserSettings"].ToString(); roles = string.Concat(roles, userSettings); Business.Common.Context.Username = employeeMaster.EmployeeName; Business.Common.Context.Image = employeeMaster.Image; Business.Common.Context.UserGender = employeeMaster.GenderId; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, userId, DateTime.Now, DateTime.Now.AddHours(2), false, roles, //define roles here "/"); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); Response.Cookies.Add(cookie); auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); if (employeeMaster.IsPasswordChangeRequired) { Response.Redirect(@"ResetPassword.aspx"); } else { Response.Redirect(@"Dashboard.aspx"); } } else { lblUserMessage.InnerHtml = "Login blocked by admin."; lblUserMessage.Visible = true; } } else { auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.WrongPassword; auth.Client = GetClient(); auth.FailedUserName = txtUserName.Text; auth.FailedPassword = txtPassword.Text; objEmployeeMaster.Login_Save(auth); lblUserMessage.InnerHtml = "Invalid Username/Password"; lblUserMessage.Visible = true; } } else { auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = txtUserName.Text; auth.FailedPassword = txtPassword.Text; objEmployeeMaster.Login_Save(auth); lblUserMessage.InnerHtml = "Invalid Username/Password"; lblUserMessage.Visible = true; } } catch (Exception ex) { ex.WriteException(); lblUserMessage.InnerHtml = "Invalid Username/Password"; lblUserMessage.Visible = true; } }
private LoginModel UserLogin(LoginModel model) { try { model.ResponseCode = 99; Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); Entity.Common.Auth auth = new Auth(); employeeMaster = objEmployeeMaster.AuthenticateUser(model.UserName); if (employeeMaster != null) { string passowrd = employeeMaster.Password; string userId = employeeMaster.UserId.ToString(); if (passowrd.Equals(model.Password.Trim().EncodePasswordToBase64())) { DataTable dtDevices = objEmployeeMaster.LinkedDevices_GetByUserId(employeeMaster.UserId); if (dtDevices != null && dtDevices.Rows.Count > 0) { model.ResponseCode = 99; model.Message = "A device is already linked with you. Please contact admin to change device."; } else if (employeeMaster.IsPasswordChangeRequired) { model.ResponseCode = 99; model.Message = "Reset password needed. Please visit aegiscrm.in to reset password."; } else if (!employeeMaster.IsLoginActive) { model.ResponseCode = 99; model.Message = "Login blocked by admin."; } else { model.Name = employeeMaster.EmployeeName + " (" + employeeMaster.EmployeeCode + ")"; model.UserId = Convert.ToInt32(userId); model.ResponseCode = 200; model.Message = "Success"; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Success; auth.Client = GetClient(); objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Invalid username/password."; auth.UserId = Convert.ToInt32(userId); auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.WrongPassword; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } else { model.Message = "Invalid username/password."; auth.IP = GetIP(); auth.Status = Entity.Common.LoginStatus.Failed; auth.Client = GetClient(); auth.FailedUserName = model.UserName; auth.FailedPassword = model.Password; objEmployeeMaster.Login_Save(auth); } } catch (Exception ex) { new Logger().LogException(ex, "UserLogin"); model.Message = ex.Message; } return(model); }
private List <Models.TonerModel> GetToner(int employeeId) { List <Models.TonerModel> model = new List <Models.TonerModel>(); Business.Service.TonerRequest objTonnerRequest = new Business.Service.TonerRequest(); Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); DataTable dtEmployee = objEmployeeMaster.EmployeeMaster_ById(new Entity.HR.EmployeeMaster() { EmployeeMasterId = employeeId }); if (dtEmployee.AsEnumerable().Any()) { employeeMaster = objEmployeeMaster.AuthenticateUser(dtEmployee.Rows[0]["EmployeeCode"].ToString()); } int assignEngineer = 0; if (employeeMaster != null) { string[] roles = employeeMaster.Roles.Split(','); if (roles.Contains(Entity.HR.Utility.CUSTOMER_LIST_SHOW_ALL)) { assignEngineer = 0; } else { assignEngineer = employeeId; } } string callStatusIds = string.Empty; callStatusIds = string.Concat(((int)CallStatusType.TonerOpenForApproval).ToString(), ",", ((int)CallStatusType.TonerRequestInQueue).ToString(), ",", ((int)CallStatusType.TonerResponseGiven).ToString()); DataTable response = objTonnerRequest.Service_Toner_GetByCallStatusIds(callStatusIds, assignEngineer); if (response != null && response.AsEnumerable().Any()) { foreach (DataRow dr in response.Rows) { model.Add(new Models.TonerModel { CallStatus = string.Format("Call Status: {0}", dr["CallStatus"].ToString()), ContactPerson = string.Format("Contact Person: {0}", dr["ContactPerson"].ToString()), CustomerName = string.Format("Customer Name: {0}", dr["CustomerName"].ToString()), TonerDateTime = string.Format("Toner Date & Time: {0}", Convert.ToDateTime(dr["RequestDate"].ToString()).ToString("dd MMM yyyy")), TonerNo = string.Format("Toner No: {0}", dr["TonnerRequestId"].ToString()), ProductName = string.Format("Product Name: {0}", dr["ProductName"].ToString()) }); } } return(model); }
private List <Models.DocketModel> GetDocket(int employeeId) { List <Models.DocketModel> model = new List <Models.DocketModel>(); Business.Service.Docket objDocket = new Business.Service.Docket(); Entity.Service.Docket docket = new Entity.Service.Docket(); Business.HR.EmployeeMaster objEmployeeMaster = new Business.HR.EmployeeMaster(); Entity.HR.EmployeeMaster employeeMaster = new Entity.HR.EmployeeMaster(); DataTable dtEmployee = objEmployeeMaster.EmployeeMaster_ById(new Entity.HR.EmployeeMaster() { EmployeeMasterId = employeeId }); if (dtEmployee.AsEnumerable().Any()) { employeeMaster = objEmployeeMaster.AuthenticateUser(dtEmployee.Rows[0]["EmployeeCode"].ToString()); } int assignEngineer = 0; if (employeeMaster != null) { string[] roles = employeeMaster.Roles.Split(','); if (roles.Contains(Entity.HR.Utility.CUSTOMER_LIST_SHOW_ALL)) { assignEngineer = 0; } else { assignEngineer = employeeId; } } string callStatusIds = string.Empty; callStatusIds = string.Concat(((int)CallStatusType.DocketClose).ToString(), ",", ((int)CallStatusType.DocketFunctional).ToString());//DOCKET CLOSE && FUNCTIONAL docket.CallStatusIds = callStatusIds; docket.AssignEngineer = assignEngineer; DataTable response = objDocket.Service_Docket_GetAllByCallStatusIds(docket); if (response != null && response.AsEnumerable().Any()) { foreach (DataRow dr in response.Rows) { model.Add(new Models.DocketModel { AssignedEngineerName = string.Format("Assigned Engineer: {0}", dr["AssignedEngineerName"].ToString()), CallStatus = string.Format("Call Status: {0}", dr["CallStatus"].ToString()), ContactPerson = string.Format("Contact Person: {0}", dr["ContactPerson"].ToString()), CustomerName = string.Format("Customer Name: {0}", dr["CustomerName"].ToString()), DocketDateTime = string.Format("Docket Date & Time: {0}", Convert.ToDateTime(dr["DocketDate"].ToString()).ToString("dd MMM yyyy")), DocketNo = string.Format("Docket No: {0}", dr["DocketId"].ToString()), IsCallAttended = string.Format("Call Attended: {0}", (dr["IsCallAttended"].ToString().Equals("1")) ? "True" : "False"), ProductName = string.Format("Product Name: {0}", dr["ProductName"].ToString()) }); } } return(model); }