/** Creates a new ChecklistViewModel from a ChecklistModel template. Converts the items list into a multi-line text as seen on the new/fork views. Items are separated by a newline, there is a newline for the last item, too. If items is null, an empty string is returned. **/ public static ChecklistViewModel FromModel(ChecklistModel template) { return new ChecklistViewModel() { Title = template.Title, Description = template.Description, Items = CreateItemsTextFromChecklistItems(template.Items) }; }
/// Tool functions: public static void AssertElementsAreEqual(ChecklistModel demoModel, ChecklistModel result) { Assert.Equal(demoModel.Id, result.Id); Assert.Equal(demoModel.Title, result.Title); Assert.Equal(demoModel.Description, result.Description); Assert.NotNull(demoModel.Items); Assert.NotNull(result.Items); if (demoModel.Items != null && result.Items != null) { Assert.Equal(demoModel.Items.Count, result.Items.Count); if (demoModel.Items.Count == result.Items.Count) { for (int i = 0; i < demoModel.Items.Count; ++i) { var demoItem = demoModel.Items[i]; var resultItem = result.Items[i]; Assert.Equal(demoItem.Id, resultItem.Id); Assert.Equal(demoItem.Title, resultItem.Title); } } } }
public ChecklistModel SaveChecklistModel(ChecklistModel template) { var newId = Tools.Web.ShortGuid.CreateGuid(); template.Id = newId; template.Items = template.Items.Select(item => item.CloneWithMutator(clonedItem => { clonedItem.Id = Tools.Web.ShortGuid.CreateGuid(); return clonedItem; })).ToList(); template.CreationTime = DateTime.Now.ToUniversalTime(); var templateCollection = GetTemplateCollection(); templateCollection.InsertOne(template); return template; }
/** Creates a demo result model with some random and some fixed infos. **/ public static ChecklistResultModel CreateDemoChecklistResultModel(ChecklistModel template) { Assert.True(template.Items.Count >= 3); return new ChecklistResultModel() { CreationTime = DateTime.Now, TemplateId = template.Id, UserId = "d.albuschat", Results = new List<ChecklistResultItem> { new ChecklistResultItem () { Result = ChecklistResult.CheckedAndOk, TemplateItemId = template.Items[0].Id, }, new ChecklistResultItem () { Result = ChecklistResult.CheckedAndNotOk, TemplateItemId = template.Items[1].Id, }, new ChecklistResultItem () { Result = ChecklistResult.NotChecked, TemplateItemId = template.Items[2].Id, }, } }; }