void Synchronizer_SyncItemMasterChangeEvent(BaseAppServerCom.Models.Product p, Configuration.Sync.SyncType e) { if (e == Configuration.Sync.SyncType.Add) { try { Func <string, bool> compare = (key) => { return(p.categories.Any(m => m == key)); }; var cat = GConfig.POS_Setup.ItemCategories.Where(n => n.vCategoryCode != "all-items").FirstOrDefault(n => p.categories.Any(m => m == n.vCategoryShortDesc)); if (cat != null && !cat.POS_ItemMasters.Any(n => n.itemID == p.id)) { POS_ItemMaster item = new POS_ItemMaster { itemID = p.id, dStartDate = p.created_at, dEndDate = p.updated_at, vItemAvailability = p.purchaseable.ToString(), vItemDesc1 = p.title, vItemDesc2 = p.description, vItemStatus = p.status, POS_ItemCategoryId = cat.CatID, vItemMinPrice = (decimal?)p.regular_price, vItemPrice = (decimal)p.price }; cat.POS_ItemMasters.Add(item); GConfig.DAL.SaveChanges(); var catvm = Register.Categories.Where(n => n.CategoryType == CategoryType.None).FirstOrDefault(n => n.CatID == cat.CatID); if (catvm != null && catvm.ItemsInitialized) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { catvm.Items.Add(new ItemMasterVM(item)); })); } } } catch (Exception ex) { var m = ex; } } }
void Synchronizer_SyncItemCategoryChangeEvent(BaseAppServerCom.Models.Category rcat, Configuration.Sync.SyncType e) { if (e == Configuration.Sync.SyncType.Add) { try { //TODO: // verify string lenghts POS_ItemCategory lcat = new POS_ItemCategory { CatID = rcat.id, vCategoryCode = rcat.slug, vCategoryDesc = rcat.description, vCategoryShortDesc = rcat.name }; GConfig.POS_Setup.ItemCategories.Add(lcat); //GConfig.DAL.StateChange(GConfig.POS_Setup, System.Data.Entity.EntityState.Modified) GConfig.DAL.SaveChanges(); if (lcat.vCategoryCode != "all-items") { if (Register.CategoriesInitialized) { var cat = GConfig.POS_Setup.ItemCategories.FirstOrDefault(n => n.CatID == lcat.CatID); if (cat != null) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { Register.Categories.Add(new CategoryVM(cat, Register)); })); } } } } catch (Exception ex) { //var error= ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors; var m = ex; } } }