Ejemplo n.º 1
0
 public ActionResult Create(AReg reg, string TourNameOptions, string UsernameOptions, string TourDateOptions)
 {
     try
     {
         if (ModelState.IsValid)
         {
             BTourGuideOp tourOp = new BTourGuideOp();
             List<ATour> tours = tourOp.GetTours();
             ATour tour = tours.Single(x => x.TourName == TourNameOptions);
             reg.TourID = tour.TourID;
             List<AUser> users = tourOp.GetUsers();
             AUser user = users.Single(x => x.Username == UsernameOptions);
             reg.UserID = user.UserID;
             List<AEvent> events = tourOp.GetEvents();
             AEvent tourEvent = events.Single(x => x.TourName == TourNameOptions && x.TourDate.ToString() == TourDateOptions.ToString());
             reg.TourDate = tourEvent.TourDate;
             tourOp.AddReg(reg);
             return RedirectToAction("Index");
         }
         else
         {
             // Saving the dropdown values selected by user:
             List<SelectListItem> tourList = Lists.CreateTourList();
             ViewBag.TourNameOptions = tourList;
             // The initial TourDateOptions ddl fits the first tour already selected by user:
             string tourName = TourNameOptions;
             ViewBag.TourDateOptions = Lists.CreateTourDateList(tourName);
             //The tourDates dropdown list options change based on the tourName choice. This is done with AJAX via query using
             // a web service.
             ViewBag.UsernameOptions = Lists.CreateUserList();
             return View(reg);
         }
     }
     catch(Exception e)
     {
         TempData["CreateException"] = "Error in Reg creation: " + e.Message;
         return View(reg);
     }
 }
Ejemplo n.º 2
0
        public ActionResult RegForm(RegResponse rr, string id)
        {
            try
            {

                if (ModelState.IsValid)
                {
                    AReg reg = new AReg();
                    reg.TourID = id;
                    reg.TourDate = rr.EventInfo.TourDate;
                    reg.RegFirstName = rr.FirstName;
                    reg.RegLastName = rr.LastName;
                    reg.RegBirthday = rr.Birthday;
                    reg.UserID = rr.UserInfo.UserID;
                    reg.RegTime = DateTime.Now;
                    reg.WillAttend = rr.WillAttend;
                    BTourGuideOp tourOp = new BTourGuideOp();
                    tourOp.AddReg(reg);

                    // Send email to user:

                    // Email stuff
                    string subject = "Your registartion to the tour " + rr.EventInfo.TourName + " on " + rr.EventInfo.TourDate.ToString("dd-MM-yyyy");
                    string body = "Thank you for your registartion to the tour " + rr.EventInfo.TourName + " on " + rr.EventInfo.TourDate.ToString("dd-MM-yyyy") + "<br />" +
                                   "Registration name: " + rr.FirstName + " " + rr.LastName + "<br />" +
                                   "<a href='" + Url.Action("EventDetails", "Home", new { id = rr.EventInfo.TourID, date = rr.EventInfo.TourDate }, "http")
                                   + "'>Click here</a> to see the tour details." + "<br />" +
                                   "To see your user profile <a href='" + Url.Action("UserProfile", "Account", new { username = rr.UserInfo.Username }, "http")
                                   + "'>Click here</a>";

                    string from = "*****@*****.**";

                    MailMessage message = new MailMessage(from, rr.UserInfo.UserEmail);
                    message.Subject = subject;
                    message.Body = body;
                    message.IsBodyHtml = true;

                    SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
                    {
                        UseDefaultCredentials = false,
                        EnableSsl = true,
                        Timeout = 20000,
                        Credentials = new NetworkCredential("*****@*****.**", "henhqwcfvmtzplgb")

                    };

                    // Attempt to send the email
                    try
                    {
                        client.Send(message);

                        // Updating the IsSentEmail in the DB

                        tourOp.UpdateEmailSent(rr.UserInfo.UserID, rr.FirstName, rr.LastName, rr.EventInfo.TourID, rr.EventInfo.TourDate, true);
                        return View("ThankYou", rr);
                    }
                    catch (Exception e)
                    {
                        TempData["EmailException"] = "Issue sending email: " + e.Message;
                        return View(rr);
                    }
                }
                else
                    return View(rr);
            }
            catch(Exception e)
            {

                TempData["Exception"] = "" + e.Message;
                return View(rr);
            }
        }