public bool UpdateTemplate(TemplateEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Templates .Single(e => e.Id == model.TemplateId); var cardsUsingTemplate = ctx .Cards .Where(c => c.TemplateId == model.TemplateId); int count = 1; if (cardsUsingTemplate != null) { foreach (Card card in cardsUsingTemplate) { card.TemplateName = model.Name; count++; } } entity.Name = model.Name; return(ctx.SaveChanges() == count); } }
// Open from the Template Sidebar public void Open(TemplateEdit.TEditSidebar ts,string ConceptId, string Html, string pbType) { this.TemplateSideBar = ts; this.HasChanged = false; this.Open(ConceptId, Html, pbType); this.btnEdit.Visibility = System.Windows.Visibility.Visible; this.btnFootnotes.Visibility = System.Windows.Visibility.Visible; }
public ActionResult Edit(int id) { var service = new TemplateService(); var template = service.GetTemplateById(id); var model = new TemplateEdit { TemplateId = template.Id, Name = template.Name, }; return(View(model)); }
//新增模版 private void menuAddTemplate_Click(object sender, EventArgs e) { TemplateEdit edit = new TemplateEdit() { EditMode = WSH.WinForm.Controls.EditMode.Add, ParentID = Convert.ToInt32(GetSelectedID()), TypeName = treeTemplate.SelectedNode.Text }; edit.ShowDialog(); if (edit.SaveCount > 0) { DataBind(); } }
public ActionResult Create(TemplateEdit model) { var xml = string.Empty; try { //Tests before uploading if (model.uploadFile != null) { if (!Path.GetExtension(model.uploadFile.FileName.ToLower()).EndsWith("xml")) { throw new NotUploaded("Please select an XML file to upload"); } if (model.uploadFile.ContentLength == 0) { throw new NotUploaded("The selected file appears to be empty, please select a different file and re-try"); } //Upload var fileName = Path.Combine("C:\\TipstaffUploads", Path.GetFileName(model.uploadFile.FileName)); model.uploadFile.SaveAs(fileName); //Save to uploads folder XmlDocument document = new XmlDocument(); document.Load(fileName); xml = document.InnerXml; //Delete file System.IO.File.Delete(fileName); model.Template.templateXML = xml; model.Template.active = true; db.Entry(model.Template).State = EntityState.Added; db.SaveChanges(); return(RedirectToAction("Index")); } else { model.ErrorMessage = "Please select a template file"; model.UploadSuccessful = false; ModelState.AddModelError("Error", "Please select a template file"); return(View(model)); } } catch (Exception ex) { model.ErrorMessage = genericFunctions.GetLowestError(ex); model.UploadSuccessful = false; return(View(model)); } }
//修改模版 private void menuEditTemplate_Click(object sender, EventArgs e) { TreeNode selectedNode = this.treeTemplate.SelectedNode; string typeName = selectedNode.Parent.Text; // string fileName = TemplateManager.GetTemplateFile(selectedNode.Text, typeName); //if (ExistsTemplate(fileName)) //{ //} TemplateEdit edit = new TemplateEdit() { RecordID = GetSelectedID(), TypeName = typeName, ParentID = Convert.ToInt32(GetSelectedID()), EditMode = WSH.WinForm.Controls.EditMode.Edit }; edit.ShowDialog(); if (edit.SaveCount > 0) { DataBind(); } }
public ActionResult Edit(int id, TemplateEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.TemplateId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = new TemplateService(); if (service.UpdateTemplate(model)) { TempData["SaveResult"] = "The Template Name was updated."; return(RedirectToAction("Details", new { id = model.TemplateId })); } ModelState.AddModelError("", "The Template name could not be updated."); return(View(model)); }
public ActionResult Edit(int id) { TemplateEdit model = new TemplateEdit(id); return(View(model)); }
public ActionResult Create() { TemplateEdit model = new TemplateEdit(); return(View(model)); }