internal static MbsResult UpdateEmployee(ZBUserDetails updateEmployee) { using (ZBWorksDBContext dbContext = new ZBWorksDBContext()) { ZB_USERDETAILS matchingEmployee = dbContext.ZBUSERDETAILs.Where (src => src.InternalEmployeeID == updateEmployee.InternalEmployeeID).FirstOrDefault(); if (matchingEmployee == null) { return(new MbsResult(false, "invalid Credentails")); } if (updateEmployee.EmployeeName != matchingEmployee.EmployeeName) { matchingEmployee.EmployeeName = updateEmployee.EmployeeName; } if (updateEmployee.Role != matchingEmployee.Role) { matchingEmployee.Role = updateEmployee.Role; } if (updateEmployee.Password != matchingEmployee.Password) { matchingEmployee.Password = updateEmployee.Password; } dbContext.SaveChanges(); return(new MbsResult(true, "")); } }
internal static MbsResult AddNewEmployee(ZBUserDetails newEmployee) { using (ZBWorksDBContext dbContext = new ZBWorksDBContext()) { ZB_USERDETAILS matchingEmployee = new ZB_USERDETAILS() { InternalEmployeeID = Guid.NewGuid().ToString(), EmployeeName = newEmployee.EmployeeName, Password = newEmployee.Password, Role = newEmployee.Role }; dbContext.ZBUSERDETAILs.Add(matchingEmployee); dbContext.SaveChanges(); return(new MbsResult(true, "")); } }
internal static MbsResult UpdateEmployee(ZBUserDetails updateEmployee) { if (updateEmployee == null) { return(new MbsResult(false, "Invalid Employee Details")); } if (string.IsNullOrEmpty(updateEmployee.EmployeeName)) { return(new MbsResult(false, "Invalid Employee Name")); } if (string.IsNullOrEmpty(updateEmployee.Password)) { return(new MbsResult(false, "Invalid Employee password")); } return(DbEngine.UpdateEmployee(updateEmployee)); }
internal static MbsResult AuthenticateEmployee(ZBUserDetails employee) { using (ZBWorksDBContext dbContext = new ZBWorksDBContext()) { ZB_USERDETAILS matchingEmployee = dbContext.ZBUSERDETAILs.Where(src => src.EmployeeName == employee.EmployeeName && src.Password == employee.Password).FirstOrDefault(); //cheking and feching data from DB if (matchingEmployee == null) { return(new MbsResult(false, "Invalid credentails")); } ZBUserDetails retVal = new ZBUserDetails() { EmployeeName = matchingEmployee.EmployeeName, InternalEmployeeID = matchingEmployee.InternalEmployeeID, Role = matchingEmployee.Role, }; return(new MbsResult(true, retVal)); } }
public IHttpActionResult UpdateEmployee([FromBody] ZBUserDetails updateEmployee) { MbsResult retVal = EmployeeFacade.UpdateEmployee(updateEmployee); return(Ok(retVal)); }
public IHttpActionResult AddEmployee([FromBody] ZBUserDetails newEmployee) { MbsResult retVal = EmployeeFacade.AddEmployee(newEmployee); return(Ok(retVal)); }
public IHttpActionResult AuthenticateEmployee([FromBody] ZBUserDetails employee) { MbsResult retVal = EmployeeFacade.AuthenticateEmployee(employee); return(Ok(retVal)); }