public async Task <Project> AddProjectAsync(UpsertProjectParams ps) { if (await _context.Projects.AsNoTracking().AnyAsync(p => p.ProjectKey == ps.ProjectKey)) { throw new ConflictException($"Project with key {ps.ProjectKey} is already existing."); } var project = _mapper.Map <Project>(ps); await _context.Projects.AddAsync(project); await _context.SaveChangesAsync(); return(project); }
public async Task <ProjectPermission> AddProjectPermissionAsync(UpsertProjectPermissionParams ps) { if (await _context.ProjectPermissions.AsNoTracking().AnyAsync(pp => pp.ProjectKey == ps.ProjectKey && pp.Username == ps.Username)) { throw new ConflictException($"Project permission {ps.Username}@{ps.ProjectKey} is already existing."); } var permission = _mapper.Map <ProjectPermission>(ps); await _context.ProjectPermissions.AddAsync(permission); await _context.SaveChangesAsync(); return(permission); }
public async Task <Item> AddItemAsync(UpsertItemParams ps) { if (await _context.Items.AsNoTracking().AnyAsync(i => i.ItemKey == ps.ItemKey)) { throw new ConflictException($"Item with key {ps.ItemKey} is already existing."); } // verification if (!ps.ItemKey.Split(".")[0].Equals(ps.ProjectKey, StringComparison.OrdinalIgnoreCase)) { throw new InvalidParamsException("The item key should be started with it's project key."); } var item = _mapper.Map <Item>(ps); await _context.Items.AddAsync(item); await _context.SaveChangesAsync(); return(item); }
public async Task <User> AddUserAsync(UpsertUserParams ps) { if (await _context.Users.AsNoTracking().AnyAsync(u => u.Username == ps.Username)) { throw new ConflictException($"User with username {ps.Username} is already existing."); } // verification if (await _context.Users.AsNoTracking().AnyAsync(u => u.Email == ps.Email)) { throw new ConflictException($"User with email {ps.Email} is already existing."); } var user = _mapper.Map <User>(ps); user.Password ??= "1"; // todo: use item in __scalpay await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }