Exemple #1
0
 public DataModel.Models.SimpleList SimpleListViewModelToSimpleList(SimpleListViewModel simpleListViewModel)
 {
     DataModel.Models.SimpleList simpleList = new DataModel.Models.SimpleList();
     simpleList.ID        = simpleListViewModel.ID;
     simpleList.Name      = simpleListViewModel.Name;
     simpleList.AllDone   = simpleListViewModel.AllDone;
     simpleList.DateAdded = simpleListViewModel.DateAdded;
     // We only populate the UserID if we have a value to populate.
     if (simpleListViewModel.UserID.HasValue)
     {
         simpleList.UserID = simpleListViewModel.UserID.Value;
     }
     return(simpleList);
 }
Exemple #2
0
        public SimpleListViewModel SimpleListToSimpleListViewModel(DataModel.Models.SimpleList simpleList, bool populateSubStructures = true)
        {
            SimpleListViewModel simpleListViewModel = new SimpleListViewModel();

            simpleListViewModel.ID        = simpleList.ID;
            simpleListViewModel.Name      = simpleList.Name;
            simpleListViewModel.UserID    = simpleList.UserID;
            simpleListViewModel.AllDone   = simpleList.AllDone;
            simpleListViewModel.DateAdded = simpleList.DateAdded;
            // We only populate the SimpleListItems if specifically requested.
            if (populateSubStructures)
            {
                simpleListViewModel.SimpleListItems = SimpleListItemsToSimpleListItemViewModels(simpleList.SimpleListItems.AsEnumerable <DataModel.Models.SimpleListItem>());
            }
            return(simpleListViewModel);
        }
Exemple #3
0
        public void SimpleListToSimpleListViewModelTest()
        {
            Mapper target = new Mapper();

            DataModel.Models.SimpleList simpleList = new DataModel.Models.SimpleList
            {
                ID              = 1,
                DateAdded       = DateTime.Now,
                AllDone         = false,
                UserID          = 1,
                Name            = "test list 1",
                SimpleListItems = new List <DataModel.Models.SimpleListItem>
                {
                    new DataModel.Models.SimpleListItem {
                        ID = 1, Description = "test list item 1", Done = false, SimpleListID = 1
                    },
                    new DataModel.Models.SimpleListItem {
                        ID = 2, Description = "test list item 2", Done = true, SimpleListID = 1
                    }
                }
            };
            SimpleListViewModel expected = new SimpleListViewModel
            {
                ID              = 1,
                DateAdded       = DateTime.Now,
                AllDone         = false,
                UserID          = 1,
                Name            = "test list 1",
                SimpleListItems = new List <Models.SimpleListItemViewModel>
                {
                    new Models.SimpleListItemViewModel {
                        ID = 1, Description = "test list item 1", Done = false, SimpleListID = 1
                    },
                    new Models.SimpleListItemViewModel {
                        ID = 2, Description = "test list item 2", Done = true, SimpleListID = 1
                    }
                }
            };
            SimpleListViewModel actual;

            actual = target.SimpleListToSimpleListViewModel(simpleList);
            Assert.AreEqual(expected, actual);
        }