コード例 #1
0
ファイル: OpenIDProvider.cs プロジェクト: seanlinmt/tradelr
 public override user GetUserByProviderID(string providerID)
 {
     using (var db = new tradelrDataContext())
     {
         return(db.users.Where(x => x.openID == providerID).SingleOrDefault());
     }
 }
コード例 #2
0
 public baseCartController()
 {
     cart          = null;
     db            = new tradelrDataContext();
     repository    = new TradelrRepository(db);
     baseviewmodel = new BaseViewModel();
 }
コード例 #3
0
ファイル: baseController.cs プロジェクト: seanlinmt/tradelr
        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();
        }
コード例 #4
0
ファイル: ScheduledTask.cs プロジェクト: seanlinmt/tradelr
        public static void PollIndexingQueue()
        {
            var myLock = new object();

            lock (myLock)
            {
                using (var db = new tradelrDataContext())
                {
                    try
                    {
                        var queueItems = db.indexingQueues.Take(10);
                        foreach (var item in queueItems)
                        {
                            var action = item.ToModel();

                            if (LuceneUtil.Instance.ModifyIndex(action))
                            {
                                db.indexingQueues.DeleteOnSubmit(item);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Syslog.Write(ex);
                    }
                    finally
                    {
                        db.SubmitChanges();
                    }
                }
            }
        }
コード例 #5
0
        // creates a cart item when a pre buyer clicks on buy now link
        public ActionResult Index(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Redirect(GeneralConstants.HTTP_HOST));
            }

            long   variantid;
            string hostname;

            using (var db = new tradelrDataContext())
            {
                var digital = db.products_digitals.SingleOrDefault(x => x.linkid == id);
                if (digital == null)
                {
                    return(Redirect(GeneralConstants.HTTP_HOST));
                }

                hostname = digital.product.MASTERsubdomain.ToHostName();
                // check expiry
                if (digital.expiryDate.HasValue && DateTime.UtcNow > digital.expiryDate.Value)
                {
                    return(Redirect(hostname.ToDomainUrl()));
                }

                variantid = digital.product.product_variants.First().id;
            }

            return(Redirect(hostname.ToDomainUrl("/cart/add/" + variantid)));
        }
コード例 #6
0
ファイル: OpenIDProvider.cs プロジェクト: seanlinmt/tradelr
 public override bool DoesIDExist(string providerID)
 {
     using (var db = new tradelrDataContext())
     {
         var result = db.users.Where(x => x.openID == providerID).SingleOrDefault();
         return(result != null);
     }
 }
コード例 #7
0
 /*
  * public static long addTestMember()
  * {
  *
  *  using (var db = new tradelrDataContext())
  *  {
  *      user u = new user();
  *      u.fullName = "test test";
  *      u.role = (int)UserRole.ALL;
  *      u.created = DateTime.Now;
  *      u.lastLogin = DateTime.Now;
  *      db.users.InsertOnSubmit(u);
  *      db.SubmitChanges();
  *      return u.id;
  *  }
  *
  * }
  * */
 public static void deleteTestMember()
 {
     using (var db = new tradelrDataContext())
     {
         var result = db.users.Where(x => x.fullName == "test test").SingleOrDefault();
         if (result != null)
         {
             db.users.DeleteOnSubmit(result);
             db.SubmitChanges();
         }
     }
 }
コード例 #8
0
ファイル: Email.cs プロジェクト: seanlinmt/tradelr
        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
        {
            // get the identifier
            var token = (mail)e.UserState;

            if (e.Error != null)
            {
                Syslog.Write(e.Error);
                if (e.Error.GetType() != typeof(SmtpFailedRecipientException))
                {
                    // reinsert back into database
                    using (var db = new tradelrDataContext())
                    {
                        db.mails.InsertOnSubmit(token);
                        db.SubmitChanges();
                    }
                }
            }

            // update order status
            //ITradelrRepository repository = new TradelrRepository();
            //repository.UpdateOrderStatus(token.orderID, token.userID, OrderStatus.SENT);
        }
コード例 #9
0
 public myspaceController()
 {
     db = new tradelrDataContext();
 }
