public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.Title = "owner"; user.CanEdit = true; SettingsForCreationDto settingsForCreation = new SettingsForCreationDto { IsNew = true, InitialEmployeePassword = "******" }; Settings settings = _mapper.Map <Settings>(settingsForCreation); user.Settings = settings; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
private User AddSettings(User user) { SettingsForCreationDto settingsForCreation = new SettingsForCreationDto { IsNew = true, TransactionPageSize = 20, AccountPageSize = 20 }; Settings settings = _mapper.Map <Settings>(settingsForCreation); user.Settings = settings; return(user); }
public async Task <IActionResult> UpdateSettingsMill(int userId, SettingsForCreationDto settingsForUpdateDto) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var settingsFromRepo = await _repo.GetSettings(userId); settingsFromRepo.SkipMill = settingsForUpdateDto.SkipMill; if (await _repo.SaveAll()) { return(CreatedAtRoute("GetSettings", new { id = settingsFromRepo.userId, userId = userId }, settingsForUpdateDto)); } throw new Exception($"Updating settings for {userId} failed on save"); }
public async Task <User> RegisterEmployee(User user, string password, int rootId) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.RootId = rootId; SettingsForCreationDto settingsForCreation = new SettingsForCreationDto { IsNew = true }; Settings settings = _mapper.Map <Settings>(settingsForCreation); user.Settings = settings; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; SettingsForCreationDto settingsForCreation = new SettingsForCreationDto { IsNew = true, SkipLathe = false, SkipMill = false }; Settings settings = _mapper.Map <Settings>(settingsForCreation); user.Settings = settings; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <IActionResult> AddSettings(int userId, SettingsForCreationDto settingsForCreationDto) { var creator = await _repo.GetUser(userId); if (creator.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var settings = _mapper.Map <Settings>(settingsForCreationDto); settings.userId = userId; _repo.Add(settings); if (await _repo.SaveAll()) { var settingsToReturn = _mapper.Map <SettingsForCreationDto>(settings); return(CreatedAtRoute("GetSettings", new { id = settings.userId, userId = userId }, settingsToReturn)); } throw new Exception("Creation of settings count failed on save"); }
public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; SettingsForCreationDto settingsForCreation = new SettingsForCreationDto { LastInvoiceNumber = 0, DefaultPointOfContact = user.Name, DefaultEmail = user.Email }; Settings settings = _mapper.Map <Settings>(settingsForCreation); user.Settings = settings; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }