//by JuSNS v1.0系列
//官方站：www.juSNS.com，演示站:www.ju001.com，www.julala.cn
//QQ:655071(技术)，QQ:9170617（客服）
//MSN:simplt@163.com EMail:simplt@163.com
//program design by Simplt.Xie，arjun
//========================================
using System;
using System.Collections.Generic;
using System.Text;
using JuSNS.Model;
using JuSNS.Common;
using JuSNS.Factory;

namespace JuSNS.Home
{
    /// <summary>
    /// 相册类
    /// </summary>
    public class Album
    {
        private IAlbum dal;

        /// <summary>
        /// 构造函数
        /// </summary>
        public Album()
        {
            dal = DataAccess.CreateAlbum();
        }

        /// <summary>
        /// 添加相册
        /// </summary>
        /// <param name="Info">相册实体类</param>
        /// <returns>添加成功返回1</returns>
        public int Add(AlbumInfo Info)
        {
            return dal.Add(Info);
        }

        /// <summary>
        /// 修改相册信息
        /// </summary>
        /// <param name="Info">相册实体类</param>
        /// <returns>修改成功返回1</returns>
        public int Edit(AlbumInfo Info)
        {
            return dal.Edit(Info);
        }

        /// <summary>
        /// 删除相册(后台)
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <returns>删除成功返回1</returns>
        public int Del(int AlbumID)
        {
            //同时删除物理文件
            Photo p = new Photo();
            List<PhotoInfo> listinfo = p.InfoList(AlbumID, 0);
            for (int i = 0; i < listinfo.Count; i++)
            {
                PhotoInfo pi = listinfo[i];
                if (pi.PhotoType == 1)
                {
                    Public.DelFile(pi.FilePath, 1);
                }
                else if (pi.PhotoType == 0)
                {
                    Public.DelFile(pi.FilePath, 0);
                }
            }
            int n = dal.Del(AlbumID);
            return n;
        }

        /// <summary>
        /// 删除相册(前台)
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <param name="UserID">会员编号</param>
        /// <returns>删除成功返回1</returns>
        public int Del(int AlbumID, int UserID)
        {
            //同时删除物理文件
            Photo p = new Photo();
            List<PhotoInfo> listinfo = p.InfoList(AlbumID, UserID);
            for (int i = 0; i < listinfo.Count; i++)
            {
                PhotoInfo pi = listinfo[i];
                if (pi.PhotoType == 1)
                {
                    Public.DelFile(pi.FilePath, 1);
                }
                else if (pi.PhotoType == 0)
                {
                    Public.DelFile(pi.FilePath, 0);
                }
            }
            int n = dal.Del(AlbumID, UserID);
            return n;
        }

        /// <summary>
        /// 取得相册照片记录数
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <returns>返回照片记录数</returns>
        public int Count(int AlbumID)
        {
            return dal.Count(AlbumID);
        }

        /// <summary>
        /// 取得相册下属相册所有相片路径
        /// </summary>
        /// <param name="AlubmID">相册编号</param>
        /// <returns>返回编号</returns>
        private string A_s_PPath(int AlubmID)
        {
            return dal.A_s_PPath(AlubmID);
        }

        /// <summary>
        /// 相册信息
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <returns>返回相册实体类</returns>
        public AlbumInfo Info(int AlbumID)
        {
            return dal.Info(AlbumID);
        }

        /// <summary>
        /// 获取指定用户相册集
        /// </summary>
        /// <param name="UserID">用户编号</param>
        /// <returns>返回相册实体类集合</returns>
        public List<AlbumInfo> AlbumList(int UserID)
        {
            return dal.AlbumList(UserID);
        }
        /// <summary>
        /// 取得好友最新相册
        /// </summary>
        /// <param name="UserID">用户名</param>
        /// <returns></returns>
        public List<AlbumInfo> FriendAlbumList(int UserID)
        {
            return dal.FriendAlbumList(UserID);
        }

        /// <summary>
        /// 获取指定用户最新相册ID
        /// </summary>
        /// <param name="UserID">用户编号</param>
        /// <returns>相册ID</returns>
        public int LastAlbumID(int UserID)
        {
            return dal.LastAlbumID(UserID);
        }
        /// <summary>
        /// 封面图片路径
        /// </summary>
        /// <param name="AlbumID">相册ID</param>
        /// <returns></returns>
        public string CoverPath(int AlbumID)
        {
            string returnPath = dal.CoverPath(AlbumID);
            if (string.IsNullOrEmpty(returnPath))
            {
                return "/template/" + JuSNS.Config.UiConfig.SkinStyle + "/images/000.jpg";
            }
            return returnPath;
        }

        /// <summary>
        /// 取得群组最新相册
        /// </summary>
        /// <param name="UserID">群组ID</param>
        /// <returns></returns>
        public List<AlbumInfo> GroupAlbumList(int GroupID)
        {
            return dal.GroupAlbumList(GroupID);
        }
    }
}
