public IActionResult UpdateDatabase(string file) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file + ".xlsx"); PerfumeWorldWide = _context.PerfumeWorldWide.ToDictionary(x => x.sku, y => y); DBModifierPerfumeWorldWideExcel dBModifierPerfumeWorldWideExcel = new DBModifierPerfumeWorldWideExcel(path, PerfumeWorldWide); dBModifierPerfumeWorldWideExcel.TableExecutor(); ServiceTimeStamp service = new ServiceTimeStamp(); service.TimeStamp = DateTime.Today; service.Wholesalers = Wholesalers.PerfumeWorldWide.ToString(); service.type = "Excel"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); System.IO.File.Delete(path); return(RedirectToAction("UpdateExcel")); }
public IActionResult UpdateAzImportsExcel(string file) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file + ".xlsx"); var azImportItems = _context.AzImporter.ToDictionary(x => x.Sku, y => y); foreach (var az in azImportItems) { az.Value.Quantity = 0; } DBModifierAzImporterExcel AzImporter = new DBModifierAzImporterExcel(path, azImportItems); AzImporter.TableExecutor(); ServiceTimeStamp service = new ServiceTimeStamp(); service.TimeStamp = DateTime.Today; service.Wholesalers = Wholesalers.AzImporter.ToString(); service.type = "Excel"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); System.IO.File.Delete(path); return(RedirectToAction("Index")); }
private void FragancexSQLPreparer(ServiceTimeStamp service) { var upc = _context.UPC.ToDictionary(x => x.ItemID, y => y.Upc); try { var listingApiClient = new FrgxListingApiClient("346c055aaefd", "a5574c546cbbc9c10509e3c277dd7c7039b24324"); // For testing purposes //List<Product> allProducts = new List<Product>(); //var product = listingApiClient.GetProductById("412492"); //allProducts.Add(product); var allProducts = listingApiClient.GetAllProducts(); DBModifierFragrancexAPI dBModifierFragrancexAPI = new DBModifierFragrancexAPI("", upc) { allProducts = allProducts }; dBModifierFragrancexAPI.TableExecutor(); // delete everything from the db, then update using (var tran = _context.Database.BeginTransaction()) { _context.BulkDelete(_context.Wholesaler_Fragrancex.ToList()); tran.Commit(); } using (var tran = _context.Database.BeginTransaction()) { _context.BulkInsertOrUpdate(dBModifierFragrancexAPI.fragrancex); tran.Commit(); } service.TimeStamp = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.type = "API"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } catch (Exception e) { throw e; } }
public async Task <IActionResult> ProductExport(IFormFile file) { if (file == null || file.Length == 0) { return(null); } var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } ServiceTimeStamp service = new ServiceTimeStamp(); if (_context.ServiceTimeStamp.Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .LastOrDefault <ServiceTimeStamp>() == null) { Helper.tablePreparer(path); service.TimeStamp = DateTime.Today; service.Wholesalers = Wholesalers.Fragrancex.ToString(); _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } else if (_context.ServiceTimeStamp.Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .LastOrDefault <ServiceTimeStamp>().TimeStamp != DateTime.Today) { Helper.tablePreparer(path); service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.TimeStamp = DateTime.Today; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } var memory = new MemoryStream(); using (var stream = new FileStream(path, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; FileStreamResult returnFile = File(memory, Helper.GetContentType(path), Path.GetFileNameWithoutExtension(path) + "_Converted" + Path.GetExtension(path).ToLowerInvariant()); System.IO.File.Delete(path); return(returnFile); }
private void updateFragrancex() { ServiceTimeStamp service = new ServiceTimeStamp(); if (_context.ServiceTimeStamp.Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .LastOrDefault <ServiceTimeStamp>() == null) { FragancexSQLPreparer(service); } else if (_context.ServiceTimeStamp.Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .LastOrDefault <ServiceTimeStamp>().TimeStamp != DateTime.Today) { FragancexSQLPreparer(service); } }
private void FragancexSQLPreparer(ServiceTimeStamp service) { var upc = _context.UPC.ToDictionary(x => x.ItemID, y => y.Upc); // TODO: Test this functionality once Alex is done with his development!! try { var listingApiClient = new FrgxListingApiClient("346c055aaefd", "a5574c546cbbc9c10509e3c277dd7c7039b24324"); // For testing purposes //List<Product> allProducts = new List<Product>(); //var product = listingApiClient.GetProductById("412492"); //allProducts.Add(product); var allProducts = listingApiClient.GetAllProducts(); DBModifierFragrancexAPI dBModifierFragrancexAPI = new DBModifierFragrancexAPI("", upc) { allProducts = allProducts }; dBModifierFragrancexAPI.TableExecutor(); service.TimeStamp = DateTime.Today; service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.type = "API"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } catch (Exception e) { } }
public IActionResult Update(string file) { ServiceTimeStamp service = new ServiceTimeStamp(); var timeStampDB = _context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .LastOrDefault()?.TimeStamp; var timeStampToday = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).Date.AddHours(5); if (timeStampDB == null || DateTime.Compare((DateTime)timeStampDB, timeStampToday) < 0) { try { FragancexSQLPreparer(service); } catch (Exception e) { ViewData["Error"] = e.Message.ToString(); return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); } } else { ViewData["Info"] = "Database already updated today after " + timeStampToday; return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); } ViewData["Success"] = "Database updated successfully at " + TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); }
public IActionResult UpdateFragrancexExcel(string file) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file + ".xlsx"); var upc = _context.UPC.ToDictionary(x => x.ItemID, y => y.Upc); DBModifierFragrancexExcel dBModifierFragrancexExcel = new DBModifierFragrancexExcel(path, upc); dBModifierFragrancexExcel.TableExecutor(); // Update the FragrancexList db var fragranceTitle = _context.FragrancexTitle.ToDictionary(x => x.ItemID, y => y.Title); DBModifierFragrancexExcelList dBModifierFragrancexExcelList = new DBModifierFragrancexExcelList(path, fragranceTitle); dBModifierFragrancexExcelList.TableExecutor(); ServiceTimeStamp service = new ServiceTimeStamp(); service.TimeStamp = DateTime.Today; service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.type = "Excel"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); System.IO.File.Delete(path); return(RedirectToAction("UpdateExcel")); }
public async Task <IActionResult> Index(string file) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file + ".xlsx"); try { var azImportItems = _context.Wholesaler_AzImporter.ToDictionary(x => x.Sku, y => y); foreach (var az in azImportItems) { az.Value.Quantity = 0; } DBModifierAzImporterExcel AzImporter = new DBModifierAzImporterExcel(path, azImportItems); AzImporter.TableExecutor(); // delete everything from the db, then update using (var tran = _context.Database.BeginTransaction()) { await _context.BulkDeleteAsync(_context.Wholesaler_AzImporter.ToList()); tran.Commit(); } using (var tran = _context.Database.BeginTransaction()) { await _context.BulkInsertOrUpdateAsync(AzImporter.azImport); tran.Commit(); } ServiceTimeStamp service = new ServiceTimeStamp(); service.TimeStamp = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); service.Wholesalers = Wholesalers.AzImporter.ToString(); service.type = "Excel"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } catch (Exception e) { SetUIValues(path); ViewData["Error"] = e.Message.ToString(); return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.AzImporter.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); } SetUIValues(path); ViewData["Success"] = "Database updated successfully at " + TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.AzImporter.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); }
public async Task <IActionResult> UpdateExcel(string file) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file + ".xlsx"); try { var upc = _context.UPC.ToDictionary(x => x.ItemID, y => y.Upc); DBModifierFragrancexExcel dBModifierFragrancexExcel = new DBModifierFragrancexExcel(path, upc); try { dBModifierFragrancexExcel.TableExecutor(); } catch (Exception e) { throw e; } // Update the FragrancexList db var fragranceTitle = _context.FragrancexTitle.ToDictionary(x => x.ItemID, y => y.Title); // delete everything from the db, then update try { using (var tran = _context.Database.BeginTransaction()) { await _context.BulkDeleteAsync(_context.Wholesaler_Fragrancex.ToList()); tran.Commit(); } using (var tran = _context.Database.BeginTransaction()) { await _context.BulkInsertOrUpdateAsync(dBModifierFragrancexExcel.fragancexList); tran.Commit(); } } catch (Exception e) { throw e; } DBModifierFragrancexExcelList dBModifierFragrancexExcelList = new DBModifierFragrancexExcelList(path, fragranceTitle); // insert to the db and update fragranceTitle dBModifierFragrancexExcelList.TableExecutor(); try { using (var tran = _context.Database.BeginTransaction()) { await _context.BulkInsertOrUpdateAsync(dBModifierFragrancexExcelList.fragrance); tran.Commit(); } } catch (Exception e) { throw e; } ServiceTimeStamp service = new ServiceTimeStamp(); service.TimeStamp = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); service.Wholesalers = Wholesalers.Fragrancex.ToString(); service.type = "Excel"; _context.ServiceTimeStamp.Add(service); _context.SaveChanges(); } catch (Exception e) { System.IO.File.Delete(path); ViewData["Error"] = e.Message.ToString(); return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); } System.IO.File.Delete(path); ViewData["Success"] = "Database updated successfully at " + TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow , TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); return(View(_context.ServiceTimeStamp .Where(x => x.Wholesalers == Wholesalers.Fragrancex.ToString()) .OrderByDescending(x => x.TimeStamp).Take(5).ToList())); }