コード例 #10
0
 public EmailRepository()
 {
     db = new tradelrDataContext();
 }
コード例 #11
0
ファイル: liquidController.cs プロジェクト: seanlinmt/tradelr
        // handles liquid template assets
        public ActionResult Handler(string filename, string domainpath)
        {
            string uniqueid;

            if (domainpath == "facebook")
            {
                uniqueid = domainpath;
            }
            else
            {
                var pathparts = domainpath.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                uniqueid = pathparts[0];
            }

            // setup physical path first
            string liquidPhysicalPath;
            bool   isSVG = false;

            if (Request.RawUrl.IndexOf(".svg.png") != -1)
            {
                liquidPhysicalPath = Request.PhysicalPath.Replace(".png", ".liquid");
                isSVG = true;
            }
            else
            {
                liquidPhysicalPath = Request.PhysicalPath + ".liquid";
            }

            // cachekey = filename
            dynamic result;
            var     cachekey = ThemeHandler.GetCacheKey(uniqueid, filename, (bool)Session[BrowserCapability.IsMobileSession]);

            if (!CacheHelper.Instance.TryGetCache(CacheItemType.liquid_assets, cachekey, out result))
            {
                if (System.IO.File.Exists(liquidPhysicalPath))
                {
                    LiquidTemplateBase template;

                    var             accountHostname = Request.Headers["Host"];
                    MASTERsubdomain sd;
                    using (var db = new tradelrDataContext())
                    {
#if DEBUG
                        if (accountHostname.EndsWith("localhost"))
#else
                        if (accountHostname.EndsWith("tradelr.com"))
#endif
                        {
                            ////////////// handles case for subdomains
                            string[] host = accountHostname.Split('.');
                            // not on a subdomain

                            sd = db.GetSubDomain(host[0]);
                        }
                        else
                        {
                            ////////////////// handles case for custom subdomains
                            sd = db.GetCustomHostname(accountHostname);
                        }

                        template = new LiquidTemplateBase(sd,
                                                          (bool)Session[BrowserCapability.IsMobileSession]);

                        var parsed_string = template.ReadTemplateFile(liquidPhysicalPath);

                        template.InitContentTemplate(parsed_string);
                        template.AddParameters("shop", sd.ToLiquidModel());
                    }

                    var dirIndex = liquidPhysicalPath.LastIndexOf("\\");

                    // handle not found
                    var config_file = liquidPhysicalPath.Substring(0, dirIndex).Replace("assets", "config\\settings_data.json");
                    if (System.IO.File.Exists(config_file))
                    {
                        var current = template.ReadThemeSettings(config_file);
                        if (current != null)
                        {
                            template.AddParameters("settings", current);
                        }

                        if (isSVG)
                        {
                            // convert to png
                            using (var stream = template.RenderBasicToStreamNoHeader())
                            {
                                var svg = SvgDocument.Open(stream);
                                result = svg.Draw();
                            }
                        }
                        else
                        {
                            result = template.RenderBasicNoHeader();
                        }

                        CacheHelper.Instance.Insert(CacheItemType.liquid_assets, cachekey, result);
                        if (uniqueid != "facebook")
                        {
                            CacheHelper.Instance.add_dependency(DependencyType.liquid_assets, uniqueid, CacheItemType.liquid_assets, cachekey);
                        }
                    }
                }
            }

            if (Request.RawUrl.IndexOf(".css") != -1)
            {
                Response.ContentType = "text/css";
                return(Content(result));
            }

            if (Request.RawUrl.IndexOf(".js") != -1)
            {
                Response.ContentType = "application/x-javascript";
                return(Content(result));
            }

            if (isSVG)
            {
                return(new SvgToPngActionResult(result));
            }

            Syslog.Write(string.Format("Unknown filetype: {0}", Request.RawUrl));
            return(new EmptyResult());
        }
