Пример #1
0
        public async Task <IActionResult> AddSystemProfileFunctionLink([FromBody] LinkSystemProfileFunctionRequest request)
        {
            if (request.IsNull())
            {
                return(ModelNullError());
            }
            var identityClaims = (ClaimsIdentity)User.Identity;

            var model = new SysProfileFunctionLinkCommandRequest
            {
                TransferObject = request
            };
            var result = await Mediator.Send(model);

            return(HandleResponse(result, r => r));
        }
Пример #2
0
        public async Task <OperationResult <SysProfileFunctionLinkCommandResponse> > Handle(SysProfileFunctionLinkCommandRequest request, CancellationToken cancellationToken)
        {
            var response = new SysProfileFunctionLinkCommandResponse(request.MessageId);
            OperationResult <SysProfileFunctionLinkCommandResponse> result;

            //Validate Unique Name
            var functionLink = await _dbContext.SystemProfileFunction.SingleOrDefaultAsync(u => u.SystemProfileId == request.TransferObject.ProfileId && u.SystemFunctionId == request.TransferObject.FunctionId);

            if (functionLink.NotNull())
            {
                result = new OperationResult <SysProfileFunctionLinkCommandResponse>(EnumOperationResult.Duplicate,
                                                                                     new List <ValidationError>
                {
                    new ValidationError(nameof(request.TransferObject.FunctionId),
                                        "System Function is already Linked to Profile")
                });
            }
            else
            {
                functionLink = new SystemProfileFunction
                {
                    SystemFunctionId = request.TransferObject.FunctionId,
                    SystemProfileId  = request.TransferObject.ProfileId
                };


                await _dbContext.SystemProfileFunction.AddAsync(functionLink, cancellationToken);

                await _dbContext.SaveChangesAsync(cancellationToken);

                result = new OperationResult <SysProfileFunctionLinkCommandResponse>(EnumOperationResult.Ok, null, response);

                //result.AddDomainEvent(new SystemFunctionAddEvent
                //{
                //    Id = response.FunctionId,

                //});
            }

            return(result);
        }