/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="oldPassword"></param> /// <param name="newPassword"></param> /// <returns></returns> public DataSet TSWeeklyEmail(string SPName, string EmpId, string Date) { DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); DataSet retVal = new DataSet(); retVal.Tables.Add(dt); retVal.Tables.Add(dt1); using (PortalDBEntities db = new PortalDBEntities()) { var entityConn = db.Database.Connection; var cmd = entityConn.CreateCommand(); cmd.CommandText = SPName; cmd.Connection.Open(); cmd.Parameters.Add(new SqlParameter("EMPLOYEEID", EmpId)); cmd.Parameters.Add(new SqlParameter("Date", Date)); cmd.CommandType = CommandType.StoredProcedure; var reader = cmd.ExecuteReader(); retVal.Load(reader, LoadOption.OverwriteChanges, dt, dt1); cmd.Connection.Close(); } return(retVal); }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <param name="roleName"></param> /// <returns></returns> public override bool IsUserInRole(string userName, string roleName) { if (String.IsNullOrEmpty(userName)) { throw new ArgumentException("Value cannot be null or empty.", "userName"); } using (PortalDBEntities db = new PortalDBEntities()) { Login login = db.Logins.FirstOrDefault(x => x.UserId.ToUpper().Equals(userName.ToUpper())); if (login == null) { return(false); } EmployeeRole employeeRole = login.Employee.EmployeeRoles.FirstOrDefault(x => x.Role.Name.Equals(roleName)); if (employeeRole != null) { return(true); } else { return(false); } } }
/// <summary> /// Validate user information /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="active"></param> /// <returns></returns> public override bool ValidateUser(string userName, string password) { if (String.IsNullOrEmpty(userName)) { throw new ArgumentException("Value cannot be null or empty.", "userName"); } if (String.IsNullOrEmpty(password)) { throw new ArgumentException("Value cannot be null or empty.", "password"); } using (PortalDBEntities db = new PortalDBEntities()) { //Get the login information by user name Login login = db.Logins.SingleOrDefault(x => x.UserId.ToUpper().Equals(userName.ToUpper())); if (login == null) { return(false); } //Employee emp = db.Employees.SingleOrDefault(x => x.Active.Equals(0)); Employee emp = db.Employees.Where(x => x.Id == login.Employee_Id).FirstOrDefault(); //if (emp.Active.Equals(0)) //return false; if (emp == null) { return(false); } //Decript password string decryptedPassword = password; if (!login.Password.Equals(decryptedPassword)) { return(false); } if (!emp.Active) { return(false); } return(true); } }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { using (PortalDBEntities db = new PortalDBEntities()) { //Get the login information by user name Login login = db.Logins.SingleOrDefault(x => x.UserId.ToUpper().Equals(username.ToUpper())); if (login == null) { return(false); } login.Password = newPassword; login.Status = (int)LoginStatus.EXISTING; db.Logins.Attach(login); db.Entry(login).State = EntityState.Modified; db.SaveChanges(); return(true); } }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <returns></returns> public override string[] GetRolesForUser(string userName) { if (String.IsNullOrEmpty(userName)) { throw new ArgumentException("Value cannot be null or empty.", "userName"); } List <string> roles = new List <string>(); using (PortalDBEntities db = new PortalDBEntities()) { Login login = db.Logins.FirstOrDefault(x => x.UserId.ToUpper().Equals(userName.ToUpper())); if (login == null) { return(null); } login.Employee.EmployeeRoles.ToList().ForEach(x => roles.Add(x.Role.Name)); } return(roles.ToArray()); }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> protected override void Initialize(RequestContext requestContext) { if (taskService == null) { taskService = new TaskService(); } if (MembershipService == null) { MembershipService = new MembershipService(); } if (AuthenticationService == null) { AuthenticationService = new FormsAuthenticationService(); } if (db == null) { db = new PortalDBEntities(); } base.Initialize(requestContext); }
public BaseService() { this.db = new PortalDBEntities(); }