public async Task <EntityDentist> RegisterAsync(EntityDentist model) { if (_context.Dentist.Any(x => x.Email == model.Email)) { throw new AppException($"Email {model.Email} already exists."); } else { var hashedPassword = _generateSecurePassword.HashAndSaltPassword(model.HashedPassword); model.HashedPassword = hashedPassword; _context.Dentist.Add(model); await _context.SaveChangesAsync(); return(model); } }
public async Task <EntityDentist> UpdateAsync(int id, EntityDentist model) { var dentist = await _context.Dentist .SingleOrDefaultAsync(a => a.Id == id); if (dentist != null) { dentist.FirstName = model.FirstName; dentist.LastName = model.LastName; var hashedPassword = _generateSecurePassword.HashAndSaltPassword(model.HashedPassword); model.HashedPassword = hashedPassword; dentist.HashedPassword = model.HashedPassword; dentist.Email = ($"{model.FirstName.Substring(0, 1)}{model.LastName}@guldtand.com").ToLower(); _context.Dentist.UpdateRange(); await _context.SaveChangesAsync(); return(dentist); } throw new AppException("Unable to update. Provided id doesn't exist."); }