public bool RemoveListening(Listening listening) { bool result = false; ISession session = SessionFactory.GetSession(); ITransaction tx = session.BeginTransaction(); try { ListeningEntity dataEntity = session.CreateCriteria <ListeningEntity>(). Add(Restrictions.Eq("ID", listening.ID)).UniqueResult <ListeningEntity>(); if (dataEntity != null) { session.Delete(dataEntity); tx.Commit(); } result = true; } catch (Exception ex) { Logger.Write(ex); tx.Rollback(); } finally { session.Close(); tx.Dispose(); } return(result); }
public bool SaveListening(Listening listening) { bool result = false; ISession session = SessionFactory.GetSession(); ITransaction tx = session.BeginTransaction(); try { EntityConverter converter = new EntityConverter(); ListeningEntity dataEntity = converter.FromBusinessEntity(listening); session.SaveOrUpdate(dataEntity); tx.Commit(); listening.ID = dataEntity.ID; result = true; } catch (Exception ex) { Logger.Write(ex); tx.Rollback(); } finally { session.Close(); tx.Dispose(); } return(result); }
public ListeningEntity FromBusinessEntity(Listening businessEntity) { if (businessEntity == null) { return(null); } ListeningEntity dataEntity = new ListeningEntity() { ID = businessEntity.ID, ListenRating = businessEntity.ListenRating, PrivateMarks = businessEntity.PrivateMarks, Review = businessEntity.Review, Comments = businessEntity.Comments, Date = businessEntity.Date, Album = new AlbumEntity() { ID = businessEntity.Album.ID }, Mood = FromBusinessEntity(businessEntity.Mood), Place = FromBusinessEntity(businessEntity.Place) }; return(dataEntity); }
public IPagedList <Listening> GetListenings(ILoadOptions options) { IPagedList <Listening> result = new PagedList <Listening>(); if (options == null) { return(result); } if (options.MaxResults <= 0) { return(result); } ISession session = SessionFactory.GetSession(); try { DetachedCriteria countCriteria = GetListeningsImpl(options); DetachedCriteria listCriteria = GetListeningsImpl(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) { ListeningEntity dataEntity = e as ListeningEntity; Listening businessEntity = entityConverter.FromDataEntity(dataEntity); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public Listening FromDataEntity(ListeningEntity dataEntity) { if (dataEntity == null) { return(null); } Listening businessEntity = new Listening() { ID = dataEntity.ID, Date = dataEntity.Date, ListenRating = dataEntity.ListenRating, PrivateMarks = dataEntity.PrivateMarks, Review = dataEntity.Review, Comments = dataEntity.Comments }; businessEntity.Album = FromDataEntity(dataEntity.Album, AlbumConvertOptions.Small); businessEntity.Mood = FromDataEntity(dataEntity.Mood, MoodConvertOptions.Short); businessEntity.Place = FromDataEntity(dataEntity.Place, PlaceConvertOptions.Short); return(businessEntity); }