コード例 #1
0
 public bool AddTour(ATour tour)
 {
     using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext())
     {
         Tour newTour = new Tour();
         newTour.TourName = tour.TourName;
         newTour.TourPrice = tour.TourPrice;
         newTour.TourLocation = tour.TourLocation;
         newTour.TourArea = tour.TourArea;
         newTour.TourCategory = tour.TourCategory;
         newTour.TourDuration = (short)tour.TourDuration;
         newTour.TourDescription = tour.TourDescription;
         newTour.MinReg = (byte)tour.MinReg;
         newTour.MaxReg = (byte)tour.MaxReg;
         newTour.TourID = System.Guid.NewGuid();
         dc.Tours.InsertOnSubmit(newTour);
         dc.SubmitChanges();
         return true;
     }
 }
コード例 #2
0
 public ActionResult Create(ATour tour)
 {
     try
     {
         if (ModelState.IsValid)
         {
             BTourGuideOp tourOp = new BTourGuideOp();
             tourOp.AddTour(tour);
             return RedirectToAction("Index");
         }
         else
         {
             return View();
         }
     }
     catch(Exception e)
     {
         TempData["CreateException"] = "Error in tour creation: " + e.Message;
         return View();
     }
 }
コード例 #3
0
        public bool EditTour(ATour tour)
        {
            using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext())
            {

                Tour row = (from c in dc.Tours
                                    where (c.TourID.ToString() == tour.TourID)
                                    select c).FirstOrDefault<Tour>();
                row.MaxReg = (byte)tour.MaxReg;
                row.MinReg = (byte)tour.MinReg;
                row.TourArea = tour.TourArea;
                row.TourCategory = tour.TourCategory;
                row.TourDescription = tour.TourDescription;
                row.TourDuration = (short)tour.TourDuration;
                row.TourLocation = tour.TourLocation;
                row.TourName = tour.TourName;
                row.TourPrice = tour.TourPrice;
                row.ImageData = tour.ImageData;
                row.ImageMimeType = tour.ImageMimeType;
                dc.SubmitChanges();
                return true;
            }
        }
コード例 #4
0
        public ActionResult Edit(string id, ATour tour, HttpPostedFileBase image)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (image != null)
                    {
                        tour.ImageMimeType = image.ContentType;
                        tour.ImageData = new byte[image.ContentLength];
                        image.InputStream.Read(tour.ImageData, 0, image.ContentLength);
                    }
                    BTourGuideOp tourOp = new BTourGuideOp();
                    tour.TourID = id;
                    tourOp.EditTour(tour);
                    return RedirectToAction("Index");
                }
                else
                {
                    tour.TourID = id; // important to get the image
                    return View(tour);
                }

            }
            catch (Exception e)
            {
                TempData["EditException"] = "Error in tour edit: " + e.Message;
                return View(tour);
            }
        }
コード例 #5
0
 public ActionResult Delete(string id, ATour tour)
 {
     try
     {
         BTourGuideOp tourOp = new BTourGuideOp();
         tourOp.DeleteTour(id);
         return RedirectToAction("Index");
     }
     catch (Exception e)
     {
         TempData["DeleteException"] = "Error in tour deletion: " + e.Message;
         return View();
     }
 }