Exemplo n.º 1
0
 /// <summary>
 /// Delete Function
 /// </summary>
 public void DeleteFunction()
 {
     try
     {
         SizeSP spSize = new SizeSP();
         if (spSize.SizeDeleting(decSizeId) <= 0)
         {
             Messages.ReferenceExistsMessage();
         }
         else
         {
             Messages.DeletedMessage();
             GridFill();
             Clear();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SZ5" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Exemplo n.º 2
0
        public ActionResult Create(ProductViewModel model, IFormFile[] files)
        {
            if (ModelState.IsValid)
            {
                SanPham sp = new SanPham();
                {
                    sp.MaSanphan  = model.MaSanphan;
                    sp.TenSanpham = model.TenSanpham;
                    sp.GiaSanpham = model.GiaSanpham;
                    sp.GiaKm      = model.GiaKm;
                    sp.Mota       = model.Mota;
                    sp.IdDanhmuc  = model.IdDanhmuc;
                    sp.SoLuong    = model.SoLuong;
                }
                _sanPhamRepository.Insert(sp);
                _unitOfWork.SaveChange();

                MauSP color = new MauSP();
                {
                    color.IdSanpahm = model.MaSanphan;
                    color.color     = model.color;
                }
                _mauRepositoty.Insert(color);
                _unitOfWork.SaveChange();

                SizeSP s = new SizeSP();
                {
                    s.IdSanpahm = model.MaSanphan;
                    s.size      = model.size;
                }
                _sizeRepositoty.Insert(s);
                _unitOfWork.SaveChange();

                AnhSanPham img = new AnhSanPham();
                {
                }
                _imageRepository.Insert(img);
                _unitOfWork.SaveChange();

                if (files != null)
                {
                    AnhSanPham anh = new AnhSanPham();
                    foreach (var photo in files)
                    {
                        var path   = Path.Combine(_environment.WebRootPath, "Images", photo.FileName);
                        var stream = new FileStream(path, FileMode.Create);
                        photo.CopyToAsync(stream);
                        anh.IdSanpahm = model.MaSanphan;
                        anh.Url       = path;
                        _imageRepository.Insert(anh);
                        _unitOfWork.SaveChange();
                    }
                }

                var uploads = Path.Combine(_environment.WebRootPath, "Images");
                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    }
                }
                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }