Exemplo n.º 1
0
 public static CategoryViewModel From(Category category)
 {
     CategoryViewModel viewModel = new CategoryViewModel();
     viewModel.Id = category.Id;
     viewModel.Name = category.Name;
     if (category.Parent != null)
         viewModel.ParentId = category.Parent.Id;
     viewModel.Description = category.Description;
     viewModel.Image = category.Image != null ? new Image(){Id = category.Image.Id} : null;
     viewModel.IsVisible = category.IsVisible;
     return viewModel;
 }
Exemplo n.º 2
0
 public ActionResult Create(CategoryViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         return View(viewModel);
     }
     Category category = new Category();
     if (viewModel.ParentId.HasValue)
     {
         Category parent = daoTemplate.FindByID<Category>(viewModel.ParentId);
         parent.AddSubCategory(category);
     }
     category.CopyFrom(viewModel);
     handleImage(category);
     daoTemplate.Save(category);
     return RedirectToAction("Index");
 }
Exemplo n.º 3
0
 public virtual void CopyFrom(CategoryViewModel viewModel)
 {
     Name = viewModel.Name;
     Description = viewModel.Description;
     IsVisible = viewModel.IsVisible;
 }
Exemplo n.º 4
0
        public ActionResult Edit(CategoryViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(viewModel);
            }
            var category = daoTemplate.FindByID<Category>(viewModel.Id);

            if ((category.Parent != null && category.Parent.Id != viewModel.ParentId) ||
                (category.Parent == null && viewModel.ParentId > 0))
            {
                Category newParent = null;
                if (viewModel.ParentId != null)
                {
                    newParent = daoTemplate.FindByID<Category>(viewModel.ParentId);
                }
                category.MoveToNewParent(newParent);
            }

            handleImage(category);

            category.CopyFrom(viewModel);
            daoTemplate.Save(category);

            return RedirectToAction("Edit", new {Id = category.Id});
        }