public IActionResult Create([FromBody] Login credentials) { if (credentials.Username.ToString() == null || credentials.Password == null) { return(BadRequest("Username or Password was not provided!")); } var newEmpUtil = new EmployeeUtils(); try { var newEmployee = newEmpUtil.LogIn(credentials.Username, credentials.Password); if (newEmployee != null) { if (!checkforSession(credentials.Username)) { _context.Employees.Add(newEmployee); _context.SaveChanges(); return(CreatedAtRoute("LoginEmployee", new { id = newEmployee.EmployeeId }, newEmployee)); } return(Json(newEmployee)); } return(NotFound($"Couldn't Login Employee {credentials.Username}! ")); } catch (Exception e) { return(NotFound($"Couldn't Login Employee {credentials.Username}! " + e)); } }
public IActionResult ResetPw([FromBody] PWResetInfo newCustInfo, int id) { if (newCustInfo.ManagerInfo.Username.ToString() == null || newCustInfo.ManagerInfo.Password == null) { return(BadRequest("Username or Password was not provided!")); } var newEmpUtil = new EmployeeUtils(); try { var newEmployee = newEmpUtil.LogIn(newCustInfo.ManagerInfo.Username, newCustInfo.ManagerInfo.Password); if (newEmployee != null) { var newEmployeeUtils = new EmployeeUtils(); var empToClean = newEmployeeUtils.GetEmployeeById(id); if (empToClean != null) { Login updatedInfo = new Login(); updatedInfo.Username = id; updatedInfo.Password = newCustInfo.NewPw; if (newEmployeeUtils.EditEmployeePW(updatedInfo)) { return(Ok()); } return(StatusCode(500, "Error, Couldnt update the User Password! ")); } } return(NotFound($"Couldn't Login Employee {newCustInfo.ManagerInfo.Username}! ")); } catch (Exception e) { return(NotFound($"You Broke something, Great Job!! " + e)); } }
public IActionResult Create([FromBody] Login credentials, int id) { if (credentials.Username.ToString() == null || credentials.Password == null) { return(BadRequest("Username or Password was not provided!")); } var newEmpUtil = new EmployeeUtils(); try { var newEmployee = newEmpUtil.LogIn(credentials.Username, credentials.Password); if (newEmployee != null) { return(Json(newEmployee)); } return(NotFound($"Couldn't Login Employee {credentials.Username}! ")); } catch (Exception e) { return(NotFound($"Couldn't Login Employee {credentials.Username}! " + e)); } }