Ejemplo n.º 1
0
        public ActionResult Create([Bind("Id,Name,IsHot,SefName,Icon,ParentCategoryId")] CategoryViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string currentUserId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                    var    parentId      = model.ParentCategoryId > 0 ? model.ParentCategoryId : (int?)null;
                    var    category      = _categoryFactory.CreateCategory(model.Name, model.IsHot, model.SefName, model.Icon, currentUserId, parentId);
                    var    catId         = _categoryRepository.Add(category);

                    //vrati se
                    //ShowOperationMessage(@UIResources.CategoryPageCreateSuccessMessage);
                    //return RedirectToAction("List", new { id = catId, page = 1 });

                    return(RedirectToAction(nameof(Index)));
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(RedirectToAction("Index", "Error"));
            }
        }
Ejemplo n.º 2
0
        public void Create2CategoriesTest()
        {
            var category1 = _factory.CreateCategory("Category 1", "Description", 5, null);
            var category2 = _factory.CreateCategory("Category 2", "Description 2", 5, null);

            _storage.CreateCategory(category1);
            _storage.CreateCategory(category2);

            var newCategory = _storage.GetAllCategories().FirstOrDefault();

            Assert.IsNotNull(newCategory);
            Assert.AreEqual(1, _storage.GetAllCategories().Count());
            Assert.AreEqual(category2.Name, newCategory.Name);
            Assert.AreEqual(category2.Description, newCategory.Description);
            Assert.AreEqual(5, newCategory.Id);
        }
Ejemplo n.º 3
0
        public static ICategory Convert(IDictionary <string, object> line, ICategoryFactory categoryFactory)
        {
            var id          = (long)line["id"];
            var name        = line["name"].ToString();
            var description = line["description"].ToString();

            var account = categoryFactory.CreateCategory(name, description, id, null);

            return(account);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            _factory = new RegularCategoryFactory();
            _storage = new SqLiteCategoryStorage(_factory);
            _storage.DeleteAllData();

            {
                var name        = "Test Category";
                var description = "Test Description";
                _category = _factory.CreateCategory(name, description, 1, null);
            }


            {
                var name        = $"Child {_category.Name} Category";
                var description = $"Child {_category.Name} Description";
                _childCategory = _factory.CreateCategory(name, description, 2, _category);
            }
        }
Ejemplo n.º 5
0
        public ICategory CreateCategory(string name, string description, long id, ICategory parentCategory)
        {
            var category = CategoryFactory.CreateCategory(name, description, id, parentCategory);

            return(CreateCategory(category));
        }