コード例 #1
0
        public async Task <IActionResult> SaveSearchData(int requestId, [FromBody] StringViewModel resultJson)
        {
            // on change le status request on le met à 3
            await _requestGateway.ChangeStatusRequest(requestId, 3);

            // recup le project Id
            RequestData request = await _requestGateway.GetRequestById(requestId);

            // Verifier que le noeud existe tjrs
            if (_dGraphGateway.NodeExists(request.ProjectId, request.UidNode))
            {
                List <NodeSearchData>     nodesSearchData = JsonConvert.DeserializeObject <List <NodeSearchData> >(resultJson.Key);
                List <AddNodesToNodeData> nodes           = await _dGraphGateway.CreateAddNodesToNodeData(request.ProjectId, request.Author, request.UidNode, nodesSearchData);

                await _dGraphGateway.AddNodesToNode(request.ProjectId, request.UidNode, nodes);

                _requestGateway.DeleteRequest(requestId);

                FluentResults.Result <string> resultNodes = await _dGraphGateway.FindByProjectId(request.ProjectId);

                // On envoit message à tous les gens du projet
                string nameProject = await GetProjectName(request.ProjectId);

                IEnumerable <string> userInProject = await _projectGateway.GetIdUserInProject(request.ProjectId);

                await _graphHub.ReceiveRequestDoneGiveNewNode(userInProject.ToList(), resultNodes.Value, request.DataEntity);

                await _projectHub.ReceiveRequestDone(userInProject.ToList(), Convert.ToString(request.ProjectId), request.DataEntity, nameProject);
            }

            return(Ok("Request done"));
        }
コード例 #2
0
        Handle(Queries.GetLogsQuery request, System.Threading.CancellationToken cancellationToken)
        {
            var result =
                new FluentResults.Result
                <System.Collections.Generic.IEnumerable
                 <Persistence.ViewModels.GetLogsQueryResponseViewModel> >();

            try
            {
                // **************************************************
                var logs =
                    await
                    UnitOfWork.Logs
                    .GetSomeAsync(count : request.Count.Value)
                ;

                // **************************************************

                // **************************************************
                result.WithValue(value: logs);
                // **************************************************
            }
            catch (System.Exception ex)
            {
                Logger.LogError
                    (exception: ex, message: ex.Message);

                result.WithError
                    (errorMessage: ex.Message);
            }

            return(result);
        }
コード例 #3
0
 public void Then_the_command_is_determined_to_be_valid()
 {
     Result.IsSuccess.Should().BeTrue();
     Result.IsFailed.Should().BeFalse();
     Result.HasWarnings().Should().BeFalse();
     Result.GetErrors().Should().HaveCount(0);
 }
コード例 #4
0
 public void Then_the_command_is_determined_to_be_valid()
 {
     Result.IsSuccess.Should().BeTrue();
     Result.IsFailed.Should().BeFalse();
     Result.HasWarnings().Should().BeTrue();
     Result.GetWarnings().Should().HaveCount(1);
     Result.GetWarnings().First().PropertyName.Should().Be(nameof(Command.Reference));
 }
コード例 #5
0
 FluentResult <T>(FluentResults.Result <T> result)
 {
     if (result.IsSuccess)
     {
         return(Ok(value: result));
     }
     else
     {
         return(BadRequest(error: result.ToResult()));
     }
 }
コード例 #6
0
        System.Threading.Tasks.Task HandleExceptionAsync
            (Microsoft.AspNetCore.Http.HttpContext context, System.Exception exception)
        {
            FluentResults.Result result = new FluentResults.Result();

            FluentValidation.ValidationException
                validationException = exception as FluentValidation.ValidationException;

            if (validationException != null)
            {
                var code =
                    System.Net.HttpStatusCode.BadRequest;

                context.Response.StatusCode  = (int)code;
                context.Response.ContentType = "application/json";

                foreach (var error in validationException.Errors)
                {
                    result.WithError(error.ErrorMessage);
                }
            }
            else
            {
                // Log Error!

                var code =
                    System.Net.HttpStatusCode.InternalServerError;

                context.Response.StatusCode  = (int)code;
                context.Response.ContentType = "application/json";

                result.WithError("Internal Server Error!");
            }

            var options = new System.Text.Json.JsonSerializerOptions
            {
                IncludeFields        = true,
                PropertyNamingPolicy =
                    System.Text.Json.JsonNamingPolicy.CamelCase,
            };

            string resultString =
                System.Text.Json.JsonSerializer.Serialize(value: result, options: options);

            return(context.Response.WriteAsync(resultString));
        }
コード例 #7
0
        Validate <TCommand, TValue>
            (FluentValidation.AbstractValidator <TCommand> validator, TCommand command)
        {
            FluentResults.Result <TValue> result = new FluentResults.Result <TValue>();

            FluentValidation.Results.ValidationResult
                validationResult = await validator.ValidateAsync(instance : command);

            if (validationResult.IsValid == false)
            {
                foreach (var error in validationResult.Errors)
                {
                    result.WithError(errorMessage: error.ErrorMessage);
                }
            }

            return(result);
        }
コード例 #8
0
ファイル: GraphController.cs プロジェクト: Chators/Digger
        public async Task <IActionResult> GetProjectGraphById(int projectId)
        {
            Result <ProjectData> result = await _projectGateway.GetProjectById(projectId);

            if (result.ErrorMessage == "Project not found")
            {
                return(BadRequest(result.ErrorMessage));
            }

            bool userCanReadProject = await UserCanReadProject(projectId, result.Content);

            if (!userCanReadProject)
            {
                return(StatusCode(403, "Access Denied !"));
            }

            FluentResults.Result <string> resultGraphByProjectId = await _dGraphGateway.FindByProjectId(projectId);

            return(Ok(resultGraphByProjectId.Value));
        }
コード例 #9
0
        Handle(Commands.CreateLogCommand request,
               System.Threading.CancellationToken cancellationToken)
        {
            var result =
                new FluentResults.Result <System.Guid>();

            try
            {
                // **************************************************
                var log = Mapper.Map <Domain.Models.Log>(source: request);
                // **************************************************

                // **************************************************
                await UnitOfWork.Logs.InsertAsync(entity : log);

                await UnitOfWork.SaveAsync();

                // **************************************************

                // **************************************************
                result.WithValue(value: log.Id);

                string successInsert =
                    string.Format(Resources.Messages.SuccessInsert, nameof(Domain.Models.Log));

                result.WithSuccess
                    (successMessage: successInsert);
                // **************************************************
            }
            catch (System.Exception ex)
            {
                Logger.LogError
                    (exception: ex, message: ex.Message);

                result.WithError
                    (errorMessage: ex.Message);
            }

            return(result);
        }
コード例 #10
0
        protected void LogStatus(NpgsqlCommand cmd, string tableName, string keyColumnName, string key, FluentResults.Result result)
        {
            cmd.CommandText = @"UPDATE " + tableName + " set status = @statusText where " + keyColumnName + "='" + key + "' and status is null";
            cmd.Parameters.Clear();

            if (result.IsSuccess)
                cmd.Parameters.AddWithValue("statusText", "OK");
            else
                cmd.Parameters.AddWithValue("statusText", result.Errors.First().Message);

            cmd.ExecuteNonQuery();
        }
コード例 #11
0
 public void Then_the_command_is_determined_to_be_invalid()
 {
     Result.IsSuccess.Should().BeFalse();
     Result.IsFailed.Should().BeTrue();
     Result.GetWarnings().Count.Should().Be(1);
 }