Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Sdtkh,DiaChiKh,Tenkh,EmailKh")] Cart cart)
        {
            if (ModelState.IsValid)
            {
                cart.NgayHD = DateTime.Now;
                cart.Id     = _context.Carts.Count() + 1;
                _context.Add(cart);
                await _context.SaveChangesAsync();



                var liscart = ListCart();
                foreach (var item in liscart)
                {
                    var TempData = new CartItem();
                    TempData.Id      = cart.Id;
                    TempData.MaTd    = item.thucDon.MaTd;
                    TempData.SoLuong = item.Quantity;
                    _context.Add(TempData);
                    await _context.SaveChangesAsync();
                }
                HttpContext.Session.Clear();
                return(RedirectToAction("category", "thucdons"));
            }
            return(View(cart));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("MaTd,TenTd,MoTa,ImageFile,Nhom,Price")] ThucDon thucDon)
        {
            if (ModelState.IsValid)
            {
                if (thucDon.ImageFile is null)
                {
                    thucDon.Hinh = "unchose.jpg";
                }
                else
                {
                    string rootpath = _hostEnvironment.WebRootPath;
                    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.Add(thucDon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Nhom"] = new SelectList(_context.Nhoms, "MaNhom", "TenNhom", thucDon.Nhom);
            return(View(thucDon));
        }
Esempio n. 3
0
        public async Task <IActionResult> PutThucDon(int id, ThucDon thucDon)
        {
            if (id != thucDon.MaTd)
            {
                return(BadRequest());
            }

            _context.Entry(thucDon).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ThucDonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,Sdtkh,DiaChiKh,Tenkh,NgayHD,EmailKh")] Cart cart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cart));
        }
        public async Task <IActionResult> Create([Bind("MaTd,TenTd,MoTa,Hinh,Nhom,Price")] ThucDon thucDon)
        {
            if (ModelState.IsValid)
            {
                _context.Add(thucDon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Nhom"] = new SelectList(_context.Nhoms, "MaNhom", "TenNhom", thucDon.Nhom);
            return(View(thucDon));
        }
Esempio n. 6
0
        public async Task <IActionResult> Post(NhomModel model)
        {
            model.MaNhom = _context.Nhoms.Count() + 1;

            if (!string.IsNullOrEmpty(model.MaNhom.ToString()))
            {
                _context.Set <Nhom>().Add(new Nhom {
                    MaNhom = model.MaNhom, TenNhom = model.TenNhom
                });
                await _context.SaveChangesAsync();

                return(Ok("Added"));
            }
            else
            {
                return(BadRequest());
            }
        }