Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="asset"></param>
        public void RemoveAssetForUnit(Model.Entities.Unit unit, Model.Entities.Asset asset)
        {
            Unit  unitEntity  = this.Context.Set <Unit>().Include(u => u.Assets).FirstOrDefault(u => u.Id.Equals(unit.Id));
            Asset assetEntity = Context.Set <Asset>().Find(ObjectMapper.GetEntityIdentifier <Model.Entities.Asset>(asset));

            unitEntity.Assets.Remove(assetEntity);
            Context.SaveChanges();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="asset"></param>
        public Model.Entities.Unit AddAssetForUnit(int unitId, Model.Entities.Asset asset)
        {
            Unit  unitEntity  = this.Context.Set <Unit>().Include(u => u.Assets).FirstOrDefault(u => u.Id.Equals(unitId));
            Asset assetEntity = Context.Set <Asset>().Find(asset.Id);

            // if the unit already has the asset, return
            if (unitEntity.Assets.Contains(assetEntity))
            {
                return(default(Model.Entities.Unit));
            }

            //updating
            Context.Entry <Unit>(unitEntity).State = System.Data.Entity.EntityState.Modified;
            unitEntity.Assets.Add(assetEntity);
            Context.SaveChanges();
            return(ObjectMapper.Map <Unit, Model.Entities.Unit>(unitEntity));
        }
Exemple #3
0
 /// <summary>
 /// Creates from domain model.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <param name="objectMapper">The object mapper.</param>
 /// <returns></returns>
 public static Repository.Asset CreateFromDomainModel(Model.Entities.Asset asset, IObjectMapperAdapter objectMapper)
 {
     if (asset is Model.Entities.Video)
     {
         return(objectMapper.Map <Model.Entities.Video, Video>((Model.Entities.Video)asset));
     }
     else if (asset is Model.Entities.Document)
     {
         return(objectMapper.Map <Model.Entities.Document, Document>((Model.Entities.Document)asset));
     }
     else if (asset is Model.Entities.Image)
     {
         return(objectMapper.Map <Model.Entities.Image, Image>((Model.Entities.Image)asset));
     }
     else
     {
         return(objectMapper.Map <Model.Entities.Asset, Asset>(asset));
     }
 }