Пример #1
0
        public async Task <Inbox> GetInboxByUserId(int id)
        {
            var inboxList = _context.InBox.ToList();
            var newInbox  = new Inbox();

            foreach (var inbox in inboxList)
            {
                if (inbox.UserId == id)
                {
                    newInbox = inbox;
                }
            }
            var advertisements = _advertisementRepository.GetAdsByUser(id).ToList();

            foreach (var advertisement in advertisements)
            {
                if (!advertisement.Expired && !advertisement.Deleted)
                {
                    var advertisementDate = Convert.ToDateTime(advertisement.PostedOn);
                    if ((DateTime.Now - advertisementDate).TotalDays >= advertisement.ExpiryDays)
                    {
                        newInbox.Expired     += 1;
                        advertisement.Expired = true;
                    }

                    _context.Entry(advertisement).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    _context.Entry(newInbox).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
            }

            return(newInbox);
        }
Пример #2
0
        public IEnumerable <AdTile> GetAdTiles(string basis, bool isTrue, int userid = 0)
        {
            var adTile         = new AdTile();
            var categories     = _categoryRepository.GetAll().ToList();
            var adTypes        = _adTypeRepository.GetAll().ToList();
            var attributes     = _attributeRepository.GetAll().ToList();
            var images         = _imageRepository.GetAll().ToList();
            var advertisements = userid != 0
                ? _advertisementRepository.GetAdsByUser(userid).ToList()
                : _advertisementRepository.GetAll().ToList();

            var adTiles  = new List <AdTile>();
            var totalAds = advertisements.Count();

            for (var index = 0; index < totalAds; index++)
            {
                if (userid != 0)
                {
                    switch (basis)
                    {
                    case "Deleted" when advertisements[index].Deleted != isTrue:
Пример #3
0
        public IEnumerable <AdTile> GetOfferedAdTiles(int userId)
        {
            var advertisements = _advertisementRepository.GetAdsByUser(userId).ToList();
            var categories     = _categoryRepository.GetAll().ToList();
            var attributes     = _attributeRepository.GetAll().ToList();
            var images         = _imageRepository.GetAll().ToList();
            var adTiles        = new List <AdTile>();
            var adTile         = new AdTile();
            var offeredAds     = new List <Offer>();

            foreach (var advertisement in advertisements.ToList())
            {
                if (advertisement.OfferCount > 0)
                {
                    var offers   = _context.Offer.ToList();
                    var newOffer = from offer in offers
                                   let userAd = _advertisementRepository.Get(offer.AdvertisementId)
                                                where userAd.UserId == userId
                                                select offer;
                    offeredAds.AddRange(newOffer);
                }
                else
                {
                    advertisements.Remove(advertisement);
                }
            }

            var totalOfferedAdsCount = offeredAds.Count;

            for (var index = 0; index < totalOfferedAdsCount; index++)
            {
                if (offeredAds[index].AdvertisementId == advertisements[index].Id)
                {
                    adTile.Price           = "Offered Amount : ₹ " + offeredAds[index].Price;
                    adTile.TimeStamp       = offeredAds[index].TimeStamp;
                    adTile.AdvertisementId = advertisements[index].Id;
                    adTile.OfferedBy       = offeredAds[index].UserId;
                }

                foreach (var category in categories)
                {
                    if (category.Id == advertisements[index].CategoryId)
                    {
                        adTile.Category = category.Name;
                        adTile.IconId   = category.Icon;
                        break;
                    }
                }

                foreach (var attribute in attributes)
                {
                    switch (attribute.Name)
                    {
                    case "Title" when attribute.AdvertisementId == adTile.AdvertisementId:
                        adTile.Title = attribute.Value;
                        break;
                    }
                }

                foreach (var image in images)
                {
                    if (image.AdvertisementId == adTile.AdvertisementId)
                    {
                        adTile.ImageUrl = image.Img;
                        break;
                    }
                }

                adTiles.Add(adTile);
            }

            return(adTiles);
        }