Exemplo n.º 1
0
        public ActionResult Index(int id)
        {
            MldProduct           model   = new MldProductDal().Query(id);
            List <MldProductImg> imgList = new MldProductImgDal().QueryList("id asc", "pid=@1", id);

            if (null == imgList || imgList.Count <= 0)
            {
                imgList = new List <MldProductImg>();
                imgList.Add(new MldProductImg()
                {
                    Img = model.Img, Pid = id
                });
            }
            ViewBag.ImgList      = imgList;
            ViewBag.CategoryName = new MldProductCategoryDal().Query(model.Cid).Name;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Index(int cid, string name, string subhead, string profile, string application, string material, string weight, string length, string massOfInertia, string sectionModulus, HttpPostedFileBase profileimg, HttpPostedFileBase img, string content, string datacontent, int allshowflag, int homeshowflag, int iselite, HttpPostedFileBase img1, HttpPostedFileBase img2, HttpPostedFileBase img3, HttpPostedFileBase img4)
        {
            ViewBag.Error     = "none";
            ViewBag.Category1 = new MldProductCategoryDal().QueryList("id asc", "tid=@1", 0);
            if (img != null && img.ContentLength > 0)
            {
                UploadFileResult result = img.FileUpLoad("img", 1024 * 1024 * 4, "product");
                if (!result.Ok)
                {
                    ViewBag.Error = result.Data;
                }
                else
                {
                    MldProduct model = new MldProduct();
                    model.Img = result.Data;
                    List <string> imgList = new List <string>();
                    if (img1 != null && img1.ContentLength > 0)
                    {
                        UploadFileResult result1 = img1.FileUpLoad("img", 1024 * 1024 * 4, "product");
                        if (result1.Ok)
                        {
                            imgList.Add(result1.Data);
                        }
                    }
                    if (img2 != null && img2.ContentLength > 0)
                    {
                        UploadFileResult result2 = img2.FileUpLoad("img", 1024 * 1024 * 4, "product");
                        if (result2.Ok)
                        {
                            imgList.Add(result2.Data);
                        }
                    }
                    if (img3 != null && img3.ContentLength > 0)
                    {
                        UploadFileResult result3 = img3.FileUpLoad("img", 1024 * 1024 * 4, "product");
                        if (result3.Ok)
                        {
                            imgList.Add(result3.Data);
                        }
                    }
                    if (img4 != null && img4.ContentLength > 0)
                    {
                        UploadFileResult result4 = img4.FileUpLoad("img", 1024 * 1024 * 4, "product");
                        if (result4.Ok)
                        {
                            imgList.Add(result4.Data);
                        }
                    }
                    model.Cid          = cid;
                    model.Name         = name;
                    model.SubHead      = subhead;
                    model.Content      = content;
                    model.AllShowFlag  = allshowflag;
                    model.HomeShowFlag = homeshowflag;
                    model.IsElite      = iselite;
                    model.AddTime      = DateTime.Now;

                    model.Profile        = profile;
                    model.Application    = application;
                    model.Material       = material;
                    model.Weight         = weight;
                    model.Length         = length;
                    model.MassOfInertia  = massOfInertia;
                    model.SectionModulus = sectionModulus;


                    if (profileimg != null && profileimg.ContentLength > 0)
                    {
                        UploadFileResult result5 = profileimg.FileUpLoad("img", 1024 * 1024 * 4, "product");
                        if (result5.Ok)
                        {
                            model.ProfileImg = result5.Data;
                        }
                    }


                    int id = dal.Add(model);
                    if (id > 0)
                    {
                        MldProductImgDal imgDal = new MldProductImgDal();
                        foreach (var item in imgList)
                        {
                            MldProductImg itemImg = new MldProductImg();
                            itemImg.Img = item;
                            itemImg.Pid = id;
                            imgDal.Add(itemImg);
                        }
                        ViewBag.Success = "ok";
                    }
                    else
                    {
                        ViewBag.Error = "Error";
                    }
                }
            }
            else
            {
                ViewBag.Error = "Please select the picture to upload";
            }
            return(View());
        }