Пример #1
0
        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));
        }
        public ActionResult Edit(int id, Product sp, HttpPostedFileBase Image)
        {
            // TODO: Add update logic here
            if (Image != null)
            {
                var fileName = Path.GetFileName(Image.FileName);
                var path     = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                if (System.IO.File.Exists(path))
                {
                    sp.Image = fileName;
                }
                else
                {
                    Image.SaveAs(path);
                    sp.Image = fileName;
                }
            }
            else
            {
                ProductBus.UpdateNoImage(id, sp);
            }

            var htf      = HttpContext.Request.Files;
            var lstImage = ProductBus.getListImage(id).ToList();

            for (int i = 1; i < htf.Count; i++)
            {
                if (htf[i].ContentLength > 0)
                {
                    string fileName = "";
                    if (Request.Browser.Browser == "IE")
                    {
                        fileName = Path.GetFileName(htf[i].FileName);
                    }
                    else
                    {
                        fileName = htf[i].FileName;
                    }
                    var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        ProductBus.UpdateImage(fileName, lstImage[i - 1].Image_ID);
                    }
                    else
                    {
                        htf[i].SaveAs(path);
                        ProductBus.UpdateImage(fileName, lstImage[i - 1].Image_ID);
                    }
                }
            }
            ProductBus.Update(id, sp);
            return(RedirectToAction("Index"));
        }
Пример #3
0
        private void TaskControl1_SaveEvent(object sender, EventArgs e)
        {
            isFind = false;
            if (!inputIsCorrect())
            {
                return;
            }
            taskControl1.isSuccessFul = true;
            var hangHoa = new HangHoa()
            {
                Name       = txtProductName.Text,
                DVT        = txtUnit.Text,
                SoLuong    = int.Parse(nbNumber.Value.ToString()),
                DonGiaNhap = double.Parse(txtPriceBuy.Text),
                DonGiaBan  = double.Parse(txtPriceSale.Text),
                GhiChu     = txtNote.Text,
                DaXoa      = false
            };

            if (isAdd)
            {
                var rs = productBus.Add(hangHoa);
                if (rs == true)
                {
                    MessageBox.Show("Thêm hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadAll();
                }
                else
                {
                    MessageBox.Show("Thêm hàng hóa không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                hangHoa.ID = int.Parse(txtProductId.Text);
                var rs = productBus.Update(hangHoa);
                if (rs == false)
                {
                    MessageBox.Show("Sửa hóa không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Sửa hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadAll();
                }
            }
            panelContent.Enabled = false;
        }