Example #1
0
        public List <PhotosBO> CountPhotosInAlbum(DataTable photos)
        {
            List <PhotosBO> count = new List <PhotosBO>();
            //hold on to unique ids
            List <long> albumIds = new List <long>();

            //Take album id from each row and store into list.
            foreach (DataRow id in photos.Rows)
            {
                albumIds.Add((long)id["AlbumId"]);
            }
            //filter any non-unique ids.
            albumIds = albumIds.Distinct().ToList();

            //Count how many photos are attatched to the id.
            foreach (long id in albumIds)
            {
                //filtering photos by album id.
                var results = from myRow in photos.Rows.Cast <DataRow>()
                              where myRow.Field <long>("AlbumId") == id
                              select myRow;

                PhotosBO photo = new PhotosBO();
                photo.AlbumId    = id;
                photo.PhotoCount = results.Count <DataRow>();

                count.Add(photo);
            }

            return(count);
        }
        public static PhotosBO MapPoToBO(AlbumPO from)
        {
            PhotosBO to = new PhotosBO();

            try
            {
                to.AlbumId    = from.AlbumId;
                to.PhotoCount = from.PhotoCount;
            }
            catch (Exception e)
            {
                throw e;
            }
            return(to);
        }
        /// <summary>
        /// Mapping a List from the Presentation Layer to Bussines Layer
        /// </summary>
        /// <param name="from">List from the Presentation Layer</param>
        /// <returns></returns>
        public static List <PhotosBO> MapPoToBO(List <AlbumPO> from)
        {
            List <PhotosBO> to = new List <PhotosBO>();

            try
            {
                foreach (AlbumPO item in from)
                {
                    PhotosBO mappedItem = MapPoToBO(item);
                    to.Add(mappedItem);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(to);
        }