Esempio n. 1
0
 public int UpdateKM(long idKM, KhuyenMai km, HttpPostedFileBase hinhAnh, double phanTram)
 {
     if (km.NgayKT <= km.NgayBD)
     {
         return(0);
     }
     else
     {
         KhuyenMai newKM = db.KhuyenMais.Find(idKM);
         newKM.TenKhuyenMai = km.TenKhuyenMai;
         newKM.PhanTram     = phanTram;
         newKM.NgayKT       = km.NgayKT;
         newKM.flag         = true;
         string path = "";
         if (hinhAnh != null)
         {
             if (hinhAnh.ContentLength > 0)
             {
                 string fileName = Path.GetFileName(hinhAnh.FileName);
                 path = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), fileName);
                 hinhAnh.SaveAs(path);
                 //path= path.Replace("\","/");
                 newKM.HinhKhuyenMai = fileName;
             }
         }
         db.SaveChanges();
         return(2);
     }
 }
Esempio n. 2
0
        public void UpdateSach(long idSach, Sach sach, HttpPostedFileBase anhBia, string chude, string ncc, string tg, string nxb, string km, HttpPostedFileBase anh1, HttpPostedFileBase anh2, double?chieuDai, double?chieuRong, double?chieuSau, string mota)
        {
            var newSach = db.Sachs.Find(idSach);

            newSach.Ten        = sach.Ten;
            newSach.Gia        = sach.Gia;
            newSach.SoLuong    = sach.SoLuong;
            newSach.NamXuatBan = sach.NamXuatBan;
            newSach.IdChuDe    = Convert.ToInt64(chude);
            newSach.ChuDe      = db.ChuDes.Find(Convert.ToInt64(chude));
            newSach.IdNCC      = Convert.ToInt64(ncc);
            newSach.NhaCungCap = db.NhaCungCaps.Find(Convert.ToInt64(ncc));
            newSach.IdNXB      = Convert.ToInt64(nxb);
            newSach.NhaXuatBan = db.NhaXuatBans.Find(Convert.ToInt64(nxb));
            newSach.IdTacGia   = Convert.ToInt64(tg);
            newSach.TacGia     = db.TacGias.Find(Convert.ToInt64(tg));
            newSach.HinhThuc   = sach.HinhThuc;
            newSach.MoTa       = mota;
            newSach.NgonNgu    = sach.NgonNgu;
            newSach.TrongLuong = sach.TrongLuong;
            newSach.SoTrang    = sach.SoTrang;
            newSach.KickThuoc  = chieuDai.ToString() + "x" + chieuRong.ToString() + "x" + chieuSau.ToString();
            if (km != "0")
            {
                newSach.IdKhuyenMai = Convert.ToInt64(km);
                newSach.KhuyenMai   = db.KhuyenMais.Find(Convert.ToInt64(km));
            }
            else
            {
                newSach.IdKhuyenMai = 1;
                newSach.KhuyenMai   = db.KhuyenMais.Find(Convert.ToInt64(1));
            }
            GanAnhUpdate(newSach, anhBia, anh1, anh2);
            db.SaveChanges();
        }
Esempio n. 3
0
        public void UpdateCD(long idChuDe, ChuDe chuDe)
        {
            var cd = db.ChuDes.Find(idChuDe);

            cd.Ten    = chuDe.Ten;
            cd.XuatXu = chuDe.XuatXu;
            db.SaveChanges();
        }
Esempio n. 4
0
        public void UpdateKH(long idKhachHang, KhachHang khachHang)
        {
            var kh = db.KhachHangs.Find(idKhachHang);

            kh.Ho       = khachHang.Ho;
            kh.Ten      = khachHang.Ten;
            kh.NgaySinh = khachHang.NgaySinh;
            kh.GioiTinh = khachHang.GioiTinh;
            db.SaveChanges();
        }
 public IActionResult Create(Producer producer)
 {
     if (ModelState.IsValid)
     {
         _context.Add(producer);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(producer));
 }
