public async Task Update(DentistDataModel request) { var dentist = await _dentistRepository.GetAsync(request.Id); if (dentist is null) { Notify("Dados do Dentista não encontrado."); return; } if (request.BirthDate == DateTime.MinValue) { Notify("Data inválida"); return; } dentist.Update(request.BirthDate, request.Cep, request.City, request.Complement, request.Cpf.Replace(".", "").Replace("-", ""), request.District, request.Email, request.Name, request.Number, request.State, request.Street, request.Cro, request.Expertise); if (dentist.IsValid()) { _dentistRepository.Update(dentist); } else { Notify(dentist.ValidationResult); return; } if (await CommitAsync() is false) { Notify("Erro ao salvar dados."); } }
public async Task <DentistDataModel> Get(Guid id) { DentistDataModel dentistModel = null; var dentist = await _dentistRepository.GetAsync(id); if (dentist is null) { Notify("Dados do Dentista não encontrado."); } else { dentistModel = new DentistDataModel() { Id = dentist.Id, BirthDate = dentist.BirthDate, Cep = dentist.Cep, City = dentist.City, Complement = dentist.Complement, Cpf = dentist.Cpf, Cro = dentist.Cro, Street = dentist.Street, Number = dentist.Number, State = dentist.State, District = dentist.District, Email = dentist.Email, Expertise = dentist.Expertise, Name = dentist.Name }; } return(dentistModel); }
public async Task <IActionResult> Create(DentistDataModel createDentistRequest) { if (ModelState.IsValid is false) { return(PartialView("_CreateDentist", createDentistRequest)); } await _dentistService.Create(createDentistRequest); if (ValidOperation() is false) { return(PartialView("_CreateDentist", createDentistRequest)); } var url = Url.Action("Index", "Dentist"); return(Json(new { success = true, url, messageText = "Dentista Cadastrado com Sucesso!" })); }
public async Task <IActionResult> Edit(Guid id, DentistDataModel createDentistRequest) { if (ModelState.IsValid is false) { return(PartialView("_EditDentist", createDentistRequest)); } createDentistRequest.Id = id; await _dentistService.Update(createDentistRequest); if (ValidOperation() is false) { return(PartialView("_EditDentist", createDentistRequest)); } var url = Url.Action("Index", "Dentist"); return(Json(new { success = true, url })); }
public async Task Create(DentistDataModel request) { var hasDentist = await _dentistRepository.GetAsync(request.Cpf); if (hasDentist is not null) { Notify("Já existe um dentista cadastrado com este cpf informado."); return; } if (request.BirthDate == DateTime.MinValue) { Notify("Data inválida"); return; } var userId = Guid.NewGuid(); if (request.CreateUser) { var user = new IdentityUser { UserName = request.Email, Email = request.Email }; userId = Guid.Parse(user.Id); var options = _userManager.Options.Password; var password = Utils.GeneratePassword(options.RequiredLength, options.RequireNonAlphanumeric, options.RequireDigit, options.RequireLowercase, options.RequireUppercase); var result = await _userManager.CreateAsync(user, password); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); await _userManager.ConfirmEmailAsync(user, code); await AddClaims(userId); _emailService.SendEmail(user.Email, "Credenciais de Acesso - SisOdonto", "Credenciais", $"Usuário: {user.Email} <br> Senha: {password}"); } else { Notify("Erro ao criar usuário."); return; } } var dentist = new Dentist(userId, request.BirthDate, request.Cep, request.City, request.Complement, request.Cpf.Replace(".", "").Replace("-", ""), request.District, request.Email, request.Name, request.Number, request.State, request.Street, request.Cro, request.Expertise); if (dentist.IsValid()) { await _dentistRepository.AddAsync(dentist); } else { var userManager = await _userManager.FindByIdAsync(userId.ToString()); if (userManager is not null) { await _userManager.DeleteAsync(userManager); } Notify(dentist.ValidationResult); return; } if (await CommitAsync() is false) { Notify("Erro ao salvar dados."); var userManager = await _userManager.FindByIdAsync(userId.ToString()); if (userManager is not null) { await _userManager.DeleteAsync(userManager); } } }