public ActionResult Edit(Voucher voucher)
 {
     using (var db = new WishoianContext())
     {
         if (ModelState.IsValid)
         {
             db.Entry(voucher).State = EntityState.Modified;
             if (Request.Files.Count > 0)
             {
                 var hpf = Request.Files[0];
                 if (hpf.ContentLength > 0)
                 {
                     string type = Utility.GetImgeType(hpf.ContentType);
                     string fileName = string.Format("{0}\\{1}.{2}", Server.MapPath("~/WebUpload"), voucher.VoucherId, type);
                     hpf.SaveAs(fileName);
                     voucher.ImageUrl = string.Format("{0}.{1}", voucher.VoucherId, type);
                 }
             }
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(voucher);
     }
 }
Esempio n. 2
0
        public ViewResult ViewTourDetail(Guid tourPlanId)
        {
            using (var db = new WishoianContext())
            {
                var tourPlan = db.TourPlans.Find(tourPlanId);
                if (tourPlan != null)
                {
                    // Set up our ViewModel
                    var viewModel = new TourPlanDetailViewModel
                    {
                        Tour = new TourDetailViewModel() { Tour = tourPlan.Tour, SpecialTourPlan = tourPlan },
                        TourSchedules = tourPlan.Tour.TourSchedules.OrderBy(s => s.IndexDay).ToList(),
                        TourPlan = tourPlan
                    };

                    // Update View
                    db.Entry(tourPlan).State = EntityState.Modified;
                    if (tourPlan.Viewed == null)
                        tourPlan.Viewed = 1;
                    else

                        tourPlan.Viewed += 1;
                    db.SaveChanges();
                    return View(viewModel);

                }
                return View();
            }
        }