public async Task <Tuple <string, string> > CreatePsychologistAsync(CreatePsychologistDTO newPsychologist) { string status = String.Empty; string description = String.Empty; var check = await this._userManager.FindByEmailAsync(newPsychologist.Email); if (check == null) { Gender? gender = newPsychologist.Gender != String.Empty ? (Gender?)Enum.Parse(typeof(Gender), newPsychologist.Gender) : null; string[] Date = newPsychologist.HireDate.Split('/', StringSplitOptions.RemoveEmptyEntries); User user = new Psychologist() { UserName = newPsychologist.Email, FirstName = newPsychologist.FirstName, LastName = newPsychologist.LastName, Email = newPsychologist.Email, EmailConfirmed = true, Blocked = false, RoleId = 2, Gender = gender, Address = newPsychologist.Address, PhoneNumber = newPsychologist.Phone, Position = "Psychologist", HireDate = new DateTime(Int32.Parse(Date[2]), Int32.Parse(Date[0]), Int32.Parse(Date[1])) }; var result = await _userManager.CreateAsync(user, newPsychologist.Password); if (result.Succeeded) { var add_role = await _userManager.AddToRoleAsync(user, "Psychologist"); status = "success"; description = "User created successfully"; } else { status = "error"; description = "Server error."; } } else { status = "error"; description = "User with this email already exists."; } return(new Tuple <string, string>(status, description)); }
public async Task <Tuple <string, string> > EditPsychologistAsync(CreatePsychologistDTO psychologistDTO) { string status = String.Empty; string description = String.Empty; Psychologist psychologist = (Psychologist)await this._userManager.FindByIdAsync(psychologistDTO.Id.ToString()); var check = await this._userManager.FindByEmailAsync(psychologistDTO.Email); if (check == null || psychologist.Id == check.Id) { psychologist.FirstName = psychologistDTO.FirstName; psychologist.LastName = psychologistDTO.LastName; psychologist.Email = psychologistDTO.Email; psychologist.UserName = psychologistDTO.Email; psychologist.Address = psychologistDTO.Address; psychologist.PhoneNumber = psychologistDTO.Phone; psychologist.Gender = psychologistDTO.Gender != String.Empty ? (Gender?)Enum.Parse(typeof(Gender), psychologistDTO.Gender) : null; if (psychologistDTO.Password != "") { } var result = await this._userManager.UpdateAsync(psychologist); if (result.Succeeded) { status = "success"; description = "User updated successfully"; } else { status = "error"; description = "Server error."; } } else { status = "error"; description = "User with this email already exists."; } return(new Tuple <string, string>(status, description)); }
public async Task <CreatePsychologistDTO> GetPsychologistForEditAsync(int id) { Psychologist psychologist = (Psychologist)await _userManager.FindByIdAsync(id.ToString()); CreatePsychologistDTO forEdit = new CreatePsychologistDTO { Id = psychologist.Id, Email = psychologist.Email, FirstName = psychologist.FirstName, LastName = psychologist.LastName, Address = psychologist.Address, Gender = psychologist.Gender.ToString(), Phone = psychologist.PhoneNumber, Position = psychologist.Position, HireDate = $"{psychologist.HireDate.Month}/{psychologist.HireDate.Day}/{psychologist.HireDate.Year}", Password = "" }; return(forEdit); }
public async Task <IActionResult> EditPsychologist(CreatePsychologistDTO model) { Tuple <string, string> tuple = await this.PsychoLogic.AdminFacade.EditPsychologistAsync(model); return(Json(new { status = tuple.Item1, description = tuple.Item2 })); }
public async Task <IActionResult> EditPsychologist(int id) { CreatePsychologistDTO psychologistDTO = await PsychoLogic.AdminFacade.GetPsychologistForEditAsync(id); return(PartialView(psychologistDTO)); }