예제 #1
0
            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));
            }
예제 #2
0
        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);
        }
예제 #3
0
            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);
            }
예제 #5
0
            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);
            }
예제 #6
0
            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));
            }
예제 #8
0
            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);
            }
예제 #9
0
            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);
            }