예제 #1
0
        public void GetListingsTest()
        {
            ManageController controller = new ManageController();

            var JSONListings = controller.GetListings();

            string stringListings = JsonConvert.SerializeObject(JSONListings.Data);

            List <ListingInfo> ListListings = JsonConvert.DeserializeObject <List <ListingInfo> >(stringListings);

            ListingInfo test = ListListings.Last();

            ListingModel listing = new ListingModel();

            listing.Title       = "Unit Test (Updated)";
            listing.StartDate   = new DateTime(2016, 3, 20, 12, 00, 00);
            listing.EndDate     = new DateTime(2016, 3, 21, 12, 00, 00);
            listing.Area        = "History";
            listing.Frequency   = "Always";
            listing.Description = "Unit testing... again!";
            listing.HangoutUrl  = "what.com";
            listing.TeacherId   = 5;
            listing.Open        = false;

            //Check that all listings were returned by checking for a specific listing
            Assert.IsTrue(listing.Title == test.Title &&
                          listing.StartDate == test.StartDate &&
                          listing.EndDate == test.EndDate &&
                          listing.Area == test.Area &&
                          listing.Frequency == test.Frequency &&
                          listing.Description == test.Description &&
                          listing.HangoutUrl == test.HangoutUrl &&
                          listing.TeacherId == test.TeacherId &&
                          listing.Open == test.Open);
        }
예제 #2
0
        public List <ListingInfo> GetListings()
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var listingModels           = db.ListingModels.ToList();
                List <ListingInfo> listings = new List <ListingInfo>();

                foreach (ListingModel listing in listingModels)
                {
                    var l = new ListingInfo();
                    l.Id           = listing.Id;
                    l.UrlId        = listing.UrlId;
                    l.Title        = listing.Title;
                    l.StartDate    = listing.StartDate;
                    l.EndDate      = listing.EndDate;
                    l.Area         = listing.Area;
                    l.AgeGroup     = listing.AgeGroup;
                    l.Frequency    = listing.Frequency;
                    l.Description  = listing.Description;
                    l.HangoutUrl   = listing.HangoutUrl;
                    l.HangoutStart = listing.HangoutStart;
                    l.TeacherId    = listing.TeacherId;
                    l.Open         = listing.Open;
                    l.Teacher      = l.GetTeacherUserName(listing);

                    listings.Add(l);
                }

                CheckForExpiredListings(listings);
                CheckForExpiredHangouts(listings);

                return(listings);
            }
        }
예제 #3
0
        public void UpdateListingTest()
        {
            ManageController controller   = new ManageController();
            ListingModel     listingModel = controller.ReturnLastAddedListing();
            ListingInfo      listing      = new ListingInfo();

            listing.Id          = listingModel.Id;
            listing.Title       = "Unit Test (Updated)";
            listing.StartDate   = listingModel.StartDate;
            listing.EndDate     = listingModel.EndDate;
            listing.Area        = listingModel.Area;
            listing.Frequency   = listingModel.Frequency;
            listing.Description = "Unit testing... again!";
            listing.HangoutUrl  = listingModel.HangoutUrl;
            listing.TeacherId   = listingModel.TeacherId;
            listing.Open        = listingModel.Open;
            listing.Teacher     = "*****@*****.**";

            //Check that the UpdateListing function completed successfully
            Assert.AreEqual(controller.UpdateListing(listing), "Listing Updated");

            //Check that the listing was actually updated in the database
            ListingModel lastAdded = controller.ReturnLastAddedListing();

            Assert.IsTrue(listing.Title == lastAdded.Title &&
                          listing.StartDate == lastAdded.StartDate &&
                          listing.EndDate == lastAdded.EndDate &&
                          listing.Area == lastAdded.Area &&
                          listing.Frequency == lastAdded.Frequency &&
                          listing.Description == lastAdded.Description &&
                          listing.HangoutUrl == lastAdded.HangoutUrl &&
                          listing.TeacherId == lastAdded.TeacherId &&
                          listing.Open == lastAdded.Open);
        }