Esempio n. 6
0
        public void DeleteCTHD(long idCTHD)
        {
            ChiTietHoaDon CTHD = db.ChiTietHoaDon.Find(idCTHD);

            db.ChiTietHoaDon.Remove(CTHD);
            db.SaveChanges();
            if (db.ChiTietHoaDon.Where(i => i.IdHoaDon == CTHD.IdHoaDon).Count() == 0)
            {
                db.HoaDon.Remove(db.HoaDon.Find(CTHD.IdHoaDon));
                db.SaveChanges();
            }
        }
Esempio n. 7
0
 public string Buy(Purchase purchase)
 {
     purchase.Date = DateTime.Now;
     db.Purchases.Add(purchase);
     db.SaveChanges();
     return("Спасибо," + purchase.Person + ", за покупку!");
 }
Esempio n. 8
0
        public HomeController(ToyContext context)
        {
            db = context;
            // добавляем начальные данные
            if (db.Types.Count() != 0)
            {
                return;
            }
            var cat = new ToyType {
                Name = "cat"
            };
            var lego = new ToyType {
                Name = "lego"
            };
            var dog = new ToyType {
                Name = "dog"
            };
            var mouse = new ToyType {
                Name = "mouse"
            };
            var doll = new ToyType {
                Name = "doll"
            };

            var toy1 = new Toy {
                Name = "Grumpy Cat", Type = cat, Price = 599
            };
            var toy2 = new Toy {
                Name = "Tom The Cat", Type = cat, Price = 499
            };
            var toy3 = new Toy {
                Name = "Jerry The Mouse", Type = mouse, Price = 599
            };
            var toy4 = new Toy {
                Name = "Mickey Mouse", Type = mouse, Price = 1099
            };
            var toy5 = new Toy {
                Name = "Minnie Mouse", Type = mouse, Price = 399
            };
            var toy6 = new Toy {
                Name = "Barbie", Type = doll, Price = 299
            };
            var toy7 = new Toy {
                Name = "Ken", Type = doll, Price = 1199
            };
            var toy8 = new Toy {
                Name = "Blue Sad Dog", Type = dog, Price = 899
            };
            var toy9 = new Toy {
                Name = "Star Wars", Type = lego, Price = 199
            };
            var toy10 = new Toy {
                Name = "Ninjago", Type = lego, Price = 299
            };

            db.Types.AddRange(cat, dog, lego, mouse, doll);
            db.Toys.AddRange(toy1, toy2, toy3, toy4, toy5, toy6, toy7, toy8, toy9, toy10);
            db.SaveChanges();
        }
Esempio n. 9
0
        // GET: ChiTietSach
        public ActionResult Index(long id)
        {
            ToyContext db   = new ToyContext();
            Sach       sach = db.Sachs.Find(id);

            sach.LuotXem++;
            db.SaveChanges();
            Session["CTSach"] = sach;
            return(View("Index"));
        }
Esempio n. 10
0
        public void UpdateTG(long idTacGia, TacGia tg, string moTa, HttpPostedFileBase hinhAnh)
        {
            var newTG = db.TacGias.Find(idTacGia);

            newTG.Ten  = tg.Ten;
            newTG.MoTa = moTa;

            string path = "";

            if (hinhAnh != null)
            {
                if (hinhAnh.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(hinhAnh.FileName);
                    path = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), fileName);
                    hinhAnh.SaveAs(path);
                    //path= path.Replace("\","/");
                    newTG.HinhAnh = fileName;
                }
            }
            db.SaveChanges();
        }
Esempio n. 11
0
        public void UpdateNCC(long idNCC, NhaCungCap ncc, string moTa, HttpPostedFileBase hinhAnh)
        {
            var newNCC = db.NhaCungCaps.Find(idNCC);

            newNCC.Ten  = ncc.Ten;
            newNCC.MoTa = moTa;

            string path = "";

            if (hinhAnh != null)
            {
                if (hinhAnh.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(hinhAnh.FileName);
                    path = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), fileName);
                    hinhAnh.SaveAs(path);
                    //path= path.Replace("\","/");
                    newNCC.HinhAnh = fileName;
                }
            }
            db.SaveChanges();
        }
