private OperationStatus AlterEmployee(Employees empl) { if (ctx.Employees.Where(em => em.EmployeeID != empl.EmployeeID && em.EMail == empl.EMail).Count() == 0) { if (empl.Password != null && !Regex.IsMatch(empl.Password, "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$")) { return(OperationStatus.PASSWORD_REQ_NOT_MET); } var hasher = new Sha256PasswordUtil(); var r = ctx.Employees.FirstOrDefault(e => e.EmployeeID == empl.EmployeeID); r.EMail = empl.EMail; r.Name = empl.Name; r.Surname = empl.Surname; r.Telephone = empl.Telephone; r.JobPositionID = empl.JobPositionID; if (empl.Password != null) { r.Password = hasher.hash(empl.Password); } ctx.Entry(r).State = EntityState.Modified; ctx.SaveChanges(); return(OperationStatus.OK); } return(OperationStatus.DUPLICATE_EMAIL); }
private OperationStatus AddEmployee(Employees empl) { if (ctx.Employees.Where(em => em.EMail == empl.EMail).Count() == 0) { if (!Regex.IsMatch(empl.Password, "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$")) { return(OperationStatus.PASSWORD_REQ_NOT_MET); } var hasher = new Sha256PasswordUtil(); empl.Password = hasher.hash(empl.Password); empl.EmployeeStateID = 1; ctx.Employees.Add(empl); ctx.SaveChanges(); return(OperationStatus.OK); } return(OperationStatus.DUPLICATE_EMAIL); }