Esempio n. 1
0
 public void CopyFrom(CategoryViewModel categoryViewModel, DBUnitOfWork db)
 {
     Name = categoryViewModel.Name;
     Description = categoryViewModel.Description;
     Items = new List<Item>();
     if (categoryViewModel.Items != null)
     {
         foreach (var itemId in categoryViewModel.Items)
         {
             var existing = db.Repository<Item>().Get(itemId);
             if (existing != null)
             {
                 Items.Add(existing);
             }
         }
     }
 }
Esempio n. 2
0
 public HttpResponseMessage Get()
 {
     using (var db = new DBUnitOfWork())
     {
         try
         {
             List<CategoryViewModel> categoryViewModelList = new List<CategoryViewModel>();
             var categoryList = db.Repository<Category>().GetAll();
             foreach (var category in categoryList)
             {
                 CategoryViewModel categoryViewModel = new CategoryViewModel();
                 categoryViewModel.CopyFrom(category);
                 categoryViewModelList.Add(categoryViewModel);
             }
             return Request.CreateResponse(HttpStatusCode.OK, categoryViewModelList);
         }
         catch (Exception)
         {
             return Request.CreateResponse(HttpStatusCode.InternalServerError);
         }
     }
 }