public ActionResult EditTour(int id) { OrderedTour tour = tourMan.GetTourInfo(id); List <OrderedTour_ExcursionSight> excursionSight = excMan.GetExcursionSightInfo(id); List <string> excursionSightArray = new List <string>(); for (int i = 0; i < excursionSight.Count; i++) { foreach (var x in excursionSight) { if (x.OrdinalNumber == i && x.ExcursionSightId.HasValue) { excursionSightArray.Add((ExcursionManager.GetExcursionSightName((int)x.ExcursionSightId)).ExcursionSightName); } } } TourModel tourM = new TourModel { OrderedTourId = tour.OrderedTourId, Date = tour.Date, ExcursionName = tour.Excursion.ExcursionName, ClientName = tour.Client.FirstName + " " + tour.Client.LastName, ExcursionSight = excursionSightArray }; if (tour != null) { return(Json(RenderPartialViewToString("EditTour", tourM), JsonRequestBehavior.AllowGet)); } return(View("Index")); }
public JsonResult AddTour(TourModel Model) { string error = ""; if (ModelState.IsValid) { int ClientId = GetClientId(Model.ClientName); int ExcursionId = GetExcursionId(Model.ExcursionName); OrderedTour objTour = new OrderedTour { Date = Model.Date, ClientId = ClientId, ExcursionId = ExcursionId }; int orderedTourId = OrderedTourManager.AddNewTour(objTour); if (orderedTourId > -1) { for (int i = 0; i < Model.ExcursionSight.Count; i++) { var excursionSightId = GetExcursionSightId(Model.ExcursionSight[i], ExcursionId); AddExcursionSight(orderedTourId, excursionSightId, i); } } } else { error = "Form is incorrect."; return(Json(new { status = false, error }, JsonRequestBehavior.AllowGet)); } return(Json(new { status = true, error }, JsonRequestBehavior.AllowGet)); }
public static int AddNewTour(OrderedTour objTour) { try { using (UserContext db = new UserContext()) { db.OrderedTours.Add(objTour); db.SaveChanges(); } return(objTour.OrderedTourId); } catch { return(-1); } }
public static Boolean EditTourInfo(int Id, DateTime Date, int ClientId, int ExcursionId) { try { using (UserContext db = new UserContext()) { OrderedTour tour = db.OrderedTours.Find(Id); tour.Date = Date; tour.ClientId = ClientId; tour.ExcursionId = ExcursionId; db.SaveChanges(); } return(true); } catch { return(false); } }