コード例 #1
0
        public async Task <ActionResult> Index(string searchingString, int?page, bool?showInRegion, int?sorting)
        {
            User profile   = null;
            var  pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
            var  show      = showInRegion.HasValue ? Convert.ToBoolean(showInRegion) : false;

            if (User.Identity.IsAuthenticated)
            {
                profile = _userProxy.FindUser(User.Identity.GetUserId());
            }


            var allOffers = await _offerProxy.GetAllOffersAsync();

            var all = allOffers.Where(x => x.IsAvailable == true).ToArray();
            IEnumerable <Offer>           list       = null;
            IPagedList <ManageOfferModel> ipagedList = null;

            switch (sorting)
            {
            case 1:    //by highest price
                list = User.Identity.GetUserId() != null && show?
                       all.Where(x => _userProxy.FindUser(x.AuthorId).Region == profile.Region).OrderByDescending(x => x.RatePerHour) :
                           all.OrderByDescending(x => x.RatePerHour);

                break;

            case 2:
                list = User.Identity.GetUserId() != null && show?
                       all.Where(x => _userProxy.FindUser(x.AuthorId).Region == profile.Region).OrderBy(x => x.RatePerHour) :

                           all.OrderBy(x => x.RatePerHour);

                break;

            case 4:    //by date
                list = User.Identity.GetUserId() != null && show?
                       all.Where(x => _userProxy.FindUser(x.AuthorId).Region == profile.Region) :

                           all.Select(x => x);

                break;

            case 3:
                list = User.Identity.GetUserId() != null && show?
                       all.Where(x => _userProxy.FindUser(x.AuthorId).Region == profile.Region).OrderByDescending(x => x.Id) :

                           all.OrderByDescending(x => x.Id);

                break;

            default:
                list = User.Identity.GetUserId() != null && show?
                       all.Where(x => _userProxy.FindUser(x.AuthorId).Region == profile.Region).OrderByDescending(x => _offerProxy.GetAvgOfServiceRates(x.Id)
                                                                                                                  as IComparable).ThenBy(x => x.RatePerHour) :

                           all.OrderByDescending(x => _offerProxy.GetAvgOfServiceRates(x.Id) as IComparable).ThenBy(x => x.RatePerHour);

                break;
            }
            if (searchingString != null)
            {
                ipagedList = list.Where(x => x.Title.ToUpper().Contains(searchingString.ToUpper())).Select(x => _mapper.Map(x, new ManageOfferModel())).ToPagedList(pageIndex, 12);
            }
            else
            {
                ipagedList = list.Select(x => _mapper.Map(x, new ManageOfferModel())).ToPagedList(pageIndex, 12);
            }

            return(View("Index", ipagedList));
        }
コード例 #2
0
        public ActionResult PaymentWithPaypal(string Cancel = null)
        {
            //getting the apiContext
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Order/PaymentWithPayPal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution
                    var guid = Convert.ToString((new Random()).Next(100000));
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This function exectues after receving all parameters for the payment
                    var guid = Request.Params["guid"];

                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    //If executed payment failed then we will show payment failure message to user
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }

                    var user = _userProxy.FindUser(User.Identity.GetUserId());
                    _orderProxy.PayForOrder(_orderProxy.FindOrder(User.Identity.GetUserId()));
                    IList <string> listOfEmailsToSend = new List <string>();
                    var            shoppingCard       = _orderProxy.GetShoppingCart(User.Identity.GetUserId());
                    foreach (var item in shoppingCard.List)
                    {
                        listOfEmailsToSend.Add(_userProxy.FindUser(item.AuthorId).Email);
                    }
                    listOfEmailsToSend.Distinct();
                    foreach (var emailAddress in listOfEmailsToSend)
                    {
                        MailMessage mail = new MailMessage();
                        mail.From = new MailAddress(ConfigurationManager.AppSettings["Glogin"], "JobPortal");
                        mail.To.Add(new MailAddress(emailAddress, "Receiver"));
                        mail.Subject = "JobPortal";
                        mail.Body    = "Hey, someone bought your offer service, log in to our website and check " +
                                       "upcoming events or call the person the phone number is: " + user.PhoneNumber + "his full name is: " +
                                       user.FirstName + " " + user.LastName;
                        mail.Priority = MailPriority.Normal;
                        using (SmtpClient MailClient = new SmtpClient("smtp.gmail.com", 587))
                        {
                            MailClient.EnableSsl   = true;
                            MailClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Glogin"], ConfigurationManager.AppSettings["Gpassowrd"]);
                            MailClient.Send(mail);
                        }
                    }
                    CleanCart(User.Identity.GetUserId());
                    return(RedirectToAction("Index", "Order", new { id = User.Identity.GetUserId() }));
                }
            }
            catch (Exception ex)
            {
                return(View("FailureView"));
            }
        }