Ejemplo n.º 1
0
 public List<Category> GetAllCategories()
 {
     using (var domain = new CraigslistDomain())
     {
         return domain.Categories.ToList();
     }
 }
Ejemplo n.º 2
0
 public void PublishListing(Listing listing)
 {
     using (var domain = new CraigslistDomain())
     {
         domain.Listings.Add(listing);
         domain.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public List<Listing> GetListingsByCategory(string category)
 {
     using (var domain = new CraigslistDomain())
     {
         return domain
             .Listings
             .Where(listing => category == null || listing.Category.Name == category)
             .ToList();
     }
 }
Ejemplo n.º 4
0
 public Listing GetListingsByRemovalGuid(string removalId)
 {
     using (var domain = new CraigslistDomain())
     {
         return domain
             .Listings
             .Include(listing => listing.Contact)
             .Include(listing => listing.Category)
             .FirstOrDefault(listing => listing.RemovalGuid == removalId && listing.IsActive);
     }
 }
Ejemplo n.º 5
0
 public Listing GetListingsById(long listingId)
 {
     using (var domain = new CraigslistDomain())
     {
         return domain
             .Listings
             .Include(listing => listing.Contact)
             .Include(listing => listing.Category)
             .FirstOrDefault(listing => listing.Id == listingId && listing.IsActive);
     }
 }
Ejemplo n.º 6
0
        public List<Category> GetAllCategories()
        {
            using (var domain = new CraigslistDomain())
            {
                var categories = domain.Categories.ToList();

                foreach (var category in categories)
                {
                    category.SubCategories = categories.Where(cat => cat.ParentId == category.Id).ToList();
                }

                return categories;
            }
        }
Ejemplo n.º 7
0
 public IPagedList<Listing> GetListingsByCategoryIdAndSearchQuery(int? page, long? categoryId, string q)
 {
     using (var domain = new CraigslistDomain())
     {
         int pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);
         int pageNumber = (page ?? 1);
         return domain
             .Listings
             .Include(l => l.Category)
             .Include("Category.ParentCategory")
             .Include(l => l.Contact)
             .Where(listing => listing.IsActive && (categoryId == null || listing.CategoryId == categoryId) && (q == null || listing.Header.Contains(q)))
             .OrderByDescending(l => l.Created)
             .ToPagedList(pageNumber, pageSize);
     }
 }
Ejemplo n.º 8
0
        public void DeactivateListingByRemovalId(string removalId)
        {
            using (var domain = new CraigslistDomain())
            {
                var listingToDeactivate = domain
                    .Listings
                    .FirstOrDefault(listing => listing.RemovalGuid == removalId);

                if (listingToDeactivate != null)
                {
                    listingToDeactivate.IsActive = false;
                    listingToDeactivate.Updated = DateTime.Now;
                    domain.SaveChanges();
                }
            }
        }
Ejemplo n.º 9
0
        public void UpdateListing(Listing listing)
        {
            using (var domain = new CraigslistDomain())
            {
                var currentLising = domain.Listings.FirstOrDefault(l => l.Id == listing.Id);
                currentLising.Header = listing.Header;
                currentLising.Body = listing.Body;
                currentLising.CategoryId = listing.CategoryId;
                currentLising.FeaturedImageData = listing.FeaturedImageData;
                currentLising.FeaturedImageMimeType = listing.FeaturedImageMimeType;
                currentLising.Price = listing.Price;

                currentLising.Contact.FirstName = listing.Contact.FirstName;
                currentLising.Contact.LastName = listing.Contact.LastName;
                currentLising.Contact.Phone = listing.Contact.Phone;
                currentLising.Contact.Email = listing.Contact.Email;
                domain.SaveChanges();
            }
        }