Пример #1
0
        private const int COOKIE_LIFETIME_MIN = 1200; // 20 mins

        #endif

        protected baseController()
        {
            db = new tradelrDataContext();
            repository = new TradelrRepository(db);
            permission = UserPermission.NONE;
            baseviewmodel = new BaseViewModel();
        }
Пример #2
0
 // used for updates to existing order
 public Transaction(order o, ITradelrRepository repository, long?sessionid)
     : this(o.user1.organisation1.MASTERsubdomain, o.user, o.type.ToEnum <TransactionType>(), repository, sessionid.HasValue?sessionid.Value:o.owner)
 {
     order    = o;
     currency = o.currency.ToCurrency();
     original = o.ToModel(transactionType, sessionid.HasValue ? sessionid.Value : o.owner);
 }
Пример #3
0
 public baseCartController()
 {
     cart          = null;
     db            = new tradelrDataContext();
     repository    = new TradelrRepository(db);
     baseviewmodel = new BaseViewModel();
 }
Пример #4
0
        public void InitGalleryView(facebookPage fbpage, ITradelrRepository repository, bool liked)
        {
            hostname   = string.Format("{0}.{1}", fbpage.MASTERsubdomain.name, GeneralConstants.SUBDOMAIN_HOST);
            viewAllUrl = hostname.ToDomainUrl();
#if DEBUG
            canvasStoreUrl = string.Format("http://apps.facebook.com/tradelrtest/store/{0}", fbpage.MASTERsubdomain.name);
#else
            canvasStoreUrl = string.Format("http://apps.facebook.com/tradelr/store/{0}", fbpage.MASTERsubdomain.name);
#endif
            categories = repository.GetProductCategories(null, fbpage.subdomainid)
                         .Select(
                x =>
                new SelectListItem()
            {
                Text = x.MASTERproductCategory.name, Value = x.id.ToString()
            });
            if ((fbpage.MASTERsubdomain.flags & (int)SubdomainFlags.STORE_ENABLED) != 0)
            {
                products = repository.GetProducts(fbpage.subdomainid)
                           .IsActive()
                           .OrderByDescending(x => x.id)
                           .Take(21)
                           .ToFacebookModel(hostname);
            }

            // handle coupon message
            if (fbpage.MASTERsubdomain.facebookCoupon.HasValue)
            {
                if (liked)
                {
                    var    coupon   = fbpage.MASTERsubdomain.coupon;
                    var    currency = fbpage.MASTERsubdomain.currency.ToCurrency();
                    string description;
                    string minimumPurchase = " on all purchases.";
                    if (coupon.minimumPurchase.HasValue)
                    {
                        minimumPurchase = string.Format(" with a minimum purchase of {0}{1}.", currency.code,
                                                        coupon.minimumPurchase.Value.ToString("n" +
                                                                                              currency.decimalCount));
                    }
                    if (coupon.couponPercentage.HasValue)
                    {
                        description = string.Format("{0}% discount", coupon.couponPercentage.Value.ToString("n2"));
                    }
                    else
                    {
                        description = string.Format("{0}{1} off", currency.code,
                                                    coupon.couponValue.Value.ToString("n" + currency.decimalCount));
                    }
                    couponMessage = string.Format(
                        "<p><strong>Discount code:</strong> {0}</p><p>{1}{2}</p>", coupon.code, description,
                        minimumPurchase);
                }
                else
                {
                    couponMessage = string.Format("<p class='strong'><img src='{0}/Content/img/arrow_up.png' /> Click on the like button above to view the latest discount code.</p>",
                                                  GeneralConstants.FACEBOOK_HOST);
                }
            }
        }
