public async Task <FunctionDto> Handle(UpdateFunctionCommand request, CancellationToken cancellationToken) { var function = await _context.Function.FindAsync(request.FunctionId); if (function == null) { return(null); } if (request.Approximation != null) { function.Approximation = (int)request.Approximation; } if (request.Min != null) { function.Min = (double)request.Min; } if (request.Max != null) { function.Min = (double)request.Max; } _context.Update(function); await _context.SaveChangesAsync(cancellationToken); return(_mapper.Map <FunctionDto>(function)); }
public async Task <User> Create(string username, string password, string email, CancellationToken cancellationToken) { // validation if (await _context.User.AnyAsync(x => x.Name == username, cancellationToken)) { throw new AppException("Username \"" + username + "\" is already taken"); } CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt); var user = new User { Name = username, PasswordHash = passwordHash, PasswordSalt = passwordSalt, Mail = email }; _context.User.Add(user); await _context.SaveChangesAsync(cancellationToken); return(user); }
protected override async Task Handle(DeleteUserRepoCommand request, CancellationToken cancellationToken) { var userep = await _context.UseRep.Where(u => u.UseId == request.UserId) .Where(r => r.RepId == request.RepoId).SingleOrDefaultAsync(cancellationToken); _context.UseRep.Remove(userep); await _context.SaveChangesAsync(cancellationToken); }
public async Task <Guid> Handle(CreateRepositoryCommand request, CancellationToken cancellationToken) { var repo = new Data.Models.Repository { Name = request.Name, Description = request.Description, CreationDate = DateTime.Now }; await _context.Repository.AddAsync(repo, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(repo.RepositoryId); }
public async Task <Guid> Handle(CreateChartCommand request, CancellationToken cancellationToken) { var chart = new Chart { Logo = request.Name, CreationDate = DateTime.Now }; await _context.Chart.AddAsync(chart, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(chart.ChartId); }
public async Task <RepositoryDto> Handle(AddChartToRepoCommand request, CancellationToken cancellationToken) { var repo = await _context.Repository.FindAsync(request.RepoId); var chart = await _context.Chart.FindAsync(request.ChartId); if (repo == null || chart == null) { return(null); } chart.Repository = repo; await _context.SaveChangesAsync(cancellationToken); return(_mapper.Map <RepositoryDto>(repo)); }
public async Task <ChartDto> Handle(AddFunctionToChartCommand request, CancellationToken cancellationToken) { var function = await _context.Function.FindAsync(request.FunctionId); var chart = await _context.Chart.FindAsync(request.ChartId); if (function == null || chart == null) { return(null); } function.Chart = chart; await _context.SaveChangesAsync(cancellationToken); return(_mapper.Map <ChartDto>(chart)); }
public async Task <CommandResult> Handle(AddRepoToUserCommand request, CancellationToken cancellationToken) { if (await _context.User.FindAsync(request.UserId) == null || await _context.Repository.FindAsync(request.RepoId) == null) { return(null); } var userep = new UseRep { RepId = request.RepoId, UseId = request.UserId, IsOwner = true }; await _context.UseRep.AddAsync(userep, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(CommandResult.Success); }
public async Task <Guid?> Handle(CreateFunctionCommand request, CancellationToken cancellationToken) { var function = new Data.Models.Function { CreationDate = DateTime.Now, Approximation = request.Approximation, FunctionString = request.FunctionString, Min = request.Min, Max = request.Max, Name = request.Name }; _eqManager = new Equation(function); if (!_eqManager.CheckSyntax()) { return(null); } await _context.AddAsync(function, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(function.FunctionId); }