コード例 #12
0
ファイル: Email.cs プロジェクト: seanlinmt/tradelr
        /// <summary>
        ///
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="isAsync"></param>
        /// <param name="repository">if specified, email is queued</param>
        public static void SendMail(mail entry, bool isAsync, bool queueMail)
        {
            // need to check for invalid email address
            if (!entry.toEmail.IsEmail())
            {
                return;
            }

            if (queueMail)
            {
                // queue it instead
                using (var db = new tradelrDataContext())
                {
                    db.mails.InsertOnSubmit(entry);
                    db.SubmitChanges();
                }
                return;
            }

            var         from    = new MailAddress(MAIL_SOURCE_ADDRESS, "tradelr", Encoding.UTF8);
            MailAddress replyto = null;

            if (!string.IsNullOrEmpty(entry.fromEmail))
            {
                replyto = new MailAddress(entry.fromEmail, entry.fromName, Encoding.UTF8);
            }
            else
            {
                entry.fromEmail = MAIL_SOURCE_ADDRESS;
                entry.fromName  = "tradelr";
            }
            var to  = new MailAddress(entry.toEmail, entry.toName, Encoding.UTF8);
            var msg = new MailMessage(from, to)
            {
                Body            = entry.body,
                IsBodyHtml      = true,
                BodyEncoding    = Encoding.UTF8,
                Subject         = entry.subject,
                SubjectEncoding = Encoding.UTF8
            };

            if (replyto != null)
            {
                msg.ReplyToList.Add(replyto);
            }

#if DEBUG
            var smtp = new SmtpClient(MAIL_SERVER, 587)
            {
                EnableSsl = true
            };
            var cred = new NetworkCredential("*****@*****.**", MAIL_PASSWORD);
            //smtp.Timeout = 10000;
#else
            SmtpClient        smtp = new SmtpClient(MAIL_SERVER);
            NetworkCredential cred = new NetworkCredential(MAIL_SOURCE_ADDRESS, MAIL_PASSWORD);
#endif
            new Thread(() =>
            {
                smtp.Credentials = cred;
                if (isAsync)
                {
                    smtp.SendCompleted += SendCompletedCallback;
                    smtp.SendAsync(msg, entry);
                }
                else
                {
                    try
                    {
                        smtp.Send(msg);
                    }
                    catch (Exception ex)
                    {
                        Syslog.Write(ex);
                    }
                }
            }).Start();
        }
コード例 #13
0
ファイル: hi5Controller.cs プロジェクト: seanlinmt/tradelr
 public hi5Controller()
 {
     db = new tradelrDataContext();
 }
コード例 #14
0
 public friendsterController()
 {
     db = new tradelrDataContext();
 }
