Exemplo n.º 1
0
        public bool EditCategory(CategoryMv category)
        {
            var data = new DanhMuc();

            data.TenDanhMuc = category.Name;
            data.MaDanhMuc  = category.ID;
            return(cl.SuaDanhMuc(data));
        }
Exemplo n.º 2
0
        public CategoryMv getCategoryDetail(int id)
        {
            var result = new CategoryMv();
            var data   = cl.ChitTietDanhMuc(id);

            result.Name = data.TenDanhMuc;
            return(result);
        }
Exemplo n.º 3
0
        public bool CreateNewCategory(CategoryMv category)
        {
            var data = new DanhMuc();

            data.TenDanhMuc = category.Name;
            var result = cl.ThemMoiDanhMuc(data);

            return(result);
        }
Exemplo n.º 4
0
 public IActionResult Post([FromBody] CategoryMv category)
 {
     try
     {
         return(Created(Url.Action("Get"), _container.CategoryFactory.CreateNew(category)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(BadRequest());
     }
 }
Exemplo n.º 5
0
 public IActionResult Put(Guid id, [FromBody] CategoryMv category)
 {
     try
     {
         if (_container.CategoryFactory.Update(id, category))
         {
             return(Ok());
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(BadRequest());
     }
 }
Exemplo n.º 6
0
        public IActionResult Create(CategoryMv category)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            category.CategoryParent = TypeCategories.Parent;
            var res = ServiceApi.PostData <CategoryMv>(ModelName, category).Result;

            if (res.IsSuccessStatusCode)
            {
                TempData[ConstKey.Success] = "Success";
                return(RedirectToAction("Index"));
            }
            TempData[ConstKey.Error] = "Error,Try Again! ";
            return(View());
        }
Exemplo n.º 7
0
 public IActionResult Post([FromBody] CategoryMv category)
 {
     try
     {
         var res = _unitOfWork.Categories.CreateNewAddReturnObject(_mapper.Map <Category>(category));
         if (_unitOfWork.Commit())
         {
             return(Created(Url.Action("Get"), res));
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(NotFound("No data"));
     }
 }
Exemplo n.º 8
0
 public IActionResult Put(Guid id, [FromBody] CategoryMv categoryMv)
 {
     try
     {
         var category = _unitOfWork.Categories.GetById(id).Result;
         category.Name = categoryMv.Name;
         _unitOfWork.Categories.Edit(category);
         if (_unitOfWork.Commit())
         {
             return(Ok());
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(NotFound("No data"));
     }
 }
Exemplo n.º 9
0
        public IActionResult Update(CategoryMv category)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("DetailParent", "Category", new { id = category.Id }));
            }
            ;
            category.CategoryParent = TypeCategories.Child;
            var res = ServiceApi.Update <CategoryMv>(ModelName, category.Id, category).Result;

            if (res.IsSuccessStatusCode)
            {
                TempData[ConstKey.Success] = "Success";
            }
            else
            {
                TempData[ConstKey.Error] = "Error,Try Again! ";
            }
            return(RedirectToAction("DetailParent", "Category", new { id = category.Id }));
        }
Exemplo n.º 10
0
 public ActionResult Edit(CategoryMv category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (!new CategoryDao().checkExistCategory(category.Name))
             {
                 if (new CategoryDao().EditCategory(category))
                 {
                     TempData["SuccessMes"] = "Sửa danh mục thành công";
                     return(RedirectToAction("Index"));
                 }
                 else
                 {
                     ViewBag.Message = "Hệ thống gặp sự cố  không thể thêm được thử lại";
                     return(View());
                 }
             }
             else
             {
                 ViewBag.Message = "Danh Mục này đã có sẵn từ trước vui lòng kiểm tra lại";
                 return(View());
             }
         }
         catch
         {
             ViewBag.Message = "Hệ thống gặp sự cố, hãy thử lại lần nữa";
             return(View());
         }
     }
     else
     {
         return(View());
     }
 }