Exemplo n.º 1
0
        public ActionResult getGroupProduct(int id)
        {
            BoSanPham item = db.BoSanPham.SingleOrDefault(t => t.ID == id);

            if (item != null)
            {
                EditGroupProductModel model = new EditGroupProductModel();
                model.id       = item.ID;
                model.Mota     = item.Mota;
                model.Ten      = item.Ten;
                model.products = new List <ProductInfo>();
                List <ChiTietBoSanPham> listpr = item.ChiTietBoSanPham.ToList();

                for (int i = 0; i < listpr.Count; i++)
                {
                    ProductInfo prod = new ProductInfo();
                    prod.id     = listpr[i].IDSanPham;
                    prod.number = listpr[i].SoLuongThuongMua;
                    prod.Ten    = listpr[i].SanPham.Ten;
                    prod.DioGia = listpr[i].SanPham.DioGia;

                    model.products.Add(prod);
                }

                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> editgroupproduct(EditGroupProductModel model)
        {
            if (model.products.Count <= 0)
            {
                return(null);
            }
            BoSanPham groups = db.BoSanPham.SingleOrDefault(t => t.ID == model.id);

            if (groups != null)
            {
                groups.Ten     = model.Ten;
                groups.Mota    = model.Mota;
                groups.NgayTao = DateTime.Now;

                db.Entry(groups).State = System.Data.Entity.EntityState.Modified;

                for (int i = 0; i < groups.ChiTietBoSanPham.Count; i++)
                {
                    db.ChiTietBoSanPham.RemoveRange(groups.ChiTietBoSanPham);
                }

                for (int i = 0; i < model.products.Count; i++)
                {
                    ChiTietBoSanPham item = db.ChiTietBoSanPham.Create();
                    item.IDBoSanPham      = groups.ID;
                    item.IDSanPham        = model.products[i].id;
                    item.SoLuongThuongMua = model.products[i].number;

                    db.ChiTietBoSanPham.Add(item);
                }
                await db.SaveChangesAsync();

                return(View());
            }

            return(HttpNotFound());
        }