Exemplo n.º 1
0
        protected void btnSubmitPlan_Click(object sender, EventArgs e)
        {
            currentUser = (BLL.User)Session["currentUser"];

            //add to Itinerary table
            newItinerary.userId        = currentUser.Id;
            newItinerary.itineraryName = tbName.Text;
            newItinerary.startDate     = Convert.ToDateTime(tbStartDate.Text);
            newItinerary.endDate       = Convert.ToDateTime(tbEndDate.Text);
            newItinerary.groupSize     = tbNoPeople.Text;

            //Calculate Middle Dates
            DateTime startDate = Convert.ToDateTime(newItinerary.startDate);

            startDate.ToString("dd MMM");
            DateTime      endDate      = Convert.ToDateTime(newItinerary.endDate);
            DateTime      current      = startDate;
            List <string> betweenDates = new List <string>();

            while (current <= endDate)
            {
                var currentDateStr = current.ToString("dd MMM");        //convert 12/1/2020 to 12 Jan
                betweenDates.Add(currentDateStr);
                current = current.AddDays(1);                           //add to current as 12/1/2020
            }

            newItinerary.AddItinerary();
            Response.Write("<script> alert('Plan Created!');</script>");

            //daybydays table
            int datesSize = betweenDates.Count;

            for (int i = 0; i < betweenDates.Count; i++)
            {
                newDayByDay.itineraryId = newItinerary.itineraryId;
                newDayByDay.date        = betweenDates[i];
                newDayByDay.AddDayByDay();
            }

            daybydaysList = betweenDates;

            Session["startDate"] = tbStartDate.Text;
            Session["endDate"]   = tbEndDate.Text;
            createdItineraryId   = newItinerary.itineraryId;

            //check pref
            PrefSelect(newItinerary.itineraryId);
            //days table and planner generate - with pref/no pref
            GeneratePlanner(newItinerary);

            string url = "Timeline.aspx?Id=" + newItinerary.itineraryId;

            Response.Redirect(url);
        }