コード例 #15
0
        public EbayProductViewModel(ebay_product _ebayproduct, MASTERsubdomain sd, tradelrDataContext db)
        {
            categories     = new List <IEnumerable <SelectListItem> >();
            sitecategories = db.ebay_categories.Where(x => x.siteid == siteid.ToString());
            currency       = sd.currency.ToCurrency();

            if (_ebayproduct == null)
            {
                // new product
                this.ebayproduct = new ebay_product();
                siteid           = SiteCodeType.US;
                includeAddress   = true;
                quantity         = 1;
                conditions       = Enumerable.Empty <SelectListItem>();
                durations        = Enumerable.Empty <SelectListItem>();
                TypeList         = typeof(ListingType).ToSelectList(true, null, null, ListingType.FixedPriceItem.ToString());
            }
            else
            {
                // existing product
                ebayproduct    = _ebayproduct;
                siteid         = ebayproduct.siteid.ToEnum <SiteCodeType>();
                includeAddress = ebayproduct.includeAddress;
                isPosted       = true;
                isActive       = ebayproduct.isActive;
                quantity       = ebayproduct.quantity;

                var leafcategory = sitecategories.Single(x => x.categoryid == ebayproduct.categoryid);

                durations = leafcategory.ebay_listingdurations.Where(x => x.listingtypeid == ebayproduct.listingType)
                            .Select(x => new SelectListItem()
                {
                    Text = DurationNames.ContainsKey(x.duration)
                                                 ? DurationNames[x.duration]
                                                 : x.duration,
                    Value    = x.duration,
                    Selected = x.duration == ebayproduct.duration
                });
                conditions = leafcategory.ebay_conditions.Select(x => new SelectListItem()
                {
                    Text     = x.name,
                    Value    = x.value.ToString(),
                    Selected =
                        x.value == ebayproduct.condition
                });

                ListingID = ebayproduct.ebayid;

                // intervals
                if (ebayproduct.startTime.HasValue)
                {
                    StartDate = ebayproduct.startTime.Value.ToString(GeneralConstants.DATEFORMAT_INVOICE);
                }

                if (ebayproduct.endTime.HasValue)
                {
                    EndDate = ebayproduct.endTime.Value.ToString(GeneralConstants.DATEFORMAT_INVOICE);
                }

                // prices
                if (ebayproduct.startPrice.HasValue)
                {
                    StartPrice = ebayproduct.startPrice.Value.ToString("n" + currency.decimalCount);
                }
                if (ebayproduct.buynowPrice.HasValue)
                {
                    BuynowPrice = ebayproduct.buynowPrice.Value.ToString("n" + currency.decimalCount);
                }
                if (ebayproduct.reservePrice.HasValue)
                {
                    ReservePrice = ebayproduct.reservePrice.Value.ToString("n" + currency.decimalCount);
                }

                ViewLocation = ebayproduct.ToExternalLink();
                ListingFees  = ebayproduct.listingFees;

                TypeList = typeof(ListingType)
                           .ToSelectList(true, null, null,
                                         Listing.GetTradelrSupportedType(ebayproduct.listingType.ToEnum <ListingTypeCodeType>()).ToString());
            }

            dispatchTimes = db.ebay_dispatchtimes
                            .Where(x => x.siteid == siteid.ToString())
                            .OrderBy(x => x.dispatchTime)
                            .Select(x => new SelectListItem()
            {
                Text     = x.name,
                Value    = x.dispatchTime.ToString(),
                Selected = x.dispatchTime == ebayproduct.dispatchTime
            });

            shippingProfiles = sd.ebay_shippingprofiles
                               .Where(x => x.siteid == siteid.ToString())
                               .Select(x => new SelectListItem()
            {
                Text     = x.title,
                Value    = x.id.ToString(),
                Selected = x.id == ebayproduct.profileid
            });
        }
コード例 #16
0
ファイル: dController.cs プロジェクト: seanlinmt/tradelr
        // actual file download
        public ActionResult Index(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Redirect(GeneralConstants.HTTP_HOST));
            }

            string filename;
            string path;
            string contentType;

            using (var db = new tradelrDataContext())
            {
                var digitalOrder = db.orderItems_digitals.SingleOrDefault(x => x.downloadid == id);
                if (digitalOrder == null)
                {
                    return(Redirect(GeneralConstants.HTTP_HOST));
                }

                // check download limit
                var spec = digitalOrder.orderItem.product_variant.product.products_digitals;

                if (spec.limit.HasValue && spec.limit.Value <= digitalOrder.downloadCount)
                {
                    return(Redirect(digitalOrder.orderItem.product_variant.product.MASTERsubdomain.ToHostName().ToDomainUrl()));
                }

                // check expiry
                if (spec.expiryDate.HasValue && DateTime.UtcNow > spec.expiryDate.Value)
                {
                    return(Redirect(digitalOrder.orderItem.product_variant.product.MASTERsubdomain.ToHostName().ToDomainUrl()));
                }

                filename = spec.filename;
                path     = GeneralConstants.APP_ROOT_DIR + spec.filepath;

                if (!System.IO.File.Exists(path))
                {
                    return(Redirect(digitalOrder.orderItem.product_variant.product.MASTERsubdomain.ToHostName().ToDomainUrl()));
                }

                // no need to store cookie as user may use different device, makes it easier to define the term download limit
                digitalOrder.downloadCount++;

                db.SubmitChanges();
            }

            var buffer = new byte[256];
            var fs     = new FileStream(path, FileMode.Open);

            // try get mimetype
            if (fs.Length >= 256)
            {
                fs.Read(buffer, 0, 256);
            }
            else
            {
                fs.Read(buffer, 0, (int)fs.Length);
            }

            // reset to beginning of stream
            fs.Seek(0, SeekOrigin.Begin);

            try
            {
                UInt32 mimetype;
                FindMimeFromData(0, null, buffer, 256, null, 0, out mimetype, 0);
                var mimeTypePtr = new IntPtr(mimetype);
                contentType = Marshal.PtrToStringUni(mimeTypePtr);
                Marshal.FreeCoTaskMem(mimeTypePtr);
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                contentType = "unknown/unknown";
            }

            // return file
            return(File(fs, contentType, filename));
        }
