コード例 #1
0
        public SpecDetail(specdetail specdetail)
        {
            this.id = specdetail.id;

            this.name  = specdetail.name;
            this.value = specdetail.value;
        }
コード例 #2
0
        public ActionResult Add([Bind(Include = "id,activeFlag,createDate,updateDate")] productdetail productdetail, int productId, int colorId, decimal price, HttpPostedFileBase imgUrl)
        {
            string fileName = System.IO.Path.GetFileName(imgUrl.FileName);
            String date     = DateTime.Now.ToString();

            System.Diagnostics.Debug.WriteLine("date " + date);
            string urlImage = Server.MapPath("~/Content/client/img/product/" + fileName);

            imgUrl.SaveAs(urlImage);
            productdetail.imgUrl = fileName;
            int countSpec = Convert.ToInt32(Request.Form["countSpec"]);

            System.Diagnostics.Debug.WriteLine("product id " + productId);
            System.Diagnostics.Debug.WriteLine("color id " + colorId);
            System.Diagnostics.Debug.WriteLine("price " + price);
            System.Diagnostics.Debug.WriteLine("file name " + fileName);

            System.Diagnostics.Debug.WriteLine("count " + countSpec);

            spec spec = new spec();

            spec.activeFlag = 1;
            spec.createDate = DateTime.Now;
            spec.updateDate = DateTime.Now;
            db.specs.Add(spec);
            db.SaveChanges();

            for (int i = 0; i < countSpec; i++)
            {
                specdetail sd = new specdetail();
                sd.spec = db.specs.Find(spec.id);
                String paramName  = "name_" + i;
                String paramValue = "value_" + i;
                String name       = Convert.ToString(Request.Form[paramName]);
                String value      = Convert.ToString(Request.Form[paramValue]);

                sd.name       = name;
                sd.value      = value;
                sd.activeFlag = 1;
                sd.createDate = DateTime.Now;
                sd.updateDate = DateTime.Now;

                db.specdetails.Add(sd);
                db.SaveChanges();
            }


            productdetail.product    = db.products.Find(productId);
            productdetail.spec       = db.specs.Find(spec.id);
            productdetail.color      = db.colors.Find(colorId);
            productdetail.price      = price;
            productdetail.activeFlag = 1;
            productdetail.createDate = DateTime.Now;
            productdetail.updateDate = DateTime.Now;

            db.productdetails.Add(productdetail);
            db.SaveChanges();


            return(RedirectToAction("productDetailList", "AdminProductDetail", new { productId = productId }));
        }