コード例 #1
0
        public TradeView Convert(Trade trade, string lang)
        {
            SkuView   relatedSku = new SkuViewController().Get(trade.SkuGuid, lang);
            OrderView orderView  = new OrderViewController().Get(trade.OrderGuid, lang);

            return(new TradeView
            {
                Guid = trade.Guid,
                TradeCode = trade.TradeCode,
                BuyerGuid = trade.BuyerGuid,
                BuyerUserName = trade.BuyerUserName,
                BuyerLanguageCode = trade.BuyerLanguageCode,
                BuyerPhoneNumber = trade.BuyerPhoneNumber,
                SellerGuid = trade.SellerGuid,
                SellerLanguageCode = trade.SellerLanguageCode,
                SellerUserName = trade.SellerUserName,
                SellerPhoneNumber = trade.SellerPhoneNumber,
                Created = trade.Created,
                Currency = trade.Currency,
                OrderGuid = trade.OrderGuid,
                ProductColourGuid = orderView.ProductColourGuid,
                ProductColourName = orderView.ProductColourName,
                ProductCondition = orderView.ProductCondition,
                ProductConditionName = orderView.ProductConditionName,
                Price = trade.Price,
                LastModified = trade.LastModified,
                Status = trade.Status,
                Quantity = trade.Quantity,
                SkuGuid = trade.SkuGuid,
                SkuFullName = relatedSku.FullName,
                Total = trade.Total
            });
        }
コード例 #2
0
        public IEnumerable <TradeView> Get(string lang = "en-US")
        {
            Account account = AccountController.GetAccountByUsername(User.Identity.Name);

            using (DatabaseContext context = Util.CreateContext())
            {
                List <Trade> trades = (from t in context.Trades.AsNoTracking()
                                       where !t.IsDeleted &&
                                       (t.BuyerGuid == account.Guid || t.SellerGuid == account.Guid)
                                       select t).ToList();

                List <SkuView>     allSkus     = new SkuViewController().GetList(lang: lang, showInactive: true).ToList();
                List <AccountInfo> allAccounts = new AccountController().GetAccounts().ToList();


                var result = trades.ConvertAll((trade) =>
                {
                    return(Convert(trade, lang));
                });
                return(result);
            }
        }
コード例 #3
0
        public IEnumerable <OrderView> Get(string accountGuid = "", string skuId = "", string orderId = "", string type = "", string query = "", string categories = "", string manufacturers = "", string lang = "en-US", bool showExpired = false, bool showSoldOut = false, bool showCancelled = false)
        {
            using (DatabaseContext context = Util.CreateContext())
            {
                var activeAccounts   = new AccountController().GetAccounts().ToList();
                var relevantSkuViews = new SkuViewController().GetList(query, categories, manufacturers, skuId, true, lang).ToList();


                var orders = (from o in context.Orders.AsNoTracking()
                              select o).ToList();

                //only show orders which match sku filters

                var relevantSkuGuids = relevantSkuViews.ConvertAll(s => s.Guid);
                orders = orders.Where(o => relevantSkuGuids.Contains(o.SkuGuid)).ToList();

                //store filter
                if (!String.IsNullOrEmpty(accountGuid))
                {
                    orders = orders.Where(o =>
                    {
                        return(o.CreatedByAccountGuid == new Guid(accountGuid));
                    }).ToList();
                }

                if (!String.IsNullOrEmpty(type))
                {
                    orders = orders.Where(o => o.Type == type).ToList();
                }

                if (!String.IsNullOrEmpty(skuId))
                {
                    orders = orders.Where(o => o.SkuGuid == new Guid(skuId)).ToList();
                }

                if (!String.IsNullOrEmpty(orderId))
                {
                    orders = orders.Where(o => o.Guid == new Guid(orderId)).ToList();
                }

                if (!showExpired)
                {
                    orders = orders.Where(o => o.ValidTo > DateTime.UtcNow).ToList();
                }

                if (!showSoldOut)
                {
                    orders = (from order in orders
                              where activeAccounts.Any(a => a.Guid == order.CreatedByAccountGuid) &&
                              order.Quantity > 0
                              select order).ToList();
                }

                if (!showCancelled)
                {
                    orders = (from order in orders
                              where !order.IsCancelled
                              select order).ToList();
                }

                var webUrl  = ConfigurationManager.AppSettings["WebUrl"];
                var baseUrl = ConfigurationManager.AppSettings["BaseUrl"];

                var marketLocations   = new MarketLocationController().Get(lang).ToList();
                var productConditions = new ProductConditionController().Get(lang).ToList();
                var productColours    = (from c in context.ProductColours.AsNoTracking()
                                         select c).ToList();

                var orderViews = orders.ConvertAll(o =>
                {
                    var sku            = relevantSkuViews.Where(s => s.Guid == o.SkuGuid).FirstOrDefault();
                    var account        = activeAccounts.Where(a => a.Guid == o.CreatedByAccountGuid).FirstOrDefault();
                    var marketLocation = marketLocations.Where(l => l.Key == o.Location).FirstOrDefault();
                    var isActive       = DateTime.UtcNow > o.ValidFrom &&
                                         DateTime.UtcNow < o.ValidTo &&
                                         o.Quantity > 0 &&
                                         !o.IsCancelled;
                    var status    = o.IsCancelled ? "Cancelled" : o.Quantity == 0 ? "Sold out" : DateTime.UtcNow > o.ValidTo ? "Expired" : "Active";
                    var viewCount = (from c in context.ViewCounts
                                     where c.Guid == o.Guid
                                     select c).FirstOrDefault();

                    var productCondition = productConditions.Where(c => c.Key == o.ProductCondition).FirstOrDefault();
                    var productColour    = (from c in productColours
                                            where c.Guid == o.ProductColourGuid
                                            select c).FirstOrDefault();
                    var imageGuids = JsonConvert.DeserializeObject <Guid[]>(o.ImageGuids).ToList();
                    var imageUrls  = imageGuids.ConvertAll(guid => String.Format("{0}/v1/image/{1}", baseUrl, guid));

                    var orderView = new OrderView
                    {
                        Price                = o.Price,
                        Currency             = o.Currency,
                        Quantity             = o.Quantity,
                        QuantityInitial      = o.QuantityInitial,
                        MinimumOrder         = o.MinimumOrder,
                        IsExclusive          = o.IsExclusive,
                        Guid                 = o.Guid,
                        SkuGuid              = o.SkuGuid,
                        CreatedByAccountGuid = o.CreatedByAccountGuid,
                        AccountUserName      = account.Username,
                        AccountPhone         = account.Phone,
                        Location             = marketLocation.Key,
                        LocationName         = marketLocation.Name,
                        ProductColourGuid    = o.ProductColourGuid,
                        ProductColourName    = TranslationInfo.ExtractTranslation(productColour.NameTranslations, lang),
                        ProductColourValue   = productColour.Value,
                        ProductCondition     = o.ProductCondition,
                        ProductConditionName = productCondition.Name,
                        Type                 = o.Type,
                        Created              = DateTime.SpecifyKind(o.Created, DateTimeKind.Utc),
                        ValidFrom            = DateTime.SpecifyKind(o.ValidFrom, DateTimeKind.Utc),
                        ValidTo              = DateTime.SpecifyKind(o.ValidTo, DateTimeKind.Utc),
                        SkuName              = sku.SkuName,
                        SkuFullName          = sku.FullName,
                        CategoryGuid         = sku.CategoryGuid,
                        CategoryName         = sku.CategoryName,
                        ManufacturerGuid     = sku.ManufacturerGuid,
                        ManufacturerName     = sku.ManufacturerName,
                        ProductGuid          = sku.ProductGuid,
                        ProductName          = sku.ProductName,
                        LastModified         = DateTime.SpecifyKind(o.LastModified, DateTimeKind.Utc),
                        ImageSrc             = sku.ImageSrc,
                        Description          = o.Description,
                        IsActive             = isActive,
                        Status               = status,
                        Url       = String.Format("{0}/{1}/order/{2}", webUrl, lang, o.Guid),
                        ViewCount = viewCount != null ? viewCount.Count : 0,
                        ImageUrls = imageUrls.ToArray()
                    };

                    return(orderView);
                });
                return(orderViews);
            }
        }
