public Boolean SaveItemProduct(ItemProduct item) { ItemProduct itemQuery = new ItemProduct(); try { using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) { if (item.id != 0) { itemQuery = db.ItemProducts.Where(m => m.id == item.id).FirstOrDefault(); } if (itemQuery != default(ItemProduct)) { itemQuery.id = item.id; itemQuery.Type = item.Type; itemQuery.ItemId = item.ItemId; } if (item.id == 0) { db.ItemProducts.InsertOnSubmit(itemQuery); } db.SubmitChanges(); DeleteItemProductAssociations(itemQuery.id); foreach (ItemProductAssociation ipa in item.ItemProductAssociations) { ItemProductAssociation itemsQuery = new ItemProductAssociation(); itemsQuery.ItemProductId = itemQuery.id; itemsQuery.ItemId = ipa.ItemId; db.ItemProductAssociations.InsertOnSubmit(itemsQuery); } db.SubmitChanges(); } } catch (Exception ex) { return false; } return true; }
public String SaveAssociatedItems(String model) { ItemProductModel model2Save; Services.ItemProduct itemProduct; Services.ItemProductAssociation itemProductAssociation; try { model2Save = SetModel(model); if (model2Save != null) { foreach (Models.ItemProduct item in model2Save.ItemsProduct) { itemProduct = new Services.ItemProduct(); itemProduct.id = item.id; itemProduct.ItemId = item.ItemId; itemProduct.Type = (Int32)item.Type; foreach (ItemProductAssociation itemAssosiation in item.ItemProductAssociation) { itemProductAssociation = new Services.ItemProductAssociation(); itemProductAssociation.ItemId = itemAssosiation.ItemId; itemProductAssociation.ItemProductId = itemAssosiation.ItemProductId; itemProduct.ItemProductAssociations.Add(itemProductAssociation); } _itemProductService.SaveItemProduct(itemProduct); } } } catch (Exception ex) { base.Log(ex); return ex.Message; } finally { } return "OK"; }
public String SaveAssociatedItems(String model) { ItemProductModel model2Save; Services.ItemProduct itemProduct; Services.ItemProductAssociation itemProductAssociation; try { model2Save = SetModel(model); if (model2Save != null) { foreach (Models.ItemProduct item in model2Save.ItemsProduct) { itemProduct = new Services.ItemProduct(); itemProduct.id = item.id; itemProduct.ItemId = item.ItemId; itemProduct.Type = (Int32)item.Type; foreach (ItemProductAssociation itemAssosiation in item.ItemProductAssociation) { itemProductAssociation = new Services.ItemProductAssociation(); itemProductAssociation.ItemId = itemAssosiation.ItemId; itemProductAssociation.ItemProductId = itemAssosiation.ItemProductId; itemProduct.ItemProductAssociations.Add(itemProductAssociation); } _itemProductService.SaveItemProduct(itemProduct); } } } catch (Exception ex) { base.Log(ex); return(ex.Message); } finally { } return("OK"); }
private ItemProductModel SetModel(String model) { JavaScriptSerializer objJavascript = new JavaScriptSerializer(); Char[] commaDelimiter = new char[] { ',' }; Char[] colonDelimiter = new char[] { ':' }; if (SessionData.item != null) { ItemProductModel productModel = new ItemProductModel(); Array assosiations = (Array)objJavascript.DeserializeObject(model); productModel.ItemsProduct = new List<Models.ItemProduct>(); foreach (String assosiation in assosiations) { Models.ItemProduct itemProduct = new Models.ItemProduct(); itemProduct.ItemId = SessionData.item.id; Array values = assosiation.Split(commaDelimiter, StringSplitOptions.RemoveEmptyEntries); itemProduct.ItemProductAssociation = new List<ItemProductAssociation>(); foreach (String value in values) { ItemProductAssociation itemProductAssociation = new ItemProductAssociation(); Array vars = value.Split(colonDelimiter, StringSplitOptions.RemoveEmptyEntries); itemProduct.id = Int32.Parse(vars.GetValue(0).ToString()); itemProduct.Type = EnumHelper<Common.ProductType>.Parse(vars.GetValue(2).ToString()); itemProductAssociation.ItemProductId = Int32.Parse(vars.GetValue(0).ToString()); itemProductAssociation.ItemId = Int32.Parse(vars.GetValue(1).ToString()); itemProduct.ItemProductAssociation.Add(itemProductAssociation); } productModel.ItemsProduct.Add(itemProduct); } return productModel; } return null; }
partial void DeleteItemProductAssociation(ItemProductAssociation instance);
partial void UpdateItemProductAssociation(ItemProductAssociation instance);
partial void InsertItemProductAssociation(ItemProductAssociation instance);
private void detach_ItemProductAssociations(ItemProductAssociation entity) { this.SendPropertyChanging(); entity.ItemProduct = null; }