Пример #5
0
        public void InitSalesAndProductsStatistics(ITradelrRepository repository, long subdomainid, long viewerid,
                                                   MASTERsubdomain sd)
        {
            var date     = DateTime.UtcNow;
            var currency = sd.currency.ToCurrency();
            // sales stats
            var invoices       = repository.GetOrders(subdomainid, TransactionType.INVOICE, viewerid, null, null, null, false);
            var invoices_month = invoices.Where(x => x.created.Month == date.Month);
            var invoices_year  = invoices.Where(x => x.created.Year == date.Year);

            numberOfSalesThisMonth       = invoices_month.Count();
            numberOfSalesThisYear        = invoices_year.Count();
            numberofSalesUnpaidThisMonth =
                invoices_month.Where(x => x.totalPaid != x.total + (x.shippingCost ?? 0)).Count();
            numberofSalesUnpaidThisYear = invoices_year.Where(x => x.totalPaid != x.total + (x.shippingCost ?? 0)).Count();
            salesThisMonth = string.Concat(currency.symbol,
                                           invoices_month.ToArray().Sum(x => x.total).ToString("n" + currency.decimalCount));
            salesThisYear = string.Concat(currency.symbol,
                                          invoices_year.ToArray().Sum(x => x.total).ToString("n" + currency.decimalCount));
            salesUnpaidThisMonth = string.Concat(currency.symbol,
                                                 invoices_month.Where(
                                                     x => x.totalPaid != x.total + (x.shippingCost ?? 0)).ToArray().Sum(
                                                     x => x.total + (x.shippingCost ?? 0) - x.totalPaid).ToString(
                                                     "n" + currency.decimalCount));
            salesUnpaidThisYear = string.Concat(currency.symbol,
                                                invoices_year.Where(
                                                    x => x.totalPaid != x.total + (x.shippingCost ?? 0)).ToArray().Sum(
                                                    x => x.total + (x.shippingCost ?? 0) - x.totalPaid).ToString(
                                                    "n" + currency.decimalCount));

            // product stats
            productTotal    = sd.total_products_mine;
            outOfStockTotal = sd.total_outofstock;
        }
Пример #6
0
        // for fb
        public Account(ITradelrRepository repository, string email, string loginPage, AccountPlanType plan, string affiliate)
        {
            this.repository = repository;
            this.email      = email;
            this.loginPage  = loginPage;
            this.plan       = plan;
            this.affiliate  = affiliate;

            // create subdomain entry
            mastersubdomain = new MASTERsubdomain
            {
                flags                   = 0,
                name                    = loginPage,
                total_outofstock        = 0,
                total_contacts_public   = 0,
                total_contacts_private  = 0,
                total_contacts_staff    = 0,
                total_invoices_sent     = 0,
                total_invoices_received = 0,
                total_orders_sent       = 0,
                total_orders_received   = 0,
                total_products_mine     = 0,
                uniqueid                = Utility.GetRandomString(10),
                accountType             = plan.ToString(),
                accountTypeStatus       = (int)AccountPlanPaymentStatus.TRIAL,                 // start date for 30-day trial campaign
                trialExpiry             = DateTime.UtcNow.AddDays(30),
                affiliateID             = AffiliateUtil.GenerateAffiliateID()
            };
        }
Пример #7
0
        public ErrorData SendMessage(Controller controller, ITradelrRepository repository, EmailViewType emailtype,
                                     object viewData, string subject, string viewloc = "", MessageType msgtype = MessageType.EMAIL)
        {
            // save notification types
            switch (msgtype)
            {
            case MessageType.LINKREQUEST:
                var message = new DBML.message
                {
                    sender           = sender.id,
                    recipient        = recipientid,
                    title            = subject,
                    body             = "",
                    readStatus       = false,
                    senderDeleted    = false,
                    recipientDeleted = false,
                    created          = DateTime.UtcNow,
                    type             = MessageType.LINKREQUEST.ToString()
                };
                repository.AddMessage(message);
                break;

            default:
                break;
            }

            ////// send message
            var error = new ErrorData();

            if (controller != null)
            {
                body = controller.RenderViewToString(emailtype.ToDescriptionString(), viewData);
            }
            else
            {
                throw new NotImplementedException();
            }

            // wrap body with div to format it
            body = string.Concat("<div style=\"font: 12.5px/20px arial, sans-serif;\"", body, "</div>");

            // subject may contain HTML tags
            subject = subject.StripHtmlTags();

            switch (transportType)
            {
            case TransportType.EMAIL:
                Email.Email.SendMail(recipientname, destEmail, subject, body, sender, true);
                break;

            case TransportType.FACEBOOK:
                Syslog.Write("fbuser no email");
                error.success = false;
                error.message = "Facebook contact did not grant email permission";
                break;
            }
            return(error);
        }
