Exemple #1
0
        public TemplateConfig RemoveTemplateconfig(TemplateConfigRemoveCommand command)
        {
            if (TemplateConfigs == null)
            {
                TemplateConfigs = new List <TemplateConfig>();
            }
            TemplateConfig templateConfig = TemplateConfigs.FirstOrDefault(p => p.Id == command.Id);

            if (templateConfig == null)
            {
                throw new Exception("TemplateConfig not found");
            }
            templateConfig.Remove(command);

            AddEvent(ToAddOrChangeCacheEvent());
            return(templateConfig);
        }
Exemple #2
0
        public async Task <ICommandResult> Handle(TemplateConfigRemoveCommand message)
        {
            try
            {
                ICommandResult result;
                RTemplate      rTemplate = await _templateService.GetById(message.TemplateId);

                if (rTemplate == null)
                {
                    result = new CommandResult()
                    {
                        Message      = "Template not found",
                        ObjectId     = "",
                        Status       = CommandResult.StatusEnum.Fail,
                        ResourceName = ResourceKey.Template_NotFound
                    };
                    return(result);
                }
                RTemplateConfig[] rTemplateConfigs = await _templateService.GetTemplateConfigByTemplateId(rTemplate.Id);

                Template       template       = new Template(rTemplate, rTemplateConfigs);
                TemplateConfig templateConfig = template.RemoveTemplateconfig(message);
                await _templateService.ChangeTemplateConfigStatus(templateConfig.Id, templateConfig.UpdatedUid,
                                                                  templateConfig.UpdatedDateUtc, templateConfig.Status);

                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 void Remove(TemplateConfigRemoveCommand command)
 {
     Status         = EnumDefine.CommonStatusEnum.Deleted;
     UpdatedUid     = command.UserId;
     UpdatedDateUtc = command.CreatedDateUtc;
 }
        public async Task <CommandResult> SendCommand(TemplateConfigRemoveCommand command)
        {
            CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command);

            return(commandResult);
        }