public ActionResult Create(Voucher voucher) { using (var db = new WishoianContext()) { if (ModelState.IsValid) { voucher.VoucherId = Guid.NewGuid(); 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.Vouchers.Add(voucher); db.SaveChanges(); return RedirectToAction("Index"); } return View(voucher); } }
public ActionResult DeleteConfirmed(Guid id) { using (var db = new WishoianContext()) { Voucher voucher = db.Vouchers.Find(id); db.Vouchers.Remove(voucher); db.SaveChanges(); return RedirectToAction("Index"); } }
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(); } }