Пример #8
0
 public void PopulateContactGroups(ITradelrRepository repository, long subdomainid)
 {
     contactGroups =
         repository.GetContactGroups(subdomainid).Select(
             x => new SelectListItem {
         Text = x.title, Value = x.id.ToString()
     }).
         ToFilterList();
 }
Пример #9
0
 public FacebookWorker(ITradelrRepository repository, long ownerid, long subdomainid)
 {
     session = new ConnectSession(GeneralConstants.FACEBOOK_API_KEY,
                                  GeneralConstants.FACEBOOK_API_SECRET);
     api = new Api(session);
     this.subdomainid = subdomainid;
     this.repository  = repository;
     this.ownerid     = ownerid;
 }
Пример #10
0
 public PaypalWorker(string uniqueid, Transaction o,
                     ITradelrRepository repo,
                     string paypalEmail,
                     int?currencyid,
                     string returnUrl)
 {
     this.uniqueid             = uniqueid;
     this.transaction          = o;
     this.repository           = repo;
     this.currency             = currencyid.ToCurrency();
     this.PaymentReceiverEmail = paypalEmail;
     this.returnUrl            = returnUrl;
 }
Пример #11
0
        private static void EbayPollForOrders(ITradelrRepository repository)
        {
            var tokens =
                repository.GetSubDomains().SelectMany(x => x.oauth_tokens).Where(
                    y => y.type == OAuthTokenType.EBAY.ToString() && y.authorised);

            foreach (var token in tokens)
            {
                var worker = new EbayWorker(token.MASTERsubdomain, token.token_key);
                worker.PollForEbayOrders();

                token.MASTERsubdomain.ebay_lastsync = DateTime.UtcNow;
            }
        }
Пример #12
0
        public GoogleBlogExporter(string sessionKey, string hostName, ITradelrRepository repository, long sesssionid)
        {
            var authFactory = new GAuthSubRequestFactory("blogger", "tradelr")
            {
                Token = sessionKey
            };

            service = new Service(authFactory.ApplicationName)
            {
                RequestFactory = authFactory
            };
            this.hostName   = hostName;
            this.repository = repository;
            this.ownerid    = sesssionid;

            blogEntry = new AtomEntry();
        }