예제 #4
0
        public MarketResponse GetMarketResponse(string item, int start, int amount)
        {
            string         marketUrl  = GetMarketUrl(item, start, amount);
            var            response   = HttpGet(marketUrl);
            dynamic        jsonObject = JsonConvert.DeserializeObject(response);
            MarketResponse mResp      = new MarketResponse();

            mResp.AmountTotal = jsonObject.total_count;
            mResp.Name        = item;
            mResp.Size        = jsonObject.pagesize;
            mResp.Start       = jsonObject.start;

            List <ListingInfo> listings = new List <ListingInfo>();
            var listingInfosJson        = jsonObject.listinginfo;

            foreach (var listingInfoJson in listingInfosJson)
            {
                ListingInfo newListing = new ListingInfo();
                newListing.Name        = item;
                newListing.ListingId   = listingInfoJson.Name;
                newListing.InternalId  = listingInfoJson.Value.asset.id;
                newListing.InspectLink = listingInfoJson.Value.asset.market_actions[0].link;
                newListing.SubTotal    = listingInfoJson.Value.converted_price - listingInfoJson.Value.converted_fee;

                listings.Add(newListing);
            }
            mResp.Listings = listings;
            return(mResp);
        }
예제 #5
0
        public List <ListingInfo> GetListingsByCurrentUser(string userName)
        {
            var currentUserName         = userName;
            List <ListingInfo> listings = new List <ListingInfo>();
            var userInDatabase          = false;

            //Check if the current user is in the database
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                userInDatabase = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault() != null;
            }

            if (userInDatabase)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    //Get the current user from the database
                    var iMentorUser = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault();

                    //Get current users assigned listings
                    var assignments = db.AssignedListings.Where(x => x.UserId == iMentorUser.Id);

                    //Get listings base on the assignments
                    var assidnedListings = new List <ListingModel>();
                    foreach (AssignedListing assignment in assignments)
                    {
                        assidnedListings.Add(db.ListingModels.Where(x => x.Id == assignment.ListingId).FirstOrDefault());
                    }



                    foreach (ListingModel listing in assidnedListings)
                    {
                        var l = new ListingInfo();
                        l.Id           = listing.Id;
                        l.UrlId        = listing.UrlId;
                        l.Title        = listing.Title;
                        l.StartDate    = listing.StartDate;
                        l.EndDate      = listing.EndDate;
                        l.Area         = listing.Area;
                        l.AgeGroup     = listing.AgeGroup;
                        l.Frequency    = listing.Frequency;
                        l.Description  = listing.Description;
                        l.HangoutUrl   = listing.HangoutUrl;
                        l.HangoutStart = listing.HangoutStart;
                        l.TeacherId    = listing.TeacherId;
                        l.Open         = listing.Open;
                        l.Teacher      = l.GetTeacherUserName(listing);

                        listings.Add(l);
                    }

                    CheckForExpiredListings(listings);
                }
            }

            return(listings);
        }
