コード例 #1
0
        public IActionResult KiemTraTrungTen(string TenHh)
        {
            string tenKD = MyTool.ConvertUrlFriendly(TenHh);
            var    hh    = _context.HangHoas.SingleOrDefault(p => p.TenKhongDau == tenKD);

            return((hh != null) ? Json(data: "Trùng tên") : Json(data: true));
        }
コード例 #2
0
        public async Task <IActionResult> Create(HangHoa hangHoa, IFormFile fHinh)
        {
            if (ModelState.IsValid)
            {
                if (fHinh != null)
                {
                    hangHoa.Hinh = MyTool.XuLyUpload(fHinh, "HangHoa");
                }

                hangHoa.TenKhongDau = MyTool.ConvertUrlFriendly(hangHoa.TenHh);
                _context.Add(hangHoa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MaLoai"] = new SelectList(_context.Loais, "MaLoai", "TenLoai", hangHoa.MaLoai);

            return(View(hangHoa));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("MaHh,TenHh,Hinh,MoTa,DonGia,GiamGia,MaLoai")] HangHoa hangHoa, IFormFile fHinh)
        {
            if (id != hangHoa.MaHh)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (fHinh != null)
                    {
                        hangHoa.Hinh = MyTool.XuLyUpload(fHinh, "HangHoa");
                    }

                    hangHoa.TenKhongDau = MyTool.ConvertUrlFriendly(hangHoa.TenHh);

                    _context.Update(hangHoa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HangHoaExists(hangHoa.MaHh))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MaLoai"] = new SelectList(_context.Loais, "MaLoai", "TenLoai", hangHoa.MaLoai);
            return(View(hangHoa));
        }