Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string id, [Bind("ID_DanhMuc,TenDanhMuc,TrangThai")] DanhMucModel danhMucModel)
        {
            if (id != danhMucModel.ID_DanhMuc)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(danhMucModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DanhMucModelExists(danhMucModel.ID_DanhMuc))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(danhMucModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,User_ID,HoTen,Sdt,ThanhTien,TrangThai")] HoaDonModel hoaDonModel)
        {
            if (id != hoaDonModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hoaDonModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HoaDonModelExists(hoaDonModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["User_ID"] = new SelectList(_context.Set <UserModel>(), "ID", "ID", hoaDonModel.User_ID);
            return(View(hoaDonModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,HoaDon_ID,TenSP,SoLuong,Gia,KhuyenMai,ThanhTien")] ChiTietHoaDonModel chiTietHoaDonModel)
        {
            if (id != chiTietHoaDonModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(chiTietHoaDonModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChiTietHoaDonModelExists(chiTietHoaDonModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HoaDon_ID"] = new SelectList(_context.HoaDonModel, "ID", "ID", chiTietHoaDonModel.HoaDon_ID);
            return(View(chiTietHoaDonModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,TenNCC,DiaChi,TrangThai")] NhaCungCapModel nhaCungCapModel)
        {
            if (id != nhaCungCapModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(nhaCungCapModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NhaCungCapModelExists(nhaCungCapModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(nhaCungCapModel));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("id,User_ID,SanPham_ID,NoiDung,NgayDang,TrangThai")] BinhLuanModel binhLuanModel)
        {
            if (id != binhLuanModel.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(binhLuanModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BinhLuanModelExists(binhLuanModel.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["User_ID"] = new SelectList(_context.UserModel, "ID", "ID", binhLuanModel.User_ID);
            return(View(binhLuanModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,TenLoai,NhaCungCap,TrangThai")] LoaiSanPhamModel loaiSanPhamModel)
        {
            if (id != loaiSanPhamModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(loaiSanPhamModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoaiSanPhamModelExists(loaiSanPhamModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["NhaCungCap"] = new SelectList(_context.Set <NhaCungCapModel>(), "ID", "ID", loaiSanPhamModel.NhaCungCap);
            return(View(loaiSanPhamModel));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,UserName,Password,HoTen,DiaChi,Email,Sdt,Loai,TrangThai")] UserModel userModel)
        {
            if (id != userModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserModelExists(userModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userModel));
        }
Exemplo n.º 8
0
        public async Task <ActionResult <SanPhamModel> > PostSanPhamModel(SanPhamModel sanPhamModel, IFormFile ful, IFormFile ful1)
        {
            _context.SanPhamModel.Add(sanPhamModel);
            await _context.SaveChangesAsync();

            //dat lai ten file hinh theo ID
            string s = sanPhamModel.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
            //Di chuyen file hinh den folder khac
            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot/images/", s);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await ful.CopyToAsync(stream);
            }
            //dat lai ten file hinh theo ID
            string s1 = sanPhamModel.ID + "2nd" + "." + ful1.FileName.Split(".")[ful1.FileName.Split(".").Length - 1];
            //Di chuyen file hinh den folder khac
            var path1 = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot/images/", s1);

            using (var stream1 = new FileStream(path1, FileMode.Create))
            {
                await ful1.CopyToAsync(stream1);
            }
            //Gan lai ten file hinh moi cho cot TenHinh
            sanPhamModel.Image      = s;
            sanPhamModel.Image_List = s1;
            _context.Update(sanPhamModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSanPhamModel", new { id = sanPhamModel.ID }, sanPhamModel));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("ID,TenSP,MaLoai,DanhMuc,Gia,GiaMoi,Image,Image_List,Size,SoLuong,NgayLap,TrangThai")] SanPhamModel sanPhamModel, IFormFile ful, IFormFile ful1)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sanPhamModel);
                await _context.SaveChangesAsync();

                //dat lai ten file hinh theo ID
                string s = sanPhamModel.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                //Di chuyen file hinh den folder khac
                var path = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot/images/", s);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                //dat lai ten file hinh theo ID
                string s1 = sanPhamModel.ID + "2nd" + "." + ful1.FileName.Split(".")[ful1.FileName.Split(".").Length - 1];
                //Di chuyen file hinh den folder khac
                var path1 = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot/images/", s1);
                using (var stream1 = new FileStream(path1, FileMode.Create))
                {
                    await ful1.CopyToAsync(stream1);
                }
                //Gan lai ten file hinh moi cho cot TenHinh
                sanPhamModel.Image      = s;
                sanPhamModel.Image_List = s1;
                _context.Update(sanPhamModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(sanPhamModel));
        }