コード例 #17
0
ファイル: LuceneWorker.cs プロジェクト: seanlinmt/tradelr
 public LuceneWorker(tradelrDataContext context, IdName subdomain)
 {
     repository     = new TradelrRepository(context);
     this.subdomain = subdomain;
 }
コード例 #18
0
        /// <summary>
        /// generates a thumbnail given the path of the original images
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="suffix"></param>
        /// <param name="desiredWidth"></param>
        /// <param name="desiredHeight"></param>
        /// <returns></returns>
        private static string thumbnail(string filePath, string suffix, float desiredWidth, float desiredHeight, Imgsize type)
        {
            string thumb = filePath;
            string file  = filePath;
            string ext   = thumb.Substring(thumb.LastIndexOf(".") + 1);

            thumb = thumb.Substring(0, thumb.LastIndexOf(".")) + "_" + suffix + "." + ext;
#if AZURE
            file  = file.Substring(file.LastIndexOf("/") + 1);
            thumb = thumb.Substring(thumb.LastIndexOf("/") + 1);
            bool exists = photoContainer.DoesBlobItemExists(file);
#else
            bool exists = File.Exists(GeneralConstants.APP_ROOT_DIR + file);
#endif
            if (!exists)
            {
                // delete from db
                new Thread(() =>
                {
                    Syslog.Write(String.Concat("Cannot find file: ", GeneralConstants.APP_ROOT_DIR + file));
                    using (var db = new tradelrDataContext())
                    {
                        var repository = new TradelrRepository(db);
                        repository.SetIsolationToNoLock();
                        repository.DeleteImage(file);
                    }
                }).Start();

                return("");
            }
            // These are the ratio calculations
#if AZURE
            Image img = Image.FromStream(photoContainer.GetBlobContentStream(file));
#else
            Image img = Image.FromFile(GeneralConstants.APP_ROOT_DIR + file);
#endif
            int width  = img.Width;
            int height = img.Height;

            img.Dispose();

            float factor = 0;
            if (width > 0 && height > 0)
            {
                float wfactor = desiredWidth / width;
                float hfactor = desiredHeight / height;
                factor = wfactor < hfactor ? wfactor : hfactor;
            }
            if (factor > 0)
            {
                int twidth  = Convert.ToInt32(Math.Floor(factor * width));
                int theight = Convert.ToInt32(Math.Floor(factor * height));
                convert(file, thumb, twidth, theight, type);
            }
            else
            {
#if AZURE
                photoContainer.DeleteBlobItem(thumb);
                photoContainer.CopyContent(file, thumb);
#else
                if (File.Exists(GeneralConstants.APP_ROOT_DIR + thumb))
                {
                    File.Delete(GeneralConstants.APP_ROOT_DIR + thumb);
                }
                File.Copy(GeneralConstants.APP_ROOT_DIR + file, GeneralConstants.APP_ROOT_DIR + thumb);
#endif
            }
            return(thumb);
        }