예제 #6
0
        private bool IncludeInResults(ListingInfo info, string itemNumber)
        {
            if (string.Equals(itemNumber, NormalizeNumber(info.number), StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            var channelNumber = info.channelNumber.ToString(CultureInfo.InvariantCulture);

            if (info.subChannelNumber > 0)
            {
                channelNumber += "." + info.subChannelNumber.ToString(CultureInfo.InvariantCulture);
            }

            return(string.Equals(channelNumber, itemNumber, StringComparison.OrdinalIgnoreCase));
        }
예제 #7
0
 public void BuyIfLowerThan(ListingInfo listing, float wear)
 {
     Bot.RequestFloat(listing.InspectLink, v =>
     {
         ReplyReceived = true;
         if (v <= wear)
         {
             Bot.BuyMarketItem(listing);
             SendChatMessage("Bought listing " + listing.InternalId + ", Float: " + v);
             Log.Success("Bought listing " + listing.InternalId + ", Float: " + v);
         }
         else
         {
             Log.Warn("Didn't buy " + listing.Name + ", Float too high: " + v);
         }
     });
 }
예제 #8
0
        public void GetListingInfo(bool live, string id, out ListingInfo info)
        {
            ApiContext apiContext = GetApiContext(live);

            var getItem = new GetItemCall(apiContext);
            getItem.ItemID = id;
            try
            {
                getItem.Execute();
            }
            catch (Exception ex)
            {
                info = new ListingInfo();
                info.CurrentStatus = EbayStatus.Unlisted;
                return;
            }
            info = new ListingInfo();

            info.ViewUrl = getItem.ApiResponse.Item.ListingDetails.ViewItemURL;
            switch (getItem.ApiResponse.Item.SellingStatus.ListingStatus)
            {
                case ListingStatusCodeType.Active:
                    info.CurrentStatus = EbayStatus.InProgressBuyItNow;
                    break;
                case ListingStatusCodeType.Ended:
                    info.CurrentStatus = EbayStatus.Unsold;
                    break;
                case ListingStatusCodeType.Completed:
                    if (getItem.ApiResponse.Item.SellingStatus.QuantitySold > 0)
                    {
                        info.CurrentStatus = EbayStatus.Sold;
                        info.SoldPrice = getItem.ApiResponse.Item.SellingStatus.CurrentPrice.Value;
                    }
                    else
                    {
                        info.CurrentStatus = EbayStatus.Unsold;
                    }
                    break;
            }
        }
예제 #9
0
        public string UpdateListing(ListingInfo listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    int no = Convert.ToInt32(listing.Id);
                    var l  = db.ListingModels.Where(x => x.Id == no).FirstOrDefault();

                    if (l != null)
                    {
                        l.Title        = listing.Title;
                        l.UrlId        = listing.UrlId;
                        l.StartDate    = listing.StartDate;
                        l.EndDate      = listing.EndDate;
                        l.Area         = listing.Area;
                        l.AgeGroup     = listing.AgeGroup;
                        l.Frequency    = listing.Frequency;
                        l.Description  = listing.Description;
                        l.HangoutUrl   = listing.HangoutUrl;
                        l.HangoutStart = listing.HangoutStart;
                        l.TeacherId    = listing.TeacherId;
                        l.Open         = listing.Open;
                        db.SaveChanges();
                        return("Listing Updated");
                    }
                    else
                    {
                        return("Invalid Listing");
                    }
                }
            }
            else
            {
                return("Invalid Listing");
            }
        }
예제 #10
0
        public static StagingEbayItem SearchItemToStgEbayItem(SearchItem ebayItem)
        {
            StagingEbayItem stgItem = new StagingEbayItem();

            //Condition
            if (ebayItem.condition != null && ebayItem.condition.conditionIdSpecified)
            {
                stgItem.Condition = ebayItem.condition.conditionDisplayName;
            }
            stgItem.CountryCode = ebayItem.country;
            stgItem.GalleryURL  = ebayItem.galleryURL;
            stgItem.GlobalId    = ebayItem.globalId;
            stgItem.ItemId      = ebayItem.itemId;
            //Listing Information
            if (ebayItem.listingInfo != null)
            {
                ListingInfo listingInfo = ebayItem.listingInfo;
                if (listingInfo.buyItNowAvailableSpecified)
                {
                    stgItem.ListingInfoBuyItNowAvailable = listingInfo.buyItNowAvailable;
                    if (listingInfo.buyItNowPrice != null)
                    {
                        stgItem.ListingInfoBuyItNowPrice = Convert.ToDecimal(listingInfo.buyItNowPrice.Value);
                    }
                }
                else
                {
                    stgItem.ListingInfoBuyItNowAvailable = false;
                }
                if (listingInfo.endTimeSpecified)
                {
                    stgItem.ListingInfoEndTime = listingInfo.endTime;
                }
                if (listingInfo.giftSpecified)
                {
                    stgItem.ListingInfoGift = listingInfo.gift;
                }
                stgItem.ListingInfoListingType = listingInfo.listingType;
                if (listingInfo.startTimeSpecified)
                {
                    stgItem.ListingInfoStartTime = listingInfo.startTime;
                }
            }
            if (ebayItem.primaryCategory != null)
            {
                stgItem.PrimaryCategory = ebayItem.primaryCategory.categoryName;
            }
            if (ebayItem.productId != null)
            {
                stgItem.ProducitId = ebayItem.productId.Value;
            }
            if (ebayItem.secondaryCategory != null)
            {
                stgItem.SecondaryCategory = ebayItem.secondaryCategory.categoryName;
            }
            if (ebayItem.sellerInfo != null)
            {
                stgItem.SellerInfoTopRatedSeller = ebayItem.sellerInfo.topRatedSellerSpecified &&
                                                   ebayItem.sellerInfo.topRatedSeller;
            }
            //Selling Status
            if (ebayItem.sellingStatus != null)
            {
                SellingStatus sellingStatus = ebayItem.sellingStatus;
                if (sellingStatus.bidCountSpecified)
                {
                    stgItem.SellingStatusBidCount = sellingStatus.bidCount;
                }
                if (sellingStatus.currentPrice != null)
                {
                    stgItem.SellingStatusCurrentPrice = Convert.ToDecimal(sellingStatus.currentPrice.Value);
                }
                stgItem.SellingStatusSellingState = sellingStatus.sellingState;
                stgItem.SellingStatusTimeLeft     = sellingStatus.timeLeft;
            }
            //Store Info
            if (ebayItem.storeInfo != null)
            {
                Storefront storefront = ebayItem.storeInfo;
                stgItem.StoreInfoStoreName = storefront.storeName;
                stgItem.StoreInfoStoreURL  = storefront.storeURL;
            }
            stgItem.SubTitle    = ebayItem.subtitle;
            stgItem.Title       = ebayItem.title;
            stgItem.ViewItemUrl = ebayItem.viewItemURL;

            return(stgItem);
        }
