Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["purchaseid"] != null)
     {
         int            purchaseid = int.Parse(Session["purchaseid"].ToString());
         MovieDbContext context    = new MovieDbContext();
         // Fetch the Details of Purchase using Purchase ID
         TicketPurchaseHistory purchase = context.TicketPurchaseHistories.FirstOrDefault(p => p.PurchaseID == purchaseid);
         if (purchase != null)
         {
             // Prepare the Result
             string result = "";
             result += "<h1> Movie Name : " + purchase.Movie.MovieName + "</h1>";
             result += "<h1> Show Date : " + purchase.MovieShowDate.ToLongDateString() + "</h1>";
             string showTime = "";
             showTime = (purchase.MovieShowTime / 60).ToString();
             int minute = (purchase.MovieShowTime % 60);
             if (minute < 10)
             {
                 showTime += ":0" + minute.ToString();
             }
             else
             {
                 showTime += ":" + minute.ToString();
             }
             result += "<h1> Show Time : " + showTime + "</h1>";
             result += "<h1> Number of Ticket : " + purchase.NoOfTicket.ToString() + "</h1>";
             result += "<h1> Ticket Price : $" + purchase.TicketPrice.ToString() + "</h1>";
             float total = purchase.NoOfTicket * purchase.TicketPrice;
             result += "<h1> Total Amount : $" + total.ToString() + "</h1>";
             if (purchase.Discount > 0)
             {
                 total   = total - (total / 100 * purchase.Discount);
                 result += "<h1> After getting Member discount, Total Amount Payble : $" + total + "</h1>";
             }
             LiteralSummary.Text = result;
         }
         // Remove purchase id from Session
         Session.Remove("purchaseid");
     }
 }
Example #2
0
        // On Click on Process Button save the details of Purchase Ticket
        protected void BtnProcess_Click(object sender, EventArgs e)
        {
            string error_message = "";
            bool   error_status  = false;
            string firstName     = TxtFirstName.Text.Trim();
            string lastName      = TxtLastName.Text.Trim();

            if (firstName.Length == 0)
            {
                error_status   = true;
                error_message += " * Please Enter Some Value in First Name Box<br>";
            }
            if (lastName.Length == 0)
            {
                error_status   = true;
                error_message += " * Please Enter Some Value in Last Name Box<br>";
            }
            if (DropDownMovieDate.SelectedIndex == 0)
            {
                error_status   = true;
                error_message += " * Please Choose Any Movie Date<br>";
            }
            if (DropDownMovieTime.SelectedIndex == 0)
            {
                error_status   = true;
                error_message += " * Please Choose Any Show Time<br>";
            }
            if (DropDownMovieTicketCategory.SelectedIndex == 0)
            {
                error_status   = true;
                error_message += " * Please Choose Any Ticket Category<br>";
            }
            if (DropDownNumberOfTicket.SelectedIndex == 0)
            {
                error_status   = true;
                error_message += " * Please Choose Any Movie Date<br>";
            }
            if (!error_status)
            {
                int noOfTicket      = int.Parse(DropDownNumberOfTicket.SelectedValue);
                int availableTicket = int.Parse(LabelTotalSeats.Text.Trim());
                if (availableTicket >= noOfTicket)
                {
                    int   movieID     = int.Parse(LabelMovieID.Text.Trim());
                    int   movieTime   = int.Parse(DropDownMovieTime.SelectedValue);
                    float ticketPrice = float.Parse(DropDownMovieTicketCategory.SelectedValue);
                    TicketPurchaseHistory purchase = new TicketPurchaseHistory
                    {
                        MovieID       = movieID,
                        MovieShowDate = DateTime.Parse(DropDownMovieDate.SelectedValue),
                        MovieShowTime = movieTime,
                        NoOfTicket    = noOfTicket,
                        FirstName     = firstName,
                        LastName      = lastName,
                        TicketPrice   = ticketPrice,
                        AccountID     = "",
                        Discount      = 0.0F
                    };
                    if (Session["accountid"] != null)
                    {
                        purchase.AccountID = Session["accountid"].ToString();
                        purchase.Discount  = 20.0F;
                    }
                    var context = new MovieDbContext();
                    try
                    {
                        context.TicketPurchaseHistories.Add(purchase);
                        context.SaveChanges();
                        error_message         = "Your Movie Ticket Are Booked " + purchase.PurchaseID.ToString();
                        Session["purchaseid"] = purchase.PurchaseID;
                        Response.Redirect("Summary.aspx");
                    }
                    catch (Exception ex)
                    {
                        error_status  = true;
                        error_message = ex.Message;
                    }
                }
                else
                {
                    error_status   = true;
                    error_message += "There is No Enough Ticket Avaiable<br>";
                }
            }
            string style = "color:green;font-size:20px;";

            if (error_status)
            {
                style = "color:red;font-size:20px;";
            }
            LiteralError.Text = "<p style=\"" + style + "\">" + error_message + "</p>";
        }