public static FormViewModel CreateFromObject(DB.Form form1, Constants.TemplateMode mode) { if (form1 != null) { var formView = CreateBasicFromObject(form1); return(formView); } return(FormViewModel.Initialize()); }
public TemplateViewModel FindTemplateToEdit(int templateID) { using (var unitOfWork = CreateUnitOfWork()) { Template template = unitOfWork.FormRepository.GetTemplate(templateID); if (template == null) { return(null); } Constants.TemplateMode Mode = Constants.TemplateMode.EDIT; var templateView = TemplateViewModel.CreateFromObject(template); templateView.Entries = HasSubmissions(templateView).ToList(); if (templateView.Entries.Any()) { var templates = FindAllTemplatesByFormId(template.FormID); if (templates.Count() == template.Version) { using (TransactionScope scope = new TransactionScope()) { IDictionary <int, TemplateField> conditionFields = new System.Collections.Generic.Dictionary <int, TemplateField>(); template = unitOfWork.FormRepository.CopyTemplate(template, out conditionFields); unitOfWork.Complete(); template = unitOfWork.FormRepository.CopyConditionFields(template, conditionFields); unitOfWork.Complete(); scope.Complete(); } } else { Mode = Constants.TemplateMode.READONLY; } } TemplateViewModel model1 = TemplateViewModel.CreateFromObject(template); model1.Mode = Mode; return(model1); } }