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."); }
public async Task <EntityAdmin> UpdateAsync(int id, EntityAdmin model) { var admin = await _context.Admin .SingleOrDefaultAsync(a => a.Id == id); if (admin != null) { admin.FirstName = model.FirstName; admin.LastName = model.LastName; admin.PhoneNumber = model.PhoneNumber; var hashedPassword = _generateSecurePassword.HashAndSaltPassword(model.HashedPassword); admin.HashedPassword = hashedPassword; admin.Email = ($"{model.FirstName.Substring(0, 1)}{model.LastName}@guldtand.com").ToLower(); //model.Email; _context.Admin.UpdateRange(); await _context.SaveChangesAsync(); return(admin); } throw new AppException("Unable to update. Provided id doesn't exist."); }