コード例 #4
0
        public TradeOfferView Get(Guid tradeOfferGuid, string lang = "en-US")
        {
            //you can only view if you are the to party
            Account account = AccountController.GetAccountByUsername(User.Identity.Name);

            using (DatabaseContext context = new DatabaseContext())
            {
                var offer = (from o in context.TradeOffers
                             where o.Guid == tradeOfferGuid
                             select o).FirstOrDefault();

                if (offer == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }

                if (offer.ToAccountGuid != account.Guid &&
                    offer.FromAccountGuid != account.Guid)
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }

                OrderView orderView  = new OrderViewController().Get(offer.OrderGuid, lang);
                SkuView   relatedSku = new SkuViewController().Get(orderView.SkuGuid, lang);
                Account   from       = (from a in context.Accounts
                                        where a.Guid == offer.FromAccountGuid
                                        select a).First();

                Account to = (from a in context.Accounts
                              where a.Guid == offer.ToAccountGuid
                              select a).First();

                TradeOfferView converted = new TradeOfferView
                {
                    Guid                 = offer.Guid,
                    Created              = offer.Created,
                    Currency             = offer.Currency,
                    FromAccountGuid      = offer.FromAccountGuid,
                    LastModified         = offer.LastModified,
                    OrderGuid            = offer.OrderGuid,
                    Price                = offer.Price,
                    ProductColourGuid    = orderView.ProductColourGuid,
                    ProductColourName    = orderView.ProductColourName,
                    ProductCondition     = orderView.ProductCondition,
                    ProductConditionName = orderView.ProductConditionName,
                    Location             = orderView.Location,
                    LocationName         = orderView.LocationName,
                    Quantity             = offer.Quantity,
                    SkuGuid              = orderView.SkuGuid,
                    SkuImageUrl          = orderView.ImageSrc,
                    SkuFullName          = orderView.SkuFullName,
                    Total                = offer.Quantity * offer.Price,
                    TradeCode            = offer.TradeCode,
                    Type                 = orderView.Type,
                    FromUserName         = from.Username,
                    ToAccountGuid        = offer.ToAccountGuid,
                    ToUserName           = to.Username,
                    CancelReason         = offer.CancelReason,
                    Status               = GetStatus(offer),
                    Deadline             = offer.Deadline
                };

                return(converted);
            }
        }