public void PopulateFields(SectionEdit section) { foreach (var field in section.FieldList.OrderBy(f => f.Position)) { if (field == null) continue; var fieldVM = FieldFactory.CreateFieldVM(field, this); FieldList.Add(fieldVM); foreach (var step in field.StepList) step.AddProps(); var expandableObj = new ExpandableStepPropBag(TheProcessFieldsViewModel.Model) { FieldSecurityManager = TheProcessFieldsViewModel, Model = field, PreviewMode = true }; foreach (var step in field.StepList) step.UpdateProps(expandableObj); expandableObj.PreviewMode = true; if (!TheProcessFieldsViewModel.FieldList.Keys.Contains(field.Guid)) TheProcessFieldsViewModel.FieldList.Add(field.Guid, new Tuple<ProcessFieldViewModel, ExpandableStepPropBag>(fieldVM, expandableObj)); Fields.Add(expandableObj); } SortFields(); }
public bool UpdateSection(SectionEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Sections .Single(e => e.SectionID == model.SectionID); entity.Title = model.Title; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateSectionService(); var detail = service.GetSectionById(id); var model = new SectionEdit { SectionID = detail.SectionId, Title = detail.Title }; return(View(model)); }
/// <summary> /// Initializes a new instance of the <see cref="SectionViewModel"/> class. /// </summary> /// <param name="selectedSection">The selected section.</param> /// <param name="parentModel">The parent model.</param> /// <param name="screenSecurity">The screen security.</param> public SectionViewModel(SectionEdit selectedSection, ProcessEdit parentModel, IFieldSecurityManager screenSecurity) { ProcessScreenSecuritySettings = screenSecurity; Fields = new ObservableCollection<ExpandableStepPropBag>(); if (FieldList == null) FieldList = new ObservableCollection<FieldEdit>(); FieldList.Clear(); _selectedSection = selectedSection; Id = selectedSection.Id; Name = selectedSection.Name; if (_selectedSection.FieldList != null) { foreach (var f in selectedSection.FieldList) { AddField(selectedSection.Id, parentModel, f); } } }
public ActionResult Edit(int id, SectionEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SectionID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateSectionService(); if (service.UpdateSection(model)) { TempData["ResultSaved"] = "Section was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Section could not be updated."); return(View(model)); }