public Models.Trainers.Trainer Create(CreateTrainerRequest createTrainerRequest) { Database.AppUser appUser = _mapper.Map <Database.AppUser>(createTrainerRequest); appUser.HashedPassword = HashUtil.ComputeSha256Hash(createTrainerRequest.Password); appUser.CreatedAt = DateTime.UtcNow; appUser.Status = Database.UserStatus.ACTIVE; // add trainer specific data Database.Trainer trainer = new Database.Trainer(); appUser.Trainer = trainer; _context.AppUsers.Add(appUser); _context.SaveChanges(); return(_mapper.Map <Models.Trainers.Trainer>(appUser)); }
public Models.Clients.Client Create(CreateClientRequest createClientRequest) { Database.AppUser appUser = _mapper.Map <Database.AppUser>(createClientRequest); appUser.HashedPassword = HashUtil.ComputeSha256Hash(createClientRequest.Password); appUser.CreatedAt = DateTime.UtcNow; appUser.Status = Database.UserStatus.INACTIVE; // add client specific data Database.Client client = new Database.Client(); appUser.Client = client; _context.AppUsers.Add(appUser); _context.SaveChanges(); return(_mapper.Map <Models.Clients.Client>(appUser)); }
public void Update(int id, UpdateClientRequest updateClientRequest) { Database.AppUser client = _context.AppUsers .Where(x => x.Id == id) .FirstOrDefault(); if (client == null) { throw new ResourceNotFoundException("Client with id: " + id + " not found"); } _mapper.Map(updateClientRequest, client); if (!string.IsNullOrEmpty(updateClientRequest.Password)) { client.HashedPassword = HashUtil.ComputeSha256Hash(updateClientRequest.Password); } _context.AppUsers.Update(client); _context.SaveChanges(); }