Esempio n. 12
0
        public void ThanhToan(long idHD, string tenNguoiNhan, string diaChi, int sdt)
        {
            HoaDon hd = db.HoaDon.Find(idHD);

            hd.NgayTao         = DateTime.Today;
            hd.TenNguoiNhan    = tenNguoiNhan;
            hd.DiaChi          = diaChi;
            hd.SDT             = sdt.ToString();
            hd.TinhTrangHoaDon = "Đã Thanh Toán";
            double tongTien = 0;

            foreach (var item in db.ChiTietHoaDon.Where(i => i.IdHoaDon == hd.IdHoaDon).ToList())
            {
                Sach sach = db.Sachs.Find(item.IdSach);
                sach.SoLuong = sach.SoLuong - item.SoLuong;
                db.SaveChanges();
                tongTien = tongTien + item.ThanhTien;
            }
            hd.TinhTrangDonHang = "Đang Giao Hàng";
            hd.TongTien         = tongTien;
            db.SaveChanges();
        }
Esempio n. 13
0
        public ToysController(ToyContext context)
        {
            db = context;
            if (!db.Toys.Any())
            {
                var toy1 = new Toy {
                    Name = "Grumpy Cat", Material = "cotton", Price = 599
                };
                var toy2 = new Toy {
                    Name = "Tom The Cat", Material = "cotton", Price = 499
                };
                var toy3 = new Toy {
                    Name = "Jerry The Mouse", Material = "synthetics", Price = 599
                };
                var toy4 = new Toy {
                    Name = "Mickey Mouse", Material = "plastic", Price = 1099
                };
                var toy5 = new Toy {
                    Name = "Minnie Mouse", Material = "plastic", Price = 399
                };
                var toy6 = new Toy {
                    Name = "Barbie", Material = "plastic", Price = 299
                };
                var toy7 = new Toy {
                    Name = "Ken", Material = "plastic", Price = 1199
                };
                var toy8 = new Toy {
                    Name = "Blue Sad Dog", Material = "cotton", Price = 899
                };
                var toy9 = new Toy {
                    Name = "Star Wars", Material = "plastic", Price = 199
                };
                var toy10 = new Toy {
                    Name = "Ninjago", Material = "plastic", Price = 299
                };

                var mat1 = new Material {
                    Name = "cotton"
                };
                var mat2 = new Material {
                    Name = "synthetic"
                };
                var mat3 = new Material {
                    Name = "plastic"
                };

                db.Materials.AddRange(mat1, mat2, mat3);
                db.Toys.AddRange(toy1, toy2, toy3, toy4, toy5, toy6, toy7, toy8, toy9, toy10);
                db.SaveChanges();
            }
        }
Esempio n. 14
0
        public ActionResult Add(Toy toy)
        {
            if (db.Toys.Contains(toy))
            {
                return(BadRequest());
            }

            if (!db.ToyTypes.Contains(toy.Type))
            {
                db.ToyTypes.Add(toy.Type);
            }

            toy.CreationDate = DateTime.Now;
            db.Toys.Add(toy);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        public KhachHang UpdateTK(long idtaikhoan, string email, string newpassword, string newrepassword, string ho, string ten, DateTime ngaysinh, int gioitinh)
        {
            KhachHang kh = db.KhachHangs.Find(idtaikhoan);

            kh.Ho       = ho;
            kh.Ten      = ten;
            kh.NgaySinh = ngaysinh;
            if (gioitinh == 0)
            {
                kh.GioiTinh = true;
            }
            else
            {
                kh.GioiTinh = false;
            }
            if (String.IsNullOrEmpty(newpassword) == false && String.IsNullOrEmpty(newrepassword) == false && newpassword == newrepassword)
            {
                kh.Password = newpassword;
            }
            db.SaveChanges();
            return(kh);
        }
        public ActionResult Giao(long idHD)
        {
            var tk = Session["TaiKhoan"] as KhachHang;

            if (tk == null)
            {
                return(View("../Login/Index"));
            }
            else
            {
                if (tk.LoaiTK != "Admin")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    var db = new ToyContext();
                    db.HoaDon.Find(idHD).TinhTrangDonHang = "Đã Giao Hàng";
                    db.SaveChanges();
                    return(RedirectToAction("Reset", "HoaDon", new { area = "Admin" }));
                }
            }
        }
 public void Save()
 {
     _context.SaveChanges();
 }