private User GetRelatedUserInfoFromRequest(HttpRequestBase request, User user) { Patient patient = null; Employee employee = null; bool isPatientExist = (request["patientExist"] == "exist"); bool isEmployeeExist = (request["employeeExist"] == "exist"); var patientRole = _roleLogic.GetByRoleName("Пациент"); var employeeRole = _roleLogic.GetByRoleName("Сотрудник"); user.Roles = new List <Role>(); if (isPatientExist && isEmployeeExist) { patient = GetNewPatientFromRequest(request); employee = GetNewEmployeeFromRequest(request); employee.LastName = patient.LastName; employee.FirstName = patient.FirstName; employee.MiddleName = patient.MiddleName; user.PatientData = _patientsLogic.Add(patient); user.Roles.Add(patientRole); user.EmployeeData = _employeesLogic.Add(employee); user.Roles.Add(employeeRole); } else if (isPatientExist) { patient = GetNewPatientFromRequest(request); user.PatientData = _patientsLogic.Add(patient); user.Roles.Add(patientRole); } else if (isEmployeeExist) { employee = GetNewEmployeeFromRequest(request); user.EmployeeData = _employeesLogic.Add(employee); user.Roles.Add(employeeRole); } return(user); }
public void InitialAdmin(User admin, string roleName) { var users = GetAll(); if (users == null || users.Count() == 0) { Role role = _rolesLogic.GetByRoleName(roleName); if (role != null) { admin.Roles = new List <Role> { role }; Add(admin); } else { throw new OperationCanceledException($"The operation canceled because role '{roleName}' does not exist."); } } }