コード例 #1
0
        public ViewModels.CategoryViewModel GetByImg(int id)
        {
            Category category = _categoriesRepository.GetByImg(id);

            ViewModels.CategoryViewModel categoryViewModel = MapToViewModel(category);
            return(categoryViewModel);
        }
コード例 #2
0
        public JsonResult GetFirstCategory()
        {
            var model = new ViewModels.CategoryViewModel {
                Id = 1, Name = "ajax sdfadassda"
            };

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public IEnumerable <ViewModels.CategoryViewModel> GetAll()
        {
            List <ViewModels.CategoryViewModel> catViewModels = new List <ViewModels.CategoryViewModel>();

            foreach (Category category in _categoriesRepository.GetAll())
            {
                ViewModels.CategoryViewModel categoryViewModel = MapToViewModel(category);
                catViewModels.Add(categoryViewModel);
            }
            return(catViewModels);
        }
コード例 #4
0
 public void Edit(ViewModels.CategoryViewModel categoryViewModel)
 {
     try
     {
         Category category = MapFromViewModel(categoryViewModel);
         _categoriesRepository.Edit(category);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #5
0
 public void Add(ViewModels.CategoryViewModel categoryViewModel)
 {
     try
     {
         Category category = MapFromViewModel(categoryViewModel);
         _categoriesRepository.Add(category);
         categoryViewModel.CategoryID = category.CategoryID;
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
コード例 #6
0
 public void Populate()
 {
     #region Fake Data
     foreach (var x in Enumerable.Range(0, 5))
     {
         var ctg = new ViewModels.CategoryViewModel($"Category {x}");
         Categories.Add(ctg);
         foreach (var y in Enumerable.Range(0, 5))
         {
             ctg.SubCategories.Add(new ViewModels.SubCategoryViewModel($"Sub-Category {x}/{y}"));
         }
     }
     #endregion Fake Data
 }
コード例 #7
0
        public ActionResult Category(int Nid, string Title = "")
        {
            dataTransfer = new DataTransfer();
            ViewModels.CategoryViewModel cvm = new ViewModels.CategoryViewModel();
            var tmpCategory = dataTransfer.GetCategoryByNidCategory(Nid);

            cvm.CategoryBrands = dataTransfer.GetCategory_BrandByNidcategory(tmpCategory.NidCategory);
            cvm.CategoryTypes  = dataTransfer.GetCategory_TypeByNidcategory(tmpCategory.NidCategory);
            cvm.Products       = dataTransfer.GetProductsByNidcategory(tmpCategory.NidCategory);
            var minmax = dataTransfer.GetMinMaxCategoryPrice(tmpCategory.NidCategory);

            cvm.MinPrice = minmax.Item1;
            cvm.MaxPrice = minmax.Item2;
            cvm.Category = tmpCategory;
            ViewBag.Desc = tmpCategory.Description;
            return(View(cvm));
        }
コード例 #8
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ViewModels.CategoryViewModel model = new ViewModels.CategoryViewModel();
            model.Categories = db.Categories.ToList();
            model.Category   = db.Categories.Find(id);

            if (model.Categories == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
コード例 #9
0
        public ActionResult Edit(ViewModels.CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(model.Category).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddModelError(string.Empty, "Someting went wrong.");
                }
            }

            return(View(new ViewModels.CategoryViewModel {
                Category = model.Category, Categories = db.Categories.ToList()
            }));
        }
コード例 #10
0
        private void GetParentCategoriesRecursive(ViewModels.CategoryViewModel request, ref List <KeyValuePair <Guid, string> > outCategories, int level)
        {
            string space = "";

            for (int i = 0; i < level; i++)
            {
                space += "---";
            }
            var model = GetCommand <GetParentCategoriesCommand>().ExecuteCommand(request);

            if (model.Count > 0)
            {
                foreach (var item in model)
                {
                    outCategories.Add(new KeyValuePair <Guid, string>(item.Id, space + item.Name));
                    GetParentCategoriesRecursive(new ViewModels.CategoryViewModel {
                        ParentId = item.Id
                    }, ref outCategories, level + 1);
                }
            }
        }
コード例 #11
0
        private Category MapFromViewModel(ViewModels.CategoryViewModel categoryViewModel)
        {
            Category category = Mapper.Map <Category>(categoryViewModel);

            return(category);
        }
コード例 #12
0
 private ViewModels.CategoryViewModel MapToViewModel(Category category)
 {
     ViewModels.CategoryViewModel categoryViewModel = Mapper.Map <ViewModels.CategoryViewModel>(category);
     return(categoryViewModel);
 }
コード例 #13
0
 public ActionResult Index()
 {
     ViewModels.CategoryViewModel model = new ViewModels.CategoryViewModel();
     model.Categories = db.Categories.OrderBy(p => p.Name).ToList();
     return(View(model));
 }