Example #1
0
        public async Task <ICommandResult> Handle(TemplateRemoveCommand message)
        {
            try
            {
                ICommandResult result;
                RTemplate      rTemplate = await _templateService.GetById(message.Id);

                if (rTemplate == null)
                {
                    result = new CommandResult()
                    {
                        Message      = "Template not found",
                        ObjectId     = "",
                        Status       = CommandResult.StatusEnum.Fail,
                        ResourceName = ResourceKey.Template_NotFound
                    };
                    return(result);
                }
                Template template = new Template(rTemplate);
                template.ChangeStatus(EnumDefine.CommonStatusEnum.Deleted, message.CreatedDateUtc, message.UserId);
                await _templateService.ChangeTemplateStatus(message.Id, message.UserId, message.CreatedDateUtc, EnumDefine.CommonStatusEnum.Deleted);

                await _eventSender.Notify(template.Events);

                result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = rTemplate.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = message;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }
        public async Task <CommandResult> SendCommand(TemplateRemoveCommand command)
        {
            CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command);

            return(commandResult);
        }