public ActionResult Create(LoaiTraSua loaitra)
        {
            DB.LoaiTraSuas.Add(loaitra);
            DB.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult Create(NhanVien nhanvien)
        {
            db.NhanViens.Add(nhanvien);
            db.SaveChanges();

            return(RedirectToAction("List"));
        }
        public ActionResult Create(KhachHang khach)
        {
            DB.KhachHangs.Add(khach);
            DB.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult InsertData()
        {
            string name        = Request.Form["billing_full_name"];
            string phone       = Request.Form["billing_phone"];
            string email       = Request.Form["billing_email"];
            string addresstype = Request.Form["billing_address_1"];
            string address     = Request.Form["billing_address_2"];

            ShoppingCart cart = (ShoppingCart)Session["cart"];
            List <Item>  lst  = new List <Item>();

            if (cart != null)
            {
                lst = cart.lst;
                if (db.KhachHangs.Where(q => q.hotenkh == name && q.sdt == phone && q.email == email).FirstOrDefault() == null)
                {
                    KhachHang khachhang = new KhachHang();
                    khachhang.hotenkh = name;
                    khachhang.diachi  = addresstype + " - " + address;
                    khachhang.email   = email;
                    khachhang.sdt     = phone;

                    db.KhachHangs.Add(khachhang);
                    db.SaveChanges();
                }

                DatHang dathang = new DatHang();
                var     x       = db.KhachHangs.Where(q => q.hotenkh == name && q.sdt == phone && q.email == email).FirstOrDefault();
                dathang.makh    = x.makh;
                dathang.ngaytao = DateTime.Today;
                dathang.Note    = "Chưa được xử lý";

                db.DatHangs.Add(dathang);
                db.SaveChanges();


                CTDatHang cTDatHang = new CTDatHang();
                foreach (var item in lst)
                {
                    cTDatHang.madh      = dathang.madh;
                    cTDatHang.mats      = item.id;
                    cTDatHang.soluong   = item.amount;
                    cTDatHang.dongia    = (decimal)item.price;
                    cTDatHang.thanhtien = (decimal)(item.price * item.amount);

                    db.CTDatHangs.Add(cTDatHang);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(TraSua trasua, HttpPostedFileBase hinhanh)
        {
            if (hinhanh != null && hinhanh.ContentLength > 0)
            {
                var tenanh = Path.GetFileName(hinhanh.FileName);
                var link   = Path.Combine(Server.MapPath("~/Content/img/"), tenanh);

                trasua.anhts = tenanh;
                hinhanh.SaveAs(link);
            }
            if (ModelState.IsValid)
            {
                DB.TraSuas.Add(trasua);
                DB.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(trasua));
            }
        }
Esempio n. 6
0
        public ActionResult Edit(DatHang order)
        {
            DatHang dathang = db.DatHangs.Find(order.madh);

            if (dathang != null)
            {
                dathang.Note = order.Note;

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }