Ejemplo n.º 1
0
 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";
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 5
0
 partial void DeleteItemProductAssociation(ItemProductAssociation instance);
Ejemplo n.º 6
0
 partial void UpdateItemProductAssociation(ItemProductAssociation instance);
Ejemplo n.º 7
0
 partial void InsertItemProductAssociation(ItemProductAssociation instance);
Ejemplo n.º 8
0
		private void detach_ItemProductAssociations(ItemProductAssociation entity)
		{
			this.SendPropertyChanging();
			entity.ItemProduct = null;
		}