public static TemplateConfigViewModel ToModel(this RTemplateConfig request, KeyValueTypeStringModel component)
        {
            if (request == null)
            {
                return(new TemplateConfigViewModel());
            }
            var model = request.ToModel();

            model.Component = component;
            return(model);
        }
Ejemplo n.º 2
0
 public ShardingManagerInitResponse()
 {
     ShardGroups = KeyValueTypeStringModel.FromEnum(typeof(EnumDefine.ShardGroupEnum));
 }
        public async Task <TemplateConfigGetResponse> GetTemplateConfigById(TemplateConfigGetRequest request)
        {
            var response = new TemplateConfigGetResponse();

            try
            {
                if (string.IsNullOrEmpty(request.Id))
                {
                    response.TemplateConfig = new TemplateConfigViewModel()
                    {
                        Status     = EnumDefine.CommonStatusEnum.New,
                        TemplateId = request.TemplateId,
                    };
                }
                else
                {
                    var data = await _templateService.GetTemplateConfigById(request.Id);

                    if (data == null)
                    {
                        response.SetFail("TemplateConfig is null");
                        return(response);
                    }
                    KeyValueTypeStringModel componentModel = null;
                    if (!string.IsNullOrEmpty(data.ComponentId))
                    {
                        switch (data.ComponentType)
                        {
                        case EnumDefine.TemplateConfigComponentTypeEnum.Banner:
                            var component = await _bannerService.GetBannerById(data.ComponentId);

                            if (component == null)
                            {
                                break;
                            }
                            componentModel = component.ToAutocompleteModel();
                            break;

                        case EnumDefine.TemplateConfigComponentTypeEnum.Menu:
                            break;

                        case EnumDefine.TemplateConfigComponentTypeEnum.ProductGroup:
                            break;
                        }
                    }

                    response.TemplateConfig = data.ToModel(componentModel);
                }
                if (response.TemplateConfig != null && !string.IsNullOrEmpty(response.TemplateConfig.TemplateId))
                {
                    var template = await _templateService.GetById(response.TemplateConfig.TemplateId);

                    if (template != null && !string.IsNullOrEmpty(template.Id))
                    {
                        response.Template = template.ToModel();
                    }
                }
                else
                {
                    var template = await _templateService.GetById(request.TemplateId);

                    if (template != null && !string.IsNullOrEmpty(template.Id))
                    {
                        response.Template = template.ToModel();
                    }
                    else
                    {
                        response.SetFail("Template not found!!!");
                    }
                }
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }