Example #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"));
        }
Example #2
0
        public async Task <IActionResult> AssignUserToProject([FromBody] AssignUserToProject model)
        {
            if (model.UserId == 0)
            {
                model.UserId = Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier));
            }

            if (!HttpContext.User.IsInRole("admin") && !_getAccessUser.UserCookieIs(HttpContext, model.UserId.ToString()))
            {
                return(StatusCode(403, "Access Denied !"));
            }

            int userInvitationId = await _projectGateway.CheckUserInvitation(model.UserId, model.ProjectId);

            if (userInvitationId == 0)
            {
                return(BadRequest("Invitation not exists"));
            }

            Result resultAssignProject = await _projectGateway.AssignUserToProject(model.UserId, model.ProjectId, (int)EnumProjectAccessRight.Voyeur);

            if (resultAssignProject.ErrorMessage == "The project is already assigned to user")
            {
                return(BadRequest(resultAssignProject.ErrorMessage));
            }

            Result resultDeleteInvitationProject = await _projectGateway.DeleteUserInvitationInProjectByUserInvitedAndProject(model.UserId, model.ProjectId);

            string nameProject = await _getAccessUser.GetProjectName(model.ProjectId);

            string userName = await _getAccessUser.GetUserName(model.UserId);

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

            await _projectHub.ReceiveUserJoinedProject(userInProject.ToList(), Convert.ToString(model.ProjectId), userName, nameProject);

            return(Ok("Assign project success"));
        }