public IActionResult Update(ProductMv product)
        {
            ViewBag.Categories = CategoryBus.GetAll().Result.Where(x => x.CategoryParent == TypeCategories.Child).ToList();
            var productData = ProductBus.GetById(product.Id).Result;

            if (!ModelState.IsValid)
            {
                return(View(productData));
            }
            product.ModifiedBy = Guid.Parse("a845b16a-4ca6-48e2-4ca6-08d817450c1a");
            if (product.FileImage != null)
            {
                var ms = new MemoryStream();
                product.FileImage.CopyTo(ms);
                var    fileBytes = ms.ToArray();
                string s         = Convert.ToBase64String(fileBytes);
                product.FileData  = s;
                product.FileImage = null;
            }
            if (ProductBus.Update(product.Id, product).Result)
            {
                TempData[ConstKey.Success] = "Success!";
                return(RedirectToAction("Index"));
            }
            TempData[ConstKey.Error] = "Fail! Try again.";
            return(View(productData));
        }
Esempio n. 2
0
        public ActionResult Edit(ProductMv product)
        {
            ViewBag.ListCategory = new CategoryDao().ListCate();
            var doto = new ProductDao().GetDetailProduct(product.ID);

            if (ModelState.IsValid)
            {
                try
                {
                    if (new ProductDao().EditProduct(product))
                    {
                        TempData["SuccessMes"] = "Sửa thành công";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ViewBag.Message = "Hệ thống gặp sự cố, hãy thử lại lần nữa";
                        return(View(doto));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    ViewBag.Message = "Hệ thống gặp sự cố, hãy thử lại lần nữa";
                    return(View(doto));
                }
            }
            else
            {
                return(View(doto));
            }
        }
Esempio n. 3
0
 public bool EditProduct(ProductMv product)
 {
     return(cl.SuaBaiViet(new BaiViet()
     {
         MaBaiViet = product.ID,
         TieuDe = product.Title,
         NoiDung = product.Content,
         MaDanhMuc = product.CateId
     }));
 }
 public IActionResult Put(Guid id, [FromBody] ProductMv product)
 {
     try
     {
         return(Ok(_container.ProductFactory.Update(id, product)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(BadRequest());
     }
 }
 public IActionResult Post([FromBody] ProductMv product)
 {
     try
     {
         return(Created(Url.Action("Get"), _container.ProductFactory.CreateNew(product)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(BadRequest());
     }
 }
Esempio n. 6
0
        public bool CreateNewProduct(ProductMv product)
        {
            var data = new BaiViet()
            {
                TieuDe      = product.Title,
                NoiDung     = product.Content,
                MaDanhMuc   = product.CateId,
                MaNguoiDung = product.UserId,
            };

            return(cl.TaoBaiVietMoi(data));
        }
Esempio n. 7
0
        public ActionResult CreatNenContent(ProductMv product)
        {
            var data = (UserLogin)Session[CommonConstants.USER_SESSION];

            if (data != null)
            {
                ViewBag.ListCategory = new CategoryDao().ListCate();
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (!new ProductDao().ChecKTileExist(product.Title))
                        {
                            product.UserId = data.UserID;
                            if (new ProductDao().CreateNewProduct(product))
                            {
                                TempData["SuccessMes"] = "Thêm mới thành công";
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                ViewBag.Message = "Hệ thống gặp sự cố, hãy thử lại lần nữa";
                                return(View());
                            }
                        }
                        else
                        {
                            ViewBag.Message = "Tiêu đề này đã có sẵn từ trước vui lòng kiểm tra lại";
                            return(View());
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        ViewBag.Message = "Hệ thống gặp sự cố, hãy thử lại lần nữa";
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
 public IActionResult Create(ProductMv product)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     if (product.FileImage != null)
     {
         var ms = new MemoryStream();
         product.FileImage.CopyTo(ms);
         var    fileBytes = ms.ToArray();
         string s         = Convert.ToBase64String(fileBytes);
         product.FileData  = s;
         product.FileImage = null;
     }
     product.ModifiedBy = Guid.Parse("a845b16a-4ca6-48e2-4ca6-08d817450c1a");
     if (ProductBus.Post(product).Result)
     {
         TempData[ConstKey.Success] = "Success!";
         return(RedirectToAction("Index"));
     }
     TempData[ConstKey.Error] = "Fail! Try again.";
     return(View());
 }
Esempio n. 9
0
        public static async Task <bool> Update(object id, ProductMv product)
        {
            var result = await ServiceApi.Update(ModelName, product.Id, product);

            return(result.StatusCode == HttpStatusCode.OK);
        }
Esempio n. 10
0
        public static async Task <bool> Post(ProductMv product)
        {
            var result = await ServiceApi.PostData(ModelName, product);

            return(result.StatusCode == HttpStatusCode.Created);
        }