Пример #13
0
        private static bool ShipwirePollForShippedStatus(ITradelrRepository repository)
        {
            bool changed = false;
            var  orders  =
                repository.GetOrders().Where(
                    x =>
                    x.shipwireTransaction != null && x.shipwireTransaction.state == ShipwireState.ORDER_SUBMITTED.ToString());

            foreach (var entry in orders)
            {
                var transaction = new Transaction(entry, repository, null);
                if (transaction.GetReceiver() == null)
                {
                    continue;
                }

                var shipwire = transaction.GetShipWireService();
                if (shipwire == null)
                {
                    continue;
                }

                var transactionid = transaction.GetShipwireTransactionID();
                shipwire.CreateTrackingUpdate(transactionid);
                var resp = shipwire.SubmitTrackingUpdate();
                if (resp == null)
                {
                    continue;
                }
                // try get matching order
                var responseOrder = resp.Orders.Where(x => x.id == transactionid).SingleOrDefault();
                if (responseOrder != null)
                {
                    if (responseOrder.shipped)
                    {
                        transaction.UpdateShipwireState(ShipwireState.ORDER_SHIPPED);

                        // add comment
                        string comment = string.Format(OrderComment.ORDER_SHIP_DETAILED, responseOrder.shipperFullName, responseOrder.TrackingNumber.Value, responseOrder.TrackingNumber.href);
                        transaction.AddComment(comment);

                        transaction.SaveUpdatedTransaction();

                        changed = true;

                        // notify buyer that order has been shipped
                        var subdomain = transaction.GetOwner().organisation1.MASTERsubdomain;
                        repository.AddActivity(transaction.GetReceiver().id,
                                               new ActivityMessage(transaction.GetID(), transaction.GetOwner().id,
                                                                   ActivityMessageType.ORDER_SHIPPED,
                                                                   new HtmlLink(transaction.GetOrderNumber(), transaction.GetID()).ToTransactionString(transaction.GetType())), subdomain.id);

                        var viewloc = subdomain.ToHostName().ToDomainUrl(transaction.GetOrderLink());

                        // notify buyer that order has been shipped
                        var emailContent = new OrderShippedEmailContent
                        {
                            orderNumber     = transaction.GetOrderNumber(),
                            shippingAddress = transaction.GetShippingAddress().ToHtmlString(),
                            sender          = transaction.GetOwner().ToEmailName(false),
                            viewloc         = viewloc
                        };

                        string subject    = "Invoice #" + emailContent.orderNumber + " has shipped";
                        var    msg        = new Models.message.Message(transaction.GetReceiver(), transaction.GetOwner(), subdomain.id);
                        var    controller = new dummyController();
                        msg.SendMessage(controller, repository, EmailViewType.ORDER_SHIPPED, emailContent, subject, viewloc);
                    }
                    else
                    {
                        Syslog.Write("Shipwire order not shipped {0} : {1}",
                                     transaction.GetShipwireTransactionID(),
                                     shipwire.GetXmlResponse());
                    }
                }
                else
                {
                    transaction.UpdateShipwireState(ShipwireState.ORDER_NOTFOUND);
                    transaction.SaveUpdatedTransaction();
                    changed = true;
                    Syslog.Write("Cannot find order for {0} : {1}",
                                 transaction.GetShipwireTransactionID(),
                                 shipwire.GetXmlResponse());
                }
            }
            return(changed);
        }
Пример #14
0
 public Products()
 {
     repository = new TradelrRepository();
 }
Пример #15
0
 public AddressHandler(organisation o, ITradelrRepository repository)
 {
     this.repository = repository;
     target_org      = o;
 }
Пример #16
0
 public registration()
 {
     repository = new TradelrRepository();
 }
Пример #17
0
 public ShoppingCart(string currencycode)
 {
     this.currencyCode = currencycode;
     repository        = new TradelrRepository(new tradelrDataContext());
     items             = new List <CheckoutItem>();
 }
Пример #18
0
        public static void UpdateOrderTotal(this order o, long subdomainid, int currency_decimalplaces, string couponCode, ITradelrRepository repository)
        {
            // we need to update invoice total
            decimal total = 0;

            foreach (var orderItem in o.orderItems)
            {
                if (orderItem.unitPrice.HasValue)
                {
                    var subtotal = orderItem.quantity * orderItem.unitPrice.Value;
                    if (orderItem.tax.HasValue)
                    {
                        subtotal = (1 + orderItem.tax.Value / 100) * subtotal;
                    }
                    total += subtotal;
                }
            }

            o.total = total;

            // apply any discount
            if (!string.IsNullOrEmpty(couponCode))
            {
                var coupon =
                    repository.GetCoupons(subdomainid)
                    .SingleOrDefault(x => x.code == couponCode && !x.expired);
                if (coupon != null)
                {
                    if (!coupon.minimumPurchase.HasValue ||
                        (total >= coupon.minimumPurchase.Value))
                    {
                        o.discountPercentage = coupon.couponPercentage;
                        o.discountValue      = coupon.couponValue;
                        o.discountCouponCode = coupon.code;
                    }
                    coupon.impressions++;
                }
            }

            if (o.discountPercentage.HasValue)
            {
                o.total = o.total * (1 - o.discountPercentage.Value / 100);
            }
            else if (o.discountValue.HasValue)
            {
                o.total = Math.Max(0, o.total - o.discountValue.Value);
            }

            // shipping cost not included in discount
            if (o.shippingCost.HasValue)
            {
                o.total = total + o.shippingCost.Value;
            }

            // add any tax
            if (o.taxAmount.HasValue)
            {
                o.total += o.taxAmount.Value;
            }

            // round it to the proper currency
            o.total = Math.Round(o.total, currency_decimalplaces);
        }
