Example #1
0
        public CategoryController(ICategoryServices categoryServices)
        {
            this._categoryServices = categoryServices;

            if (_categoryServices.Count() == 0)
            {
                List <Category> items = new List <Category>();

                items.Add(new Category("Regular Question"));
                items.Add(new Category("C#"));
                items.Add(new Category("PHP"));
                items.Add(new Category("Ruby and Rails"));
                items.Add(new Category("Javascript"));
                items.Add(new Category("Java"));
                items.Add(new Category("Data Analysis - BI"));
                items.Add(new Category("SQL Server"));
                items.Add(new Category("General"));

                foreach (var categorias in items)
                {
                    _categoryServices.Add(categorias);
                }

                _categoryServices.Save();
            }
        }
Example #2
0
        public async Task <MessageModel <string> > Post([FromBody] Category category)
        {
            var data = new MessageModel <string>();

            var id = (await _categoryServices.Add(category));

            data.success = id > 0;
            if (data.success)
            {
                data.msg  = "添加成功";
                data.data = id.ObjToString();
            }

            return(data);
        }
Example #3
0
        public IActionResult Add(CategoryAddModel categoryAddModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(categoryAddModel));
            }

            else
            {
                Category category = new Category
                {
                    CategoryName = categoryAddModel.CategoryName
                };

                ICategoryServices.Add(category);
                return(RedirectToAction("Index"));
            }
        }
        public IActionResult Add(CategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                var categoryForAdd = new Category
                {
                    AddedBy   = "iso",
                    AddedDate = DateTime.Now,
                    isActive  = true,
                    Name      = categoryViewModel.Category.Name
                };
                try
                {
                    _categoryServices.Add(categoryForAdd);
                    return(RedirectToAction("GetCategories"));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(RedirectToAction("GetCategories"));
        }
Example #5
0
 public HttpResponseMessage Post([FromBody] Category category)
 {
     return(ToJson(_categoryServices.Add(category)));
 }