public async Task <string> Handle(SolutionCreateCommand request, CancellationToken cancellationToken)
        {
            var data = new Solution(request.Name, request.Description, request.Icon, identityService.GetOrganizationId(), identityService.GetUserId());
            await solutionRepository.AddAsync(data);

            return(data.Id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Создание солюшна
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <SolutionDto> CreateAsync(NewSolutionDto dto)
        {
            var result = await _solutionRepository.AddAsync(_mapper.Map <Solution>(dto));

            await _solutionRepository.SaveChangesAsync();

            return(_mapper.Map <SolutionDto>(result));
        }
        public async Task <SolutionResponse> SaveAsync(Solution solution)
        {
            try
            {
                await _solutionRepository.AddAsync(solution);

                await _unitOfWork.CompleteAsync();

                return(new SolutionResponse(solution));
            }
            catch (Exception ex)
            {
                return(new SolutionResponse($"An error ocurred while saving the solution: {ex.Message}"));
            }
        }
Exemplo n.º 4
0
        public async Task <AddSolution> Handle(AddSolutionCommand request, CancellationToken cancellationToken)
        {
            var dbEntity = new DomainEntity.Solution()
            {
                Name              = request.Name,
                CName             = request.CName,
                ContactEmail      = request.ContactEmail,
                ManagerUserId     = _httpAuthorizeHandler.GetUseIdFromCookie(),
                SolutionProcesses = new List <SolutionProcess>()
                {
                    new SolutionProcess()
                    {
                        Level   = SolutionProcessLevel.Solution,
                        Content = $"创建解决方案【{request.Name}】"
                    }
                }
            };
            await _solutionRepository.AddAsync(dbEntity, cancellationToken);

            var changedRow = await _unitOfWork.SaveChangesAsync(cancellationToken);

            if (changedRow > 0)
            {
                await _mediator.Publish(new SolutionCreatedEvent()
                {
                    SolutionId = dbEntity.Id
                }, cancellationToken);

                return(new AddSolution()
                {
                    IsSuccess = true,
                    Msg = "添加解决方案成功",
                    Id = dbEntity.Id
                });
            }
            else
            {
                return(new AddSolution()
                {
                    IsSuccess = false,
                    Msg = "添加解决方案失败"
                });
            }
        }