public long?AddImage(long productId, long imageStoreId) { var entities = GeneralService.GetDbEntities(); var product = GeneralService.GetDbEntities().Products.Where(p => p.ID == productId).FirstOrDefault(); if (product == null) { return(null); } if (!product.PrimaryImageStoreID.HasValue || product.PrimaryImageStoreID.Value == 0) { product.PrimaryImageStoreID = imageStoreId; } var productImage = entities.ProductImages.Add(new ProductImage { ProductID = productId, ImageStoreID = imageStoreId }); entities.SaveChanges(); if (productImage != null) { return(productImage.ID); } return(null); }
public long?CreateOffer(long id, decimal price, long customerId) { var entities = GeneralService.GetDbEntities(); Product product = entities.Products.FirstOrDefault(p => p.ID == id); if (product == null) { return(null); } product.OfferPrice = price; TransactionLine transaction = new TransactionLine { ProductID = id, CategoryID = product.CategoryID, CustomerID = customerId, SellerID = product.CustomerID, OfferPrice = price, TransactionType = TransactionTypes.Offer, CreatedDate = DateTime.Now, }; entities.TransactionLines.Add(transaction); entities.SaveChanges(); return(transaction.ID); }
public ProductViewModel Add(ProductViewModel viewModel) { var entities = GeneralService.GetDbEntities(); Product product = entities.Products.Add(viewModel.ToEntity()); entities.SaveChanges(); viewModel.ID = product.ID; return(viewModel); }
public ImageStoreViewModel Get(long id) { var imageStore = GeneralService.GetDbEntities().ImageStores.Where(i => i.ID == id).FirstOrDefault(); if (imageStore == null) { return(null); } return(new ImageStoreViewModel(imageStore)); }
public ProductViewModel Get(long id) { var product = GeneralService.GetDbEntities().Products.Where(p => p.ID == id).FirstOrDefault(); if (product == null) { return(null); } return(new ProductViewModel(product)); }
public CustomerViewModel Get(long id) { var customer = GeneralService.GetDbEntities().Customers.Where(c => c.ID == id).FirstOrDefault(); if (customer == null) { return(null); } return(new CustomerViewModel(customer)); }
public IQueryable <ZipCode> GetZipCodesInRange(float latitude, float longitude, float radiusInMiles = 5) { float tolerance = 0.08f * 5; // 0.08 lat/lon units approximately equals 5 miles DesiOfferEntities entities = GeneralService.GetDbEntities(); return(entities.ZipCodes.Where(z => ((z.Lat > latitude && (z.Lat - latitude) <= tolerance) || (z.Lat <= latitude && (latitude - z.Lat) <= tolerance)) && ((z.Long > longitude && (z.Long - longitude) <= tolerance) || (z.Long <= longitude && (longitude - z.Long) <= tolerance)) ) .AsQueryable()); }
public IEnumerable <ProductViewModel> ListRecent(int limit = 50) { DesiOfferEntities entities = GeneralService.GetDbEntities(); List <ProductViewModel> viewModels = new List <ProductViewModel>(); foreach (Product product in entities.Products.Take(limit)) { viewModels.Add(new ProductViewModel(product)); } return(viewModels); }
public TransactionModel GetLeadingOffer(long productId) { var entities = GeneralService.GetDbEntities(); TransactionLine transaction = entities.TransactionLines.Where(t => t.ProductID == productId).OrderByDescending(p => p.OfferPrice).FirstOrDefault(); if (transaction == null) { return(null); } return(new TransactionModel(transaction)); }
public IEnumerable <CategoryViewModel> ListCategories() { var entities = GeneralService.GetDbEntities(); List <CategoryViewModel> viewModels = new List <CategoryViewModel>(); foreach (Category category in entities.Categories) { viewModels.Add(new CategoryViewModel(category)); } return(viewModels); }
public IEnumerable <CustomerViewModel> ListInZipCodes(List <string> zipCodes) { DesiOfferEntities entities = GeneralService.GetDbEntities(); var query = entities.Customers.Where(c => zipCodes.Contains(c.ZipCode)); List <CustomerViewModel> customers = new List <CustomerViewModel>(); foreach (Customer customer in query) { customers.Add(new CustomerViewModel(customer)); } return(customers); }
public IEnumerable <TransactionViewModel> ListTransactions(long customerId) { var entities = GeneralService.GetDbEntities(); List <TransactionViewModel> transactionViewModels = new List <TransactionViewModel>(); var transactions = entities.TransactionLines.Where(t => t.CustomerID == customerId).OrderByDescending(t => t.ID); foreach (var transaction in transactions) { transactionViewModels.Add(new TransactionViewModel(transaction)); } return(transactionViewModels); }
public IEnumerable <ProductViewModel> ListByZipCodes(List <string> zipCodes) { DesiOfferEntities entities = GeneralService.GetDbEntities(); var query = entities.Products.Where(c => zipCodes.Contains(c.Customer.ZipCode)); List <ProductViewModel> viewModels = new List <ProductViewModel>(); foreach (Product product in query) { viewModels.Add(new ProductViewModel(product)); } return(viewModels); }
public IEnumerable <ProductViewModel> ListMatching(string searchText, int limit = 50) { var entities = GeneralService.GetDbEntities(); var products = entities.Products.Where(p => (p.Name != null && p.Name.Contains(searchText) || (p.Tags != null && p.Tags.Contains(searchText)))); List <ProductViewModel> viewModels = new List <ProductViewModel>(); foreach (Product product in products.Take(limit)) { ProductViewModel viewModel = new ProductViewModel(product); viewModels.Add(viewModel); } return(viewModels.AsEnumerable()); }
public ProductViewModel Update(ProductViewModel viewModel) { var entities = GeneralService.GetDbEntities(); Product product = entities.Products.FirstOrDefault(p => p.ID == viewModel.ID); if (product == null) { return(null); } viewModel.Sync(product); entities.SaveChanges(); return(viewModel); }
public IEnumerable <CustomerViewModel> ListMatching(string searchText) { searchText = searchText ?? string.Empty; searchText = searchText.Trim().ToLower(); DesiOfferEntities entities = GeneralService.GetDbEntities(); var query = entities.Customers.Where(c => (c.FirstName != null && c.FirstName.ToLower().Contains(searchText)) || (c.LastName != null && c.LastName.ToLower().Contains(searchText))); List <CustomerViewModel> customers = new List <CustomerViewModel>(); foreach (Customer customer in query) { customers.Add(new CustomerViewModel(customer)); } return(customers); }
public bool Delete(long id) { var entities = GeneralService.GetDbEntities(); Product product = entities.Products.FirstOrDefault(p => p.ID == id); if (product == null) { return(false); } entities.Products.Remove(product); #if DEBUG == false entities.SaveChanges(); // Dont delete records in debug mode #endif return(true); }
public ImageStoreViewModel AddNew(string fileName) { string fileType = !string.IsNullOrWhiteSpace(fileName) ? Path.GetExtension(fileName) : ".jpg"; ImageStore imageStore = new ImageStore(); long nextImageId = GeneralService.CounterNextValue(CounterNames.ImageId); imageStore.FilePath = string.Format("\\Products\\{0}{1}", nextImageId, fileType); imageStore.FilePathRootID = 1; // TODO - set it from config imageStore.CreatedDate = DateTime.Now; var entities = GeneralService.GetDbEntities(); entities.ImageStores.Add(imageStore); entities.SaveChanges(); return(new ImageStoreViewModel(imageStore)); }
public string GetImagePath(long?imageId) { if (imageId.HasValue && imageId.Value != 0) { ImageStore imageStore = GeneralService.GetDbEntities().ImageStores.Where(img => img.ID == imageId.Value).FirstOrDefault(); if (imageStore != null) { return(PathingService.MapPath(imageStore.FilePathRootID, imageStore.FilePath, PathTypes.DiskPath)); /* * string filePath = imageStore.FilePath; * if (!string.IsNullOrWhiteSpace(filePath)) * { * filePath = filePath.Replace('\\', '/'); * return string.Format("{0}{1}", BaseUrl, filePath); * } */ } } return(string.Empty); }
public bool Delete(long id) { var imageStore = GeneralService.GetDbEntities().ImageStores.Where(i => i.ID == id).FirstOrDefault(); if (imageStore == null) { return(false); } string fullPath = PathingService.MapPath(imageStore.FilePathRootID, imageStore.FilePath, PathTypes.DiskPath); try { GeneralService.GetDbEntities().ImageStores.Remove(imageStore); File.Delete(fullPath); } catch (Exception) { return(false); } return(true); }
public static string GetPathRoot(long pathRootId) { FilePathRoot filePathRoot = GeneralService.GetDbEntities().FilePathRoots.Where(p => p.ID == pathRootId).FirstOrDefault(); return(filePathRoot != null ? filePathRoot.FullPath : string.Empty); }