예제 #11
0
 public string UpdateListing(ListingInfo listing)
 {
     return(listingService.UpdateListing(listing));
 }
예제 #12
0
        private ProgramInfo GetProgramInfo(ListingInfo info)
        {
            var showType = info.showType ?? string.Empty;

            var program = new ProgramInfo
            {
                Id          = info.listingID.ToString(CultureInfo.InvariantCulture),
                Name        = GetStringValue(info.showName),
                HomePageUrl = GetStringValue(info.webLink),
                Overview    = info.description,
                IsHD        = info.hd,
                IsLive      = info.live,
                IsPremiere  = info.seasonPremiere || info.seriesPremiere,
                IsMovie     = showType.IndexOf("Movie", StringComparison.OrdinalIgnoreCase) != -1,
                IsKids      = showType.IndexOf("Children", StringComparison.OrdinalIgnoreCase) != -1,
                IsNews      = showType.IndexOf("News", StringComparison.OrdinalIgnoreCase) != -1,
                IsSports    = showType.IndexOf("Sports", StringComparison.OrdinalIgnoreCase) != -1
            };

            if (!string.IsNullOrWhiteSpace(info.listDateTime))
            {
                program.StartDate = DateTime.ParseExact(info.listDateTime, "yyyy'-'MM'-'dd' 'HH':'mm':'ss", CultureInfo.InvariantCulture);
                program.StartDate = DateTime.SpecifyKind(program.StartDate, DateTimeKind.Utc);
                program.EndDate   = program.StartDate.AddMinutes(info.duration);
            }

            if (info.starRating > 0)
            {
                program.CommunityRating = info.starRating * 2;
            }

            if (!string.IsNullOrWhiteSpace(info.rating))
            {
                // They don't have dashes so try to normalize
                program.OfficialRating = info.rating.Replace("TV", "TV-").Replace("--", "-");

                var invalid = new[] { "N/A", "Approved", "Not Rated" };
                if (invalid.Contains(program.OfficialRating, StringComparer.OrdinalIgnoreCase))
                {
                    program.OfficialRating = null;
                }
            }

            if (!string.IsNullOrWhiteSpace(info.year))
            {
                program.ProductionYear = int.Parse(info.year, CultureInfo.InvariantCulture);
            }

            if (info.showID > 0)
            {
                program.ShowId = info.showID.ToString(CultureInfo.InvariantCulture);
            }

            if (info.seriesID > 0)
            {
                program.SeriesId = info.seriesID.ToString(CultureInfo.InvariantCulture);
                program.IsSeries = true;
                program.IsRepeat = info.repeat;

                program.EpisodeTitle = GetStringValue(info.episodeTitle);

                if (string.Equals(program.Name, program.EpisodeTitle, StringComparison.OrdinalIgnoreCase))
                {
                    program.EpisodeTitle = null;
                }
            }

            if (info.starRating > 0)
            {
                program.CommunityRating = info.starRating * 2;
            }

            if (string.Equals(info.showName, "Movie", StringComparison.OrdinalIgnoreCase))
            {
                // Sometimes the movie title will be in here
                if (!string.IsNullOrWhiteSpace(info.episodeTitle))
                {
                    program.Name = info.episodeTitle;
                }
            }

            return(program);
        }