public ActionResult CreateCity(tCityCountry _city, HttpPostedFileBase fImage, string fCountry, string fCity)
        {
            if (ModelState.IsValid)
            {
                if (fImage != null && fImage.ContentLength > 0)
                {
                    //檢查國家是否重複新增
                    //若有則直接新增城市
                    //若無則先新增國家在新增城市
                    var _country = from c in db.tCityCountry
                                   where (c.fCC_Place == fCountry)
                                   select c;

                    if (_country.Count() == 0)
                    {
                        _city.fCC_Dad   = null;
                        _city.fCC_Place = fCountry;

                        db.tCityCountry.Add(_city);
                        db.SaveChanges();

                        tCityCountry tcc = new tCityCountry();
                        tcc.fCC_Dad   = db.tCityCountry.AsEnumerable().Last().fCC_ID;
                        tcc.fCC_Place = fCity;

                        //將上傳的圖轉成二進位
                        var    imgSize = fImage.ContentLength;
                        byte[] imgByte = new byte[imgSize];
                        fImage.InputStream.Read(imgByte, 0, imgSize);
                        tcc.fCC_Img = imgByte;

                        db.tCityCountry.Add(tcc);
                        db.SaveChanges();
                    }
                    else
                    {
                        _city.fCC_Dad   = _country.Single().fCC_ID;
                        _city.fCC_Place = fCity;

                        //將上傳的圖轉成二進位
                        var    imgSize = fImage.ContentLength;
                        byte[] imgByte = new byte[imgSize];
                        fImage.InputStream.Read(imgByte, 0, imgSize);
                        _city.fCC_Img = imgByte;

                        db.tCityCountry.Add(_city);
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Index", "TravelMapHome"));
                }
                else
                {
                    ViewBag.message = "請選擇圖檔!!";
                }
            }
            return(View());
        }
        public ActionResult GetImageByte(int id)
        {
            tCityCountry _citycountry = db.tCityCountry.Find(id);

            byte[] img = _citycountry.fCC_Img;
            try
            {
                return(File(img, "image/jpeg"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(HttpPostedFileBase fImage)
        {
            tCityCountry _ct = db.tCityCountry.Find(Convert.ToInt32(Request.Form["cityID"]));

            _ct.fCC_Place = Request.Form["CityName"];

            //將上傳的圖轉成二進位
            var imgSize = fImage.ContentLength;

            byte[] imgByte = new byte[imgSize];
            fImage.InputStream.Read(imgByte, 0, imgSize);
            _ct.fCC_Img = imgByte;


            db.Entry(_ct).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("ShowAll"));
        }
        public ActionResult Index(tCityCountry _city, tSampleProposal _proposal, List <string> ActCheckbox)
        {
            _proposal.fCC_ID   = _city.fCC_ID;
            _proposal.fSP_Date = DateTime.Now;
            db.tSampleProposal.Add(_proposal);
            db.SaveChanges();
            int a = db.tSampleProposal.AsEnumerable().Last().fSP_ID;

            tActivitySelect _actselect = new tActivitySelect();

            foreach (string _actlist in ActCheckbox)
            {
                _actselect.fSP_ID = a;
                _actselect.fAL_ID = Convert.ToInt32(_actlist);
                db.tActivitySelect.Add(_actselect);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Activity"));
        }