// transactional method public bool AcceptEmployee(int employeeId, int vacancyId, int responseId) { bool employeeDeactivated = false; bool vacancyDeactivated = false; bool responseRemoved = false; var employee = _employeeLogic.SelectById(employeeId); if (employee == null) { return(false); } var vacancy = _vacancyLogic.SelectById(vacancyId); if (vacancy == null) { return(false); } employeeDeactivated = _employeeLogic.Deactivate(employeeId); if (!employeeDeactivated) { return(false); } vacancyDeactivated = _vacancyLogic.Deactivate(vacancyId); if (!vacancyDeactivated) { _employeeLogic.Update(employee); return(false); } responseRemoved = _employeeLogic.DeleteVacancyResponse(responseId); if (!responseRemoved) { _employeeLogic.Update(employee); _vacancyLogic.Update(vacancy); return(false); } _employeeLogic.DeleteHiredVacancyResponses(employeeId, vacancyId); _vacancyLogic.DeleteHiredEmployeeResponses(employeeId, vacancyId); return(true); }
public static void Update(HttpRequestBase req, HttpResponseBase res) { int id = int.Parse(req["id"]); string firstName = req["firstName"]; string lastName = req["lastName"]; string city = req["city"]; bool relocation = req["relocation"] == "true"; string password = req["password"]; var image = req.Files["image"]; var employee = _employeeLogic.SelectById(id); if (employee == null) { res.Write(JsonConvert.SerializeObject ( new RequestResult("Error", "No such employee in Database") )); return; } if (!string.IsNullOrWhiteSpace(firstName)) { employee.FirstName = firstName; } if (!string.IsNullOrWhiteSpace(lastName)) { employee.LastName = lastName; } if (!string.IsNullOrWhiteSpace(city)) { employee.City = city; } if (!string.IsNullOrWhiteSpace(password)) { employee.Password = Convert.ToBase64String(_sha256.ComputeHash(Encoding.Unicode.GetBytes(password))); } if (relocation ^ employee.Relocation) { employee.Relocation = relocation; } if (image != null && image.ContentLength != 0) { var bytes = new byte[image.ContentLength]; image.InputStream.Read(bytes, 0, bytes.Length); employee.Photo = Convert.ToBase64String(bytes); } if (_employeeLogic.Update(employee)) { res.Write(JsonConvert.SerializeObject(new RequestResult("Success", "Profile has been updated."))); } else { res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Profile cannot be updated."))); } }