Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("MaTd,TenTd,MoTa,Hinh,Nhom,Price")] ThucDon thucDon)
        {
            if (id != thucDon.MaTd)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(thucDon);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ThucDonExists(thucDon.MaTd))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Nhom"] = new SelectList(_context.Nhoms, "MaNhom", "TenNhom", thucDon.Nhom);
            return(View(thucDon));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Sdtkh,DiaChiKh,Tenkh,NgayHD,EmailKh")] Cart cart)
        {
            if (id != cart.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cart);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CartExists(cart.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cart));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("MaTd,TenTd,MoTa,Hinh,ImageFile,Nhom,Price")] ThucDon thucDon)
        {
            if (id != thucDon.MaTd)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                try
                {
                    string rootpath = _hostEnvironment.WebRootPath;
                    if (thucDon.ImageFile is null)
                    {
                    }
                    else
                    {
                        string fileName = Path.GetFileNameWithoutExtension(thucDon.ImageFile.FileName);
                        string ext      = Path.GetExtension(thucDon.ImageFile.FileName);
                        thucDon.Hinh = fileName = thucDon.MaTd + DateTime.Now.ToString("ddmmyyyy") + ext;
                        string path = Path.Combine(rootpath + "/img/", fileName);
                        using (var fs = new FileStream(path, FileMode.Create))
                        {
                            await thucDon.ImageFile.CopyToAsync(fs);
                        }
                    }

                    _context.Update(thucDon);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ThucDonExists(thucDon.MaTd))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Nhom"] = new SelectList(_context.Nhoms, "MaNhom", "TenNhom", thucDon.Nhom);
            return(View(thucDon));
        }