Пример #1
0
 public static CategoryViewModel ConvertFrom(Category category)
 {
     return new CategoryViewModel
     {
         Id = category.Id,
         Name = category.Name
     };
 }
        public ActionResult Create(CategoryViewModel categoryViewModel)
        {
            return ManipulaateCategory(0, false,
                c =>
                {
                    var category = new Category
                    {
                        Name = categoryViewModel.Name
                    };

                    this.Data.Categories.Add(category);
                });
        }
        public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel category)
        {
            if (category != null && ModelState.IsValid)
            {
                Category categoryToBase = new Category()
                {
                    Name = category.Name,
                };

                this.Data.Categories.Add(categoryToBase);
                this.Data.SaveChanges();
                category.Id = categoryToBase.Id;
            }

            return Json(new[] { category }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
        }
        public ActionResult Create(Category category)
        {
            if (category != null && ModelState.IsValid)
            {
                var newCategory = new Category
                {
                    Name = category.Name
                };

                this.Data.GetRepository<Category>().Add(newCategory);
                this.Data.Save();
                return RedirectToAction("Index");
            }

            return View(category);
        }
Пример #5
0
        public static int CalcualteFilterCategoryRelevance(Category category, string queryString)
        {
            if (string.IsNullOrEmpty(queryString))
            {
                return 1;
            }

            var relevance = 0;
            var words = queryString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var searchTarget = category.Name.ToLower();

            foreach (var word in words)
            {
                if (searchTarget.IndexOf(word.ToLower()) >= 0)
                {
                    relevance++;
                }
            }

            return relevance;
        }