public IList <Place> GetPlaces() { IList <Place> result = new List <Place>(); ISession session = SessionFactory.GetSession(); try { ICriteria criteria = session.CreateCriteria <PlaceEntity>(); IList <PlaceEntity> places = criteria.List <PlaceEntity>(); EntityConverter entityConverter = new EntityConverter(); foreach (PlaceEntity dataEntity in places) { Place businessEntity = entityConverter.FromDataEntity(dataEntity, PlaceConvertOptions.Short); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public Album GetAlbum(int albumID) { Album result = null; ISession session = SessionFactory.GetSession(); try { AlbumEntity dataEntity = session.CreateCriteria <AlbumEntity>(). Add(Restrictions.Eq("ID", albumID)).UniqueResult <AlbumEntity>(); EntityConverter entityConverter = new EntityConverter(); result = entityConverter.FromDataEntity(dataEntity, AlbumConvertOptions.Full); } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public User GetUser(string userName, string password) { User result = null; ISession session = SessionFactory.GetSession(); try { var query = session.QueryOver <UserEntity>(). Where(u => u.UserName == userName).And(u => u.Password == password); IList <UserEntity> users = query.List <UserEntity>(); if (users.Count > 0) { UserEntity foundUser = users[0]; EntityConverter converter = new EntityConverter(); result = converter.FromDataEntity(foundUser); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IList <Mood> GetMoods() { IList <Mood> result = new List <Mood>(); ISession session = SessionFactory.GetSession(); try { ICriteria criteria = session.CreateCriteria <MoodEntity>(); IList <MoodEntity> moods = criteria.List <MoodEntity>(); EntityConverter entityConverter = new EntityConverter(); foreach (MoodEntity dataEntity in moods) { Mood businessEntity = entityConverter.FromDataEntity(dataEntity, MoodConvertOptions.Short); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IList <Tag> GetTagsWithAssociatedEntitiesCount() { var result = new List <Tag>(); ISession session = SessionFactory.GetSession(); try { var query = session.GetNamedQuery("GetTagsWithAssociatedEntitiesCount"); var dataEntities = query.SetResultTransformer(new TagResultTransformer()).List <TagEntity>(); EntityConverter converter = new EntityConverter(); foreach (var de in dataEntities) { var tag = converter.FromDataEntity(de); result.Add(tag); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public Tag GetTag(int tagID) { Tag result = null; ISession session = SessionFactory.GetSession(); try { TagEntity dataEntity = session.QueryOver <TagEntity>(). Where(t => t.ID == tagID).SingleOrDefault(); EntityConverter entityConverter = new EntityConverter(); result = entityConverter.FromDataEntity(dataEntity); } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IList <Tag> GetTags() { IList <Tag> result = new List <Tag>(); ISession session = SessionFactory.GetSession(); try { ICriteria criteria = session.CreateCriteria <TagEntity>(); IList <TagEntity> tags = criteria.List <TagEntity>(); EntityConverter entityConverter = new EntityConverter(); foreach (TagEntity dataEntity in tags) { Tag businessEntity = entityConverter.FromDataEntity(dataEntity); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public Artist GetArtist(int artistID) { Artist result = null; ISession session = SessionFactory.GetSession(); try { ArtistEntity dataEntity = session.QueryOver <ArtistEntity>(). Where(a => a.ID == artistID).SingleOrDefault(); EntityConverter entityConverter = new EntityConverter(); result = entityConverter.FromDataEntity(dataEntity, ArtistConvertOptions.Full); } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IPagedList <Album> GetAlbums(ILoadOptions options) { IPagedList <Album> result = new PagedList <Album>(); if (options == null) { return(result); } if (options.MaxResults <= 0) { return(result); } ISession session = SessionFactory.GetSession(); try { DetachedCriteria countCriteria = GetAlbumsImpl(options); DetachedCriteria listCriteria = GetAlbumsImpl(options); countCriteria.SetProjection(Projections.RowCount()); countCriteria.ClearOrders(); listCriteria. SetFirstResult(options.FirstResult). SetMaxResults(options.MaxResults); IMultiCriteria multiCriteria = session.CreateMultiCriteria(); multiCriteria.Add(countCriteria); multiCriteria.Add(listCriteria); IList queryResult = multiCriteria.List(); result.TotalItems = (int)((IList)queryResult[0])[0]; IList recordsList = (IList)queryResult[1]; EntityConverter entityConverter = new EntityConverter(); foreach (var e in recordsList) { AlbumEntity dataEntity = e as AlbumEntity; Album businessEntity = entityConverter.FromDataEntity(dataEntity, AlbumConvertOptions.Small); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IList <Album> GetAlbumsByArtistID(int artistID) { IList <Album> result = new List <Album>(); ISession session = SessionFactory.GetSession(); try { DetachedCriteria artistsCriteria = DetachedCriteria.For <AlbumEntity>().CreateCriteria("Artists"). Add(Restrictions.Eq("ID", artistID)). SetProjection(Property.ForName("ID")); ICriteria criteria = session.CreateCriteria <AlbumEntity>(). Add(Subqueries.PropertyIn("ID", artistsCriteria)).AddOrder(new Order("ID", true)); IList <AlbumEntity> albums = criteria.List <AlbumEntity>(); EntityConverter converter = new EntityConverter(); foreach (AlbumEntity dataEntity in albums) { Album businessEntity = converter.FromDataEntity(dataEntity, AlbumConvertOptions.Small); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IPagedList <TaggedObject> GetTaggedObjects(ILoadOptions loadOptions) { /* * This method uses sophisticated stored procedure which performs actual pagination and * filtering logic against special database view. * * First record of result set is stub one and returns total number of items matching filtering * rules. */ var result = new PagedList <TaggedObject>(); ISession session = SessionFactory.GetSession(); try { var specialOptions = loadOptions as TagLoadOptions; string entityTypeFilter = String.Empty; string entityNameFilter = String.Empty; if (specialOptions != null) { if (!specialOptions.ExcludeAlbums && !specialOptions.ExcludeArtists) { entityTypeFilter = String.Format("{0},{1}", (int)TaggedObjectType.Artist, (int)TaggedObjectType.Album); } else if (!specialOptions.ExcludeAlbums) { entityTypeFilter = String.Format("{0}", (int)TaggedObjectType.Album); } else if (!specialOptions.ExcludeArtists) { entityTypeFilter = String.Format("{0}", (int)TaggedObjectType.Artist); } entityNameFilter = specialOptions.EntityName == null ? String.Empty : specialOptions.EntityName; } var query = session.GetNamedQuery("GetTaggedObjects"); query.SetParameter("tagIDs", loadOptions.FilterValue); query.SetParameter("entityTypes", entityTypeFilter); query.SetParameter("ioffset", loadOptions.FirstResult); query.SetParameter("ilimit", loadOptions.MaxResults); query.SetParameter("entityName", entityNameFilter); var dataEntities = query.SetResultTransformer(new TaggedObjectResultTransformer()).List <TaggedObjectEntity>(); //get stub entity generated by sp, which stores total items count needed for pagination var stubCounterEntity = dataEntities.Where(e => e.ObjectType == -1).First(); dataEntities.Remove(stubCounterEntity); EntityConverter converter = new EntityConverter(); foreach (var de in dataEntities) { var tag = converter.FromDataEntity(de); result.Add(tag); } result.TotalItems = stubCounterEntity.ID; } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }