コード例 #1
0
 /// <summary>
 /// Create a new cg_Products_Tags_Map object.
 /// </summary>
 /// <param name="productTagMapId">Initial value of the ProductTagMapId property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 /// <param name="productTagId">Initial value of the ProductTagId property.</param>
 public static cg_Products_Tags_Map Createcg_Products_Tags_Map(global::System.Int64 productTagMapId, global::System.Int64 productId, global::System.Int64 productTagId)
 {
     cg_Products_Tags_Map cg_Products_Tags_Map = new cg_Products_Tags_Map();
     cg_Products_Tags_Map.ProductTagMapId = productTagMapId;
     cg_Products_Tags_Map.ProductId = productId;
     cg_Products_Tags_Map.ProductTagId = productTagId;
     return cg_Products_Tags_Map;
 }
コード例 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the cg_Products_Tags_Map EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTocg_Products_Tags_Map(cg_Products_Tags_Map cg_Products_Tags_Map)
 {
     base.AddObject("cg_Products_Tags_Map", cg_Products_Tags_Map);
 }
コード例 #3
0
        public ActionResult product_tags_update(FormCollection collection)
        {
            long ProductId = Convert.ToInt64(collection["ProductId"]);
            cg_Products product = db.cg_Products.Where(p => p.ProductId == ProductId).FirstOrDefault();
            string[] tags = collection["productTag"].Split(',');

            // load existing tags
            product.cg_Products_Tags_Map.Load();
            var tagList = product.cg_Products_Tags_Map.ToList();

            // remove all existing tags
            foreach (cg_Products_Tags_Map tagmap in tagList)
            {
                if (!tags.Contains(tagmap.ProductTagId.ToString()))
                {
                    db.DeleteObject(tagmap);
                }
                else
                {
                    tags = tags.Where(val => val != tagmap.ProductTagId.ToString()).ToArray();
                }
            }

            // create a collection of the new tag list
            foreach (string sTagId in tags)
            {
                if (sTagId != "false")
                {
                    long tagId = Convert.ToInt64(sTagId);

                    // create the new object
                    cg_Products_Tags_Map tmap = new cg_Products_Tags_Map() { ProductId = ProductId, ProductTagId = tagId };

                    tmap.cg_ProductsReference.EntityKey = new System.Data.EntityKey("caval_goEntities.cg_Products", "ProductId", ProductId);
                    tmap.cg_Products_TagsReference.EntityKey = new System.Data.EntityKey("caval_goEntities.cg_Products_Tags", "ProductTagId", tagId);

                    // add object to collection
                    db.AddTocg_Products_Tags_Map(tmap);

                    Response.Write("TagId: " + tagId + "<br /> ProductId: " + ProductId + "<hr />");
                }
            }

            // save changes to DB
            db.SaveChanges();

            return RedirectToAction("product_edit", new { id = ProductId });
        }