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 bool AddReg(AReg reg)
 {
     using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext())
     {
         Registration registration = new Registration();
         registration.IsSentEmail = 0;
         registration.IsPaid = 0;
         registration.Attended = 0;
         registration.RegFirstName = reg.RegFirstName;
         registration.RegLastName = reg.RegLastName;
         registration.RegBirthday = reg.RegBirthday;
         registration.TourDate = reg.TourDate;
         registration.TourID = System.Guid.Parse(reg.TourID);
         registration.UserID = System.Guid.Parse(reg.UserID);
         registration.RegTime = DateTime.Now;
         registration.WillAttend = (byte)(reg.WillAttend?1:0);
         registration.RegID = System.Guid.NewGuid();
         dc.Registrations.InsertOnSubmit(registration);
         dc.SubmitChanges();
         return true;
     }
 }
Ejemplo n.º 3
0
 public ActionResult Delete(string id, AReg reg)
 {
     try
     {
         BTourGuideOp tourOp = new BTourGuideOp();
         tourOp.DeleteReg(id);
         return RedirectToAction("Index");
     }
     catch(Exception e)
     {
         TempData["DeleteException"] = "Error in Reg deletion: " + e.Message;
         return View();
     }
 }
Ejemplo n.º 4
0
 public ActionResult Edit(string id, AReg reg)
 {
     try
     {
         if (ModelState.IsValid)
         {
             BTourGuideOp tourOp = new BTourGuideOp();
             reg.RegID = id;
             tourOp.EditReg(reg);
             return RedirectToAction("Index");
         }
         else
             return View(reg);
     }
     catch(Exception e)
     {
         TempData["EditException"] = "Error in Reg edit: " + e.Message;
         return View(reg);
     }
 }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public bool EditReg(AReg reg)
        {
            using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext())
            {

                Registration row = (from c in dc.Registrations
                             where (c.RegID.ToString() == reg.RegID)
                             select c).FirstOrDefault<Registration>();
                row.IsSentEmail = (byte)(reg.IsSentEmail?1:0);
                row.IsPaid = (byte)(reg.IsPaid?1:0);
                row.Attended = (byte)(reg.Attended?1:0);
                row.RegFirstName = reg.RegFirstName;
                row.RegLastName = reg.RegLastName;
                row.RegBirthday = reg.RegBirthday;
                row.WillAttend = (byte)(reg.WillAttend?1:0);
                dc.SubmitChanges();
                return true;
            }
        }
Ejemplo n.º 7
0
 public bool EditEvent(AEvent tourEvent)
 {
     using (DataClassesTourGuideDataContext dc = new DataClassesTourGuideDataContext())
     {
     if (tourEvent.TourDate == tourEvent.TourOriginalDate) // The TourDate is not changed - save the other changes
     {
             Event row = (from c in dc.Events
                          where (c.TourID.ToString() == tourEvent.TourID && c.TourDate == tourEvent.TourDate)
                          select c).FirstOrDefault<Event>();
             row.TourGuide = tourEvent.TourGuide;
         row.IsOn = (byte)(tourEvent.IsOn?1:0);
             dc.SubmitChanges();
             return true;
     }
     else // The TourDate has been changed - delete the event and create a new one with the new date. Copy the registrations with the new date
     {
             AddEvent(tourEvent); // Adding the new event (the same event with the new date)
             // Adding new registrations to the new event (with the new date)
             List<Registration> registrations = (from r in dc.Registrations
                                                 where (r.TourID.ToString() == tourEvent.TourID && r.TourDate == tourEvent.TourOriginalDate)
                                                 select r).ToList();
             foreach (Registration reg in registrations)
             {
                 AReg newReg = new AReg();
                 newReg.IsSentEmail = reg.IsSentEmail==1?true:false;
                 newReg.IsPaid = reg.IsPaid==1?true:false;
                 newReg.Attended = reg.Attended==1?true:false;
                 newReg.RegFirstName = reg.RegFirstName;
                 newReg.RegLastName = reg.RegLastName;
                 newReg.RegBirthday = reg.RegBirthday;
                 newReg.TourDate = tourEvent.TourDate;
                 newReg.TourID = tourEvent.TourID;
                 newReg.UserID = reg.UserID.ToString();
                 newReg.WillAttend = reg.WillAttend==1?true:false;
                 AddReg(newReg);
             }
             DeleteEvent(tourEvent.TourID, tourEvent.TourOriginalDate); // this function also deletes the previous date regisrations
             dc.SubmitChanges();
             return true;
       }
     }
 }