public async Task <TemplateDto> CreateTemplate(CreateTemplateInput input)
        {
            if (string.IsNullOrEmpty(input.Extension))
            {
                input.Extension = Template.DefaultExtension;
            }

            var template = new Template(input.AppId, input.Title, input.Name, input.Type, input.Extension, false);

            template.TemplateContent = input.TemplateContent;
            await _templateManager.CreateAsync(template);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(template.MapTo <TemplateDto>());
        }
Exemple #2
0
        public ResponseInfoModel AddInfo([FromBody] CreateTemplateInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                CheckModelState();

                var entity = _templateService.Addinfo(input);

                if (entity == null)
                {
                    json.Success = 0;
                    json.Result  = LocalizationConst.InsertFail;
                }
                else
                {
                    _logService.Insert(new Log()
                    {
                        ActionContent = LocalizationConst.Insert,
                        SourceType    = _moduleName,
                        SourceID      = entity.ID,
                        LogTime       = DateTime.Now,
                        LogUserID     = input.CreateUser,
                        LogIPAddress  = IPHelper.GetIPAddress,
                    });
                }
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/template/addInfo", LocalizationConst.InsertFail);
            }
            return(json);
        }
Exemple #3
0
        public Template Addinfo(CreateTemplateInput input)
        {
            string guid     = Guid.NewGuid().ToString();
            var    template = input.MapTo <Template>();

            template.CreateTime = DateTime.Now;
            template.CreateIP   = IPHelper.GetIPAddress;
            template.Guid       = guid;

            db.Templates.Add(template);

            var attach = input.Attach.MapTo <ArticleAttach>();

            if (attach != null)
            {
                attach.ModuleType  = (int)AttachTypesEnum.模板图片;
                attach.ArticleGuid = guid;
                attach.CreateTime  = DateTime.Now;
                attach.CreateIP    = IPHelper.GetIPAddress;
                attach.CreateUser  = input.CreateUser;
                db.ArticleAttaches.Add(attach);
            }
            return(db.SaveChanges() > 0 ? template : null);
        }