Пример #19
0
 public AddressHandler(order o, ITradelrRepository repository)
 {
     this.repository = repository;
     target_order    = o;
 }
Пример #20
0
        private static bool PaypalHandleBuyerPaidAndWeNeedToVerify(ITradelrRepository repository)
        {
            bool haveChanges             = false;
            var  paymentsNeededVerifying = repository.GetPayments(PaymentMethodType.Paypal, PaymentStatus.Charging);

            foreach (var payment in paymentsNeededVerifying)
            {
                var configurationMap = Configuration.GetAcctAndConfig();

                var service = new AdaptivePaymentsService(configurationMap);

                var detailsRequest = new PaymentDetailsRequest
                {
                    payKey          = payment.redirectUrl.ToPayPalPayKey(),
                    requestEnvelope = new RequestEnvelope
                    {
                        errorLanguage
                            =
                                "en_US"
                    },
                    trackingId = payment.reference
                };

                PaymentDetailsResponse resp = null;
                bool haveError = false;
                try
                {
                    resp = service.PaymentDetails(detailsRequest);
                }
                catch (Exception ex)
                {
                    var affectedInvoice = payment.order;
                    Syslog.Write(
                        string.Format(
                            "Failed to process payment for order {0}, payment amount of {1} deleted",
                            affectedInvoice.id, payment.paidAmount));
                    Syslog.Write(ex);
                    haveError = true;
                }
                if (!haveError && resp.responseEnvelope.ack == AckCode.SUCCESS)
                {
                    var transaction = new Transaction(payment.order, repository, null);

                    switch (resp.status)
                    {
                    case "COMPLETED":
                        transaction.UpdatePaymentStatus(payment, PaymentStatus.Accepted);

                        transaction.AddPaidAmount(payment.paidAmount);          // <------- order status is updated inside here

                        // send download links if digital order
                        if (transaction.HasDigitalOrderItems())
                        {
                            transaction.SendDownloadLinksEmail();
                        }
                        haveChanges = true;
                        break;

                    case "ERROR":
                        transaction.UpdatePaymentStatus(payment, PaymentStatus.Declined);

                        haveChanges = true;
                        break;

                    case "EXPIRED":
                        repository.DeletePayment(payment);
                        haveChanges = true;
                        break;
                    }
                }
            }
            return(haveChanges);
        }
Пример #21
0
 // used for creation
 public Transaction(MASTERsubdomain senderDomain, user to, TransactionType transactionType, ITradelrRepository repository, long sessionid)
 {
     this.senderDomain    = senderDomain;
     receiver             = to;
     this.repository      = repository;
     this.transactionType = transactionType;
     caller_sessionid     = sessionid;
 }
Пример #22
0
 public fbappController()
 {
     repository = new TradelrRepository();
 }
Пример #23
0
 // for email
 public Account(ITradelrRepository repository, string email, string password, string passwordConfirm, string loginPage, AccountPlanType plan, string affiliate)
     : this(repository, email, loginPage, plan, affiliate)
 {
     this.password        = password;
     this.passwordConfirm = passwordConfirm;
 }
Пример #24
0
 public LuceneWorker(ITradelrRepository repo, IdName subdomain)
 {
     repository     = repo;
     this.subdomain = subdomain;
 }
Пример #25
0
 public LuceneWorker(tradelrDataContext context, IdName subdomain)
 {
     repository     = new TradelrRepository(context);
     this.subdomain = subdomain;
 }