/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> public override Model.Entities.Asset Add(Model.Entities.Asset model) { Asset newEntity = AssetEntityFactory.CreateFromDomainModel(model, ObjectMapper); DbEntityEntry entry = Context.Entry <Asset>(newEntity); if (entry.State == System.Data.Entity.EntityState.Detached) { Context.Entry <Asset>(newEntity).State = System.Data.Entity.EntityState.Added; Context.SaveChanges(); } return(AssetEntityFactory.CreateFromDataModel(newEntity, ObjectMapper)); }
/// <summary> /// Finds the assets by company. /// </summary> /// <param name="companyId">The company id.</param> /// <returns></returns> public List <Model.Entities.Asset> FindAssetsByCompany(int companyId, int view, List <String> tagsFiltering) { List <Model.Entities.Asset> assetList = new List <Model.Entities.Asset>(); try { IQueryable <Asset> assetQuery = this.Context.Set <Asset>() .Where(a => a.CompanyId.Equals(companyId)) .Include("Tags") .OrderByDescending(p => p.Id); // Filtering if (tagsFiltering != null && tagsFiltering.Count > 0) { List <Asset> assetListEntity = assetQuery.ToList(); List <Asset> assetListFiltered = new List <Asset>(); assetListEntity.ForEach(a => a.Tags.ToList <Tag>() .ForEach(t => { if (!assetListFiltered.Contains(a)) { if (tagsFiltering.Contains(t.Name)) { assetListFiltered.Add(a); } } } )); // Return Assets assetList = AssetEntityFactory.CreateFromDataModel(assetListFiltered, ObjectMapper); } else { // Return Assets assetList = AssetEntityFactory.CreateFromDataModel(assetQuery.ToList(), ObjectMapper); } if (view != 0) { //assetQuery = assetQuery.Take(view); assetList = assetList.Take <Model.Entities.Asset>(view).ToList(); } } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(assetList); }
/// <summary> /// Gets the asset by id. /// </summary> /// <param name="moduleId">The module id.</param> /// <returns></returns> public Model.Entities.Asset GetAssetById(int assetId, List <string> includeAssociations) { Model.Entities.Asset asset = null; try { IQueryable <Asset> assets = this.Context.Assets.Where(a => a.Id.Equals(assetId)); assets = IncludePropertyAssociations(assets, includeAssociations); Asset assetEntity = assets.ToList().FirstOrDefault(); asset = AssetEntityFactory.CreateFromDataModel(assetEntity, ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(asset); }
/// <summary> /// Finds the video assets by company. /// </summary> /// <param name="companyId">The company id.</param> /// <returns></returns> public List <Model.Entities.Asset> FindDocumentAssetsByCompany(int companyId) { List <Model.Entities.Asset> assetList = new List <Model.Entities.Asset>(); try { IQueryable <Asset> assetQuery = this.Context.Set <Document>().Where(a => a.CompanyId.Equals(companyId)).OrderByDescending(p => p.Id); // Return Assets assetList = AssetEntityFactory.CreateFromDataModel(assetQuery.ToList(), ObjectMapper); } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding); } return(assetList); }