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 GetEmployeeDetails(string internalEmployeeId) { using (ZBWorksDBContext dbContext = new ZBWorksDBContext()) { ZB_USERDETAILS matchingEmployee = dbContext.ZBUSERDETAILs.Where (src => src.InternalEmployeeID == internalEmployeeId).FirstOrDefault(); if (matchingEmployee == null) { return(new MbsResult(false, "invalid")); } ZB_USERDETAILS retval = new ZB_USERDETAILS() { InternalEmployeeID = Guid.NewGuid().ToString(), EmployeeName = matchingEmployee.EmployeeName, Password = matchingEmployee.Password, Role = matchingEmployee.Role }; return(new MbsResult(true, retval)); } }
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)); } }