public async Task <ActionResult> ProcessStores(bool forceGeocode = false, bool ESIndex = true) { var storesToProcess = await _db.Stores .Include(s => s.ClientStores) .ThenInclude(cs => cs.Client) .Include(s => s.Retailer) .ToListAsync(); if (ESIndex) { _esStoreClient.DeleteIndex(); } foreach (var storeToProcess in storesToProcess) { if (forceGeocode || storeToProcess.Latitude == 0 || storeToProcess.Latitude == null) { GoogleGeocoding_Location location = GeneralPurpose.GetLatLong(storeToProcess.Address); storeToProcess.Latitude = location.lat; storeToProcess.Longitude = location.lng; _db.Attach(storeToProcess).State = EntityState.Modified; } if (ESIndex) { _esStoreClient.CreateAsAsync(storeToProcess); } } await _db.SaveChangesAsync(); return(Ok()); }
/// <summary> /// Create/Get a general purpose Data Store. Key and/or Value types can be any of the following: /// - simple type, e.g. - int, short, string, char, float, etc... /// - Xml serializable object. /// NOTE: simple type data are stored in non-Xml format for space optimization reasons. /// /// NOTE 2: this is a multi-thread safe method. /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="createIfNotExist"></param> /// <param name="container"></param> /// <param name="comparer"></param> /// <param name="name"></param> /// <param name="isDataInKeySegment"> </param> /// <param name="mruManaged">true means the returned store's lifetime is managed by StoreFactory using MRU algorithm. /// i.e. - least recently used store(s) will be most likely auto-disposed when number of stores accessed by code reached MRU maximum threshold count.</param> /// <returns></returns> public ISortedDictionary <TKey, TValue> Get <TKey, TValue>(object container, string name, IComparer <TKey> comparer = null, bool createIfNotExist = true, bool isDataInKeySegment = true, bool mruManaged = true) { // assign the current default Value Unpack delegate BTreeAlgorithm.CurrentOnValueUnpack = GeneralPurpose <TKey, TValue> .Collection_OnUnpack; var r2 = CreateDictionary <GeneralPurpose <TKey, TValue>, TKey, TValue>(createIfNotExist, container, name, containerDod => { var r = new GeneralPurpose <TKey, TValue >( container, comparer, name, DataStoreType . SopOndisk, null, isDataInKeySegment); containerDod. SetCurrentValueInMemoryData (r); return(r); }, mruManaged); // assign the current default Value Unpack delegate BTreeAlgorithm.CurrentOnValueUnpack = null; return(r2); }
//PopulateDaysDropDownList private void PopulateDaysDropDownList() { var DayRange = GeneralPurpose.IntRange(1, 7); ViewBag.DayOfWeek = new SelectList(DayRange); }
private void PopulateDurationDropDownList(int minMinute = 0, int maxMinute = 59) { var MinuteRange = GeneralPurpose.IntRange(minMinute, maxMinute); ViewBag.DurationMinutes = new SelectList(MinuteRange); }
private void PopulateMinutesDropDownList(int minMinute = 0, int maxMinute = 59) { var MinuteRange = GeneralPurpose.IntRange(minMinute, maxMinute); ViewBag.StartingMinute = new SelectList(MinuteRange); }
private void PopulateHoursDropDownList(int minHour, int maxHour) { var HourRange = GeneralPurpose.IntRange(minHour, maxHour); ViewBag.StartingHour = new SelectList(HourRange); }
public async Task <IActionResult> Update(Store_AddEditModel model) { if (!ModelState.IsValid) { model.ClientRetailers = await _db.ClientRetailers .Where(q => q.ClientId == _client_id) .Select(s => s.Retailer) .ToListAsync(); View("Edit", model); } Store storeToUpdate = await _db.Stores .Include(i => i.ClientStores) .FirstOrDefaultAsync(q => q.Id == model.Id); if (storeToUpdate == null) { return(NotFound()); } string addr_cmp_old = storeToUpdate.Address.ToUpper(); string addr_cmp_new = model.Address.ToUpper(); storeToUpdate.Name = model.Name; storeToUpdate.Addr_Ln_1 = model.Addr_Ln_1; storeToUpdate.Addr_Ln_2 = model.Addr_Ln_2; storeToUpdate.City = model.City; storeToUpdate.State = model.State; storeToUpdate.Zip = model.Zip; storeToUpdate.Phone = model.Phone; if (!String.IsNullOrEmpty(model.NewRetailer.Name)) { Retailer newRetailer = new Retailer { Name = model.NewRetailer.Name, ClientRetailers = new List <ClientRetailer> { new ClientRetailer { ClientId = _client_id } } }; _db.Retailers.Add(newRetailer); storeToUpdate.Retailer = newRetailer; } else { storeToUpdate.RetailerId = (Guid)model.RetailerId; } ClientStore clientStore = storeToUpdate.ClientStores.FirstOrDefault(q => q.ClientId == _client_id); Dictionary <string, object> props = new Dictionary <string, object>(); string[] keysToUpdate = new string[] { "MaxOrderAmount", "LocationNumber" }; // Copy JSON data that is not relevant to this action as-is try { foreach (var key in clientStore.Properties.Object.Keys.Where(q => !keysToUpdate.Contains(q))) { props.Add(key, clientStore.Properties.Object[key]); } } catch { props = new Dictionary <string, object>(); } // Update JSON data that is relevant to this action // Only update the ones that are set to non-null values // This logic will drop the properties that don't have values foreach (string keyToUpdate in keysToUpdate) { try { if (model.GetType().GetProperty(keyToUpdate).GetValue(model, null) != null) { props.Add(keyToUpdate, model.GetType().GetProperty(keyToUpdate).GetValue(model, null)); } } catch { continue; } } // Finally associate the Properties to the // client-store combo clientStore.Properties = new JsonObject <Dictionary <string, object> > { Object = props }; _db.Attach(clientStore).State = EntityState.Modified; // Only Geocode if the address has changed if (addr_cmp_new != addr_cmp_old || storeToUpdate.Latitude == null || storeToUpdate.Latitude == 0) { GoogleGeocoding_Location location = GeneralPurpose.GetLatLong(addr_cmp_new); storeToUpdate.Latitude = location.lat; storeToUpdate.Longitude = location.lng; } _db.Attach(storeToUpdate).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (Exception) { model.ClientRetailers = await _db.ClientRetailers .Where(q => q.ClientId == _client_id) .Select(s => s.Retailer) .ToListAsync(); View("Edit", model); } // Reindex with ES IndexStoreWithES(storeToUpdate.Id); return(RedirectToAction("Details", new { id = model.Id })); }
public async Task <IActionResult> Create(Store_AddEditModel model) { if (!ModelState.IsValid) { model.ClientRetailers = await _db.ClientRetailers .Where(q => q.ClientId == _client_id) .Select(s => s.Retailer) .ToListAsync(); return(View("New", model)); } ClientStore clientStore = new ClientStore { ClientId = _client_id, Store = new Store { Name = model.Name, Active = true, Addr_Ln_1 = model.Addr_Ln_1, Addr_Ln_2 = model.Addr_Ln_2, City = model.City, State = model.State, Zip = model.Zip, Country = "USA", Phone = model.Phone }, Active = true }; if (!String.IsNullOrEmpty(model.NewRetailer.Name)) { Retailer newRetailer = new Retailer { Name = model.NewRetailer.Name, ClientRetailers = new List <ClientRetailer> { new ClientRetailer { ClientId = _client_id } } }; _db.Retailers.Add(newRetailer); clientStore.Store.Retailer = newRetailer; } else { clientStore.Store.RetailerId = model.RetailerId ?? (new Guid()); } Dictionary <string, object> props = new Dictionary <string, object>(); if (model.MaxOrderAmount != null) { props.Add("MaxOrderAmount", model.MaxOrderAmount); } if (model.LocationNumber != null) { props.Add("LocationNumber", model.LocationNumber); } if (props.Any()) { clientStore.Properties = new JsonObject <Dictionary <string, object> > { Object = props } } ; GoogleGeocoding_Location location = GeneralPurpose.GetLatLong(clientStore.Store.Address); clientStore.Store.Latitude = location.lat; clientStore.Store.Longitude = location.lng; _db.ClientStores.Add(clientStore); await _db.SaveChangesAsync(); IndexStoreWithES(clientStore.Store.Id); return(RedirectToAction("Index")); }