Пример #1
0
        public ActionResult CreateFromServiceId(StudentWidget studentwidget)
        {
            var widget = new StudentWidget();

            try{
                using (var svc = new WebserviceFundAFSerSoapClient())
                {
                    XElement studentAccount = svc.AFSWidgetGetProgramDetails("afserwidget", "globalwidgerasfer2012",
                                                                             studentwidget.ServiceId.ToString());

                    Guid serviceId;
                    DateTime endDate;

                    if (studentAccount.Descendants("GLMessage").First().Value.Equals("Success"))
                    {
                        bool isValidAcct = Guid.TryParse(studentAccount.Descendants("Service_ID").First().Value, out serviceId);
                        if (!isValidAcct)
                        {
                            TempData["WSError"] = "Not a valid Service Id.";
                            return RedirectToAction("Index");
                        }
                        widget.ServiceId = Guid.Parse(studentAccount.Descendants("Service_ID").First().Value);
                        widget.FirstName = studentAccount.Descendants("First_Name").First().Value;
                        widget.LastName = studentAccount.Descendants("Last_Name").First().Value;
                        widget.State = studentAccount.Descendants("State").First().Value;
                        widget.ProgramRefCode = studentAccount.Descendants("Program_Code").First().Value;
                        widget.DestinationCountry = studentAccount.Descendants("Hosting_Country").First().Value;
                        widget.Srn = studentAccount.Descendants("Service_Ref").First().Value;
                        widget.AreaTeam = studentAccount.Descendants("Area_Team_Name").First().Value;
                        widget.State = studentAccount.Descendants("State").First().Value;
                        widget.EnabledStatus = 1;
                        widget.DisplayName = widget.FirstName + ' ' + widget.LastName;
                        widget.EndDate = DateTime.TryParse(studentAccount.Descendants("Widget_End_Date").First().Value, out endDate) ? endDate : DateTime.Now.AddMonths(3);
                        widget.FundraisingAmount = decimal.Parse(studentAccount.Descendants("Widget_Amount").First().Value);

                        return View(widget);
                    }
                    //If we get here and didn't hit the View or an Error, then it is a bad Id.

                }
            }
            catch(Exception e)
            {
                TempData["WSError"] = "Error in Global Link response: " + e.Message;
            }

            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult Create(StudentWidget studentwidget)
        {
            if (ModelState.IsValid)
            {
                studentwidget.StudentWidgetId = Guid.NewGuid();
                _db.StudentWidgets.Add(studentwidget);
                using (var svc = new WebserviceFundAFSerSoapClient())
                {
                    var reply = svc.AFSWidgetSetCode("afserwidget", "globalwidgerasfer2012",
                                         studentwidget.ServiceId.ToString(),
                                         studentwidget.StudentWidgetId.ToString(),
                                         "http://donatew.afsusa.org/SponsorAnAFSer/Widget/Details/" + studentwidget.StudentWidgetId.ToString(),
                                         studentwidget.EndDate.ToString());
                }
                _db.SaveChanges();
                return RedirectToAction("Index");
            }

            return RedirectToAction("Index");
        }
Пример #3
0
        public ActionResult Index(Donation donation)
        {
            var request = new AuthorizationRequest(donation.CardNumber, donation.ExpMonth + donation.ExpYear, donation.Amount,
                "Sponsor an AFSer");

            request.AddCustomer("", donation.FirstName, donation.LastName, donation.Address, donation.State,
                                donation.Zip);

            request.City = donation.City;
            request.Email = donation.Email;

            using (var context = new AFSAdminContext())
            {
                var widget = context.StudentWidgets.Find(donation.StudentWidget_StudentWidgetId);
                request.ShipToFirstName = widget.FirstName;
                request.ShipToLastName = widget.LastName;
            }

            //step 2 - create the gateway, sending in your credentials
            //var gate = new Gateway("6zz6m5N4Et", "9V9wUv6Yd92t27t5", true);
            var gate = new Gateway("7f5SDz7huZ", "8A44F37ee89KqBDz", false);

            //step 3 - make some money
            var response = gate.Send(request);

            if (response.Approved)
            {
                donation.TransactionId = response.TransactionID;
                using (var context = new AFSAdminContext())
                {
                    var widget = context.StudentWidgets.Find(donation.StudentWidget_StudentWidgetId);
                    donation.DonationId = Guid.NewGuid();
                    donation.StudentWidget = widget;
                    donation.DateOfTransaction = DateTime.Now;
                    donation.StudentWidget.AmountRaised += donation.Amount;
                    context.Donations.Add(donation);
                    context.SaveChanges();

                }

                using (var svc = new WebserviceFundAFSerSoapClient())
                {
                    XElement rsp = svc.AFSWidgetPaymentDetails("afserwidget", "globalwidgerasfer2012"
                                                                    , donation.StudentWidget.ServiceId.ToString()
                                                                    , donation.StudentWidget.StudentWidgetId.ToString()
                                                                    , donation.TransactionId
                                                                    , donation.DonationId.ToString()
                                                                    , donation.FirstName
                                                                    , donation.LastName
                                                                    , donation.Address
                                                                    , donation.City
                                                                    , donation.State
                                                                    , donation.Zip
                                                                    , donation.Email
                                                                    , donation.Amount.ToString()
                                                                    , donation.Message);
                    TempData["WSResponse"] = rsp;
                }

                TempData["Email"] = donation.Email;
                TempData["Name"] = donation.StudentWidget.FirstName;
                TempData["Amount"] = donation.Amount;
                return RedirectToAction("Reciept");
            }

            using (var context = new AFSAdminContext())
            {
                var widget = context.StudentWidgets.Find(donation.StudentWidget_StudentWidgetId);
                donation.StudentWidget = widget;
                ViewBag.WidgetName = widget.FirstName;
            }
            ViewBag.ErrorMsg = "Error code: " + response.ResponseCode + " Message: " + response.Message;
            return View(donation);
        }