public ResponseInfoModel EditInfo([FromBody] UpdateTemplateInput input) { ResponseInfoModel json = new ResponseInfoModel() { Success = 1, Result = new object() }; try { CheckModelState(); if (!_templateService.Editinfo(input)) { json.Success = 0; json.Result = LocalizationConst.UpdateFail; } else { _logService.Insert(new Log() { ActionContent = LocalizationConst.Update, SourceType = _moduleName, SourceID = input.ID, LogTime = DateTime.Now, LogUserID = input.ModifyUser, LogIPAddress = IPHelper.GetIPAddress, }); } } catch (Exception e) { DisposeUserFriendlyException(e, ref json, "api/template/editInfo", LocalizationConst.UpdateFail); } return(json); }
public async Task <TemplateDto> UpdateTemplate(UpdateTemplateInput input) { var template = await _templateManager.TemplateRepository.GetAsync(input.Id); template.Title = input.Title; template.Name = input.Name; template.Type = input.Type; template.Extension = input.Extension; template.TemplateContent = input.TemplateContent; await _templateManager.UpdateAsync(template); await CurrentUnitOfWork.SaveChangesAsync(); return(template.MapTo <TemplateDto>()); }
public bool Editinfo(UpdateTemplateInput input) { var template = db.Templates.Find(input.ID); if (template == null) { throw new UserFriendlyException(LocalizationConst.NoExist); } template = input.MapTo(template); template.ModifyTime = DateTime.Now; template.ModifyIP = IPHelper.GetIPAddress; if (!input.Attach.ID.HasValue || input.Attach.ID == 0) { var attach = db.ArticleAttaches.FirstOrDefault(a => a.ArticleGuid == template.Guid && a.ModuleType == (int)AttachTypesEnum.模板图片); if (attach != null) { db.ArticleAttaches.Remove(attach); } if (input.Attach.ID.HasValue && input.Attach.ID == 0) { db.ArticleAttaches.Add(new ArticleAttach() { HashValue = input.Attach.HashValue, ArticleGuid = template.Guid, AttachName = input.Attach.AttachName, AttachNewName = input.Attach.AttachNewName, AttachUrl = input.Attach.AttachUrl, AttachFormat = input.Attach.AttachFormat, AttachIndex = 1, AttachBytes = input.Attach.AttachBytes, AttachType = input.Attach.AttachType, ModuleType = (int)AttachTypesEnum.模板图片, CreateTime = DateTime.Now, CreateUser = input.ModifyUser, CreateIP = IPHelper.GetIPAddress }); } } db.Entry(template).State = EntityState.Modified; return(db.SaveChanges() > 0); }