コード例 #1
0
 public void SaveTSKT(ThongSoKiThuat tskt)
 {
     context.ThongSoKiThuat.AddAsync(tskt);
     context.SaveChanges();
 }
コード例 #2
0
 public void UpdateTSKT(ThongSoKiThuat tskt)
 {
     context.Update(tskt);
     context.SaveChanges();
 }
コード例 #3
0
        public IActionResult Them(SanPham model,
                                  IFormFile AnhDaiDien,
                                  IFormCollection fc,
                                  IFormFile productImages1,
                                  IFormFile productImages2,
                                  IFormFile productImages3
                                  )
        {
            string message = "";

            if (ModelState.IsValid)
            {
                //  model.MaSp = (context.SanPham.ToList().Count() + 1).ToString();

                model.AnhDaiDien  = UploadedFile(AnhDaiDien, "ProductAvatar");
                model.SoLuotXemSp = 0;
                model.Ishot       = Convert.ToBoolean(fc["isHot"].ToString().Split(',')[0]);
                model.Isnew       = Convert.ToBoolean(fc["isNew"].ToString().Split(',')[0]);
                context.SanPham.Add(model);
                context.SaveChanges();

                AnhSanPham pic = new AnhSanPham()
                {
                    MaSp                                                        = model.MaSp,
                    Anh1                                                        = productImages1 != null?UploadedFile(productImages1, "ProductImages") : null,
                                                     Anh2                       = productImages2 != null?UploadedFile(productImages2, "ProductImages") : null,
                                                                           Anh3 = productImages3 != null?UploadedFile(productImages3, "ProductImages") : null,
                };

                context.AnhSanPham.Add(pic);
                context.SaveChanges();

                ThongSoKiThuat tskt;
                List <ThongSo> listTS = dataAccess.ReadThongSo(model.LoaiSp).ToList();
                for (int i = 0; i < listTS.Count(); i++)
                {
                    tskt = new ThongSoKiThuat()
                    {
                        MaSp    = model.MaSp,
                        ThongSo = listTS[i].MaThongSo,
                        GiaTri  = fc[listTS[i].MaThongSo],
                    };

                    context.ThongSoKiThuat.AddAsync(tskt);
                    context.SaveChanges();
                    tskt = null;
                }



                //for (int i = 1; i < 10; i++)
                //{
                //    var param = "attribute_" + i.ToString() + "_name";
                //    var param2 = "attribute_" + i.ToString() + "_value";
                //    if (fc[param].ToString()!="" && fc[param2].ToString() != "")
                //    {
                //        var thongSoKiThuat = new ThongSoKiThuat()
                //        {
                //            MaTskt = (context.ThongSoKiThuat.ToList().Count() + 1).ToString(),
                //            ThuocTinh = fc[param],
                //            GiaTri = fc[param2],
                //            MaSp = model.MaSp
                //        };
                //        context.ThongSoKiThuat.Add(thongSoKiThuat);
                //        context.SaveChanges();
                //    }
                //    else break;

                //}
                return(RedirectToAction("QuanLy", "Admin", new { id = model.LoaiSp }).WithSuccess("Thành công", "Sản phẩm đã được thêm. ID:" + model.MaSp));
            }
            else
            {
                ModelState.AddModelError("", "aaa");
                ViewData["MaLoai"] = model.LoaiSp;
                return(View(model));
            }
        }