Beispiel #1
0
        public ActionResult Create(HttpPostedFileBase video, ProductViewModels vModel)
        {
            if (ModelState.IsValid)
            {
                //ToDo  upload video
                if (video != null)
                {
                    string SourceFileName = Path.GetFileName(video.FileName);
                    string VideoUrl       = Path.Combine("~/Videos", SourceFileName);
                    string TargetFileName = Path.Combine(Server.MapPath("~/Videos"), SourceFileName);
                    video.SaveAs(TargetFileName);

                    //SourceFileName = Path.GetFileName(File1.FileName);
                    //string PicUrl = Path.Combine("~/Pic", SourceFileName);
                    //TargetFileName = Path.Combine(Server.MapPath("~/Pic"), SourceFileName);
                    //file.SaveAs(TargetFileName);

                    if (Request.Files["File1"] != null)
                    {
                        byte[] ImageContent = null;
                        using (BinaryReader br = new BinaryReader(Request.Files["File1"].InputStream))
                        {
                            ImageContent = br.ReadBytes(
                                Request.Files["File1"].ContentLength);
                        }

                        vModel.Picture = ImageContent;
                    }

                    //return RedirectToAction("Create");
                    ProductEntity pe = new ProductEntity();
                    Boolean       isSucced;

                    //取得目前登入使用者Id
                    var UserId = HttpContext.User.Identity.GetUserId();
                    vModel.MId      = UserId;
                    vModel.VidioUrl = VideoUrl;
                    isSucced        = pe.Insert(vModel);
                    return(RedirectToAction("Index"));
                    //return Content("Insert state==>" + isSucced.ToString());
                    //string total = ShowInfo(vModel);
                    //return Content(total);
                }
            }

            //return Content("<root>check failure</root>", "application/xml");
            return(View(vModel));
        }