Exemple #1
0
        public static Asset MapAsset(IAsset asset)
        {
            if (asset == null)
            {
                return(null);
            }

            Context.Asset result = new Context.Asset();
            result.Id          = asset.Id;
            result.AssetTypeId = (int)asset.AssetType;
            result.Title       = asset.Title;
            result.Description = asset.Description;
            result.Url         = asset.Url;

            /*
             * if (asset.Tags != null)
             * {
             *  foreach (var assetTag in asset.Tags)
             *  {
             *      if (assetTag.Tags != null)
             *      {
             *          var tag = MapTag(assetTag.Tags);
             *          result.Tags.Add(tag);
             *      }
             *  }
             * }
             */
            return(result);
        }
Exemple #2
0
 private void AddTags(Context.Asset asset, IAsset value, Dictionary <int, Context.Tag> dicExistingTags)
 {
     foreach (Contracts.Tag vtag in value.Tags)
     {
         //If not an existing tag, create a new tag.
         Tag tag = dicExistingTags.Values.FirstOrDefault(t => t.Title.ToLower() == vtag.Name.ToLower());
         if (tag == null)
         {
             asset.AssetTags.Add(new AssetTag()
             {
                 Asset = asset,
                 Tags  = new Tag()
                 {
                     Title    = vtag.Name,
                     IsActive = true
                 }
             });
         }
         else if (!asset.AssetTags.Any(t => t.Tags.Id == tag.Id))
         {
             asset.AssetTags.Add(new AssetTag()
             {
                 Asset = asset,
                 Tags  = tag
             });
         }
     }
 }
Exemple #3
0
 private void MarkAssetTagsForDelete(Context.Asset asset, Dictionary <int, Context.Tag> dicExistingTags)
 {
     if (asset.AssetTags != null)
     {
         for (int i = asset.AssetTags.Count - 1; i >= 0; i--)
         {
             Context.AssetTag at = asset.AssetTags.ElementAt(i);
             if (!dicExistingTags.ContainsKey(at.TagId))
             {
                 this.Context.Entry(at).State = EntityState.Deleted;
             }
         }
     }
 }
Exemple #4
0
        private Context.Asset ProcessTags(Context.Asset asset, IAsset value)
        {
            if (value.Tags == null || value.Tags.Count == 0)
            {
                return(asset);
            }

            Dictionary <int, Context.Tag> dicExistingTags = this.GetTags(value);

            //Remove Tags from Asset that don't match List.
            //This means that the user has deleted some tags and we want to remove the association.
            this.MarkAssetTagsForDelete(asset, dicExistingTags);

            //Add Tags.
            this.AddTags(asset, value, dicExistingTags);

            return(asset);
        }