コード例 #19
0
        private void HandlePaymentMethods(bool safeTrader)
        {
            bool bankDeposit = false;
            bool creditCard  = false;
            bool cash        = false;
            var  others      = new List <string>();

            using (var db = new tradelrDataContext())
            {
                var methods = db.paymentMethods.Where(x => x.subdomainid == subdomainid);
                foreach (var entry in methods)
                {
                    switch (entry.method.ToEnum <PaymentMethod>())
                    {
                    case PaymentMethod.CashInPerson:
                        cash = true;
                        break;

                    case PaymentMethod.COD:
                        cash = true;
                        break;

                    case PaymentMethod.LoanCheck:
                        break;

                    case PaymentMethod.MoneyOrder:
                        break;

                    case PaymentMethod.Moneybookers:
                        break;

                    case PaymentMethod.BankTransfer:
                        bankDeposit = true;
                        break;

                    case PaymentMethod.Paypal:
                        others.Add("Paypal");
                        break;

                    case PaymentMethod.PayOnPickup:
                        break;

                    case PaymentMethod.PersonalCheck:
                        others.Add("Check");
                        break;

                    case PaymentMethod.Other:
                        if (entry.name.ToLower().IndexOf("credit card") != -1)
                        {
                            others.Add(entry.name);
                        }
                        else
                        {
                            creditCard = true;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            var results = new List <api.trademe.co.nz.v1.PaymentMethod>();

            if (bankDeposit)
            {
                results.Add(api.trademe.co.nz.v1.PaymentMethod.BankDeposit);
            }

            if (cash)
            {
                results.Add(api.trademe.co.nz.v1.PaymentMethod.Cash);
            }

            if (creditCard)
            {
                results.Add(api.trademe.co.nz.v1.PaymentMethod.CreditCard);
            }

            if (others.Count() != 0)
            {
                results.Add(api.trademe.co.nz.v1.PaymentMethod.Other);
                item.OtherPaymentMethod = string.Join(", ", others);
            }

            if (safeTrader)
            {
                results.Add(api.trademe.co.nz.v1.PaymentMethod.SafeTrader);
            }
            item.PaymentMethods = results.ToArray();
        }
コード例 #20
0
        public TrademeProductViewModel(trademe_product _trademeproduct, MASTERsubdomain sd, tradelrDataContext db)
        {
            categories     = new List <IEnumerable <SelectListItem> >();
            sitecategories = db.trademe_categories;
            currency       = sd.currency.ToCurrency();

            if (_trademeproduct == null)
            {
                // new product
                trademeproduct = new trademe_product();
                quantity       = 1;
                durations      = Enumerable.Empty <SelectListItem>();
                shippingCosts  = Enumerable.Empty <TrademeShippingCost>();
                freeShipping   = true;
            }
            else
            {
                // existing product
                trademeproduct     = _trademeproduct;
                isPosted           = true;
                isActive           = trademeproduct.isActive;
                isBrandNew         = trademeproduct.isnew;
                onlyAuthenticated  = trademeproduct.authenticatedOnly;
                isBold             = trademeproduct.isBold;
                isFeatured         = trademeproduct.isFeatured;
                isHomepageFeatured = trademeproduct.isHomepageFeatured;
                hasGallery         = trademeproduct.hasGallery;

                // shipping costs
                shippingCosts = trademeproduct.trademe_shippingcosts.ToModel();
                freeShipping  = !shippingCosts.Any();

                quantity = trademeproduct.quantity;

                var leafcategory = sitecategories.Single(x => x.id == trademeproduct.categoryid);

                durations = leafcategory.trademe_listingdurations.Where(x => x.categoryid == trademeproduct.categoryid)
                            .Select(x => new SelectListItem()
                {
                    Text     = x.duration == 1? (x.duration + " day"):(x.duration + " days"),
                    Value    = x.duration.ToString(),
                    Selected = x.duration == trademeproduct.duration
                });

                ListingID = trademeproduct.listingid;

                // intervals
                if (trademeproduct.startTime.HasValue)
                {
                    StartDate = trademeproduct.startTime.Value.ToString(GeneralConstants.DATEFORMAT_INVOICE);
                }

                if (trademeproduct.endTime.HasValue)
                {
                    EndDate = trademeproduct.endTime.Value.ToString(GeneralConstants.DATEFORMAT_INVOICE);
                }

                // prices
                StartPrice = trademeproduct.startPrice.ToString("n" + currency.decimalCount);

                if (trademeproduct.buynowPrice.HasValue)
                {
                    BuynowPrice = trademeproduct.buynowPrice.Value.ToString("n" + currency.decimalCount);
                }

                ReservePrice = trademeproduct.reservePrice.ToString("n" + currency.decimalCount);

                ViewLocation = trademeproduct.ToExternalLink();
                ListingFees  = trademeproduct.listingfees.HasValue? trademeproduct.listingfees.Value.ToString(): "";
            }
        }