//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 Photo
    {
        private IPhoto dal;

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

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

        /// <summary>
        /// 修改照片
        /// </summary>
        /// <param name="Info">照片实体类</param>
        /// <returns>修改成功返回1</returns>
        public int Edit(PhotoInfo Info)
        {
            return dal.Edit(Info);
        }

        /// <summary>
        /// 添加照片被查看次数
        /// </summary>
        /// <param name="PhotoID">相片编号</param>
        /// <returns>添加成功返回1</returns>
        public int AddViews(int PhotoID)
        {
            return dal.AddViews(PhotoID);
        }

        /// <summary>
        /// 添加照片评论次数
        /// </summary>
        /// <param name="PhotoID">相片编号</param>
        /// <returns>添加成功返回1</returns>
        public int AddComm(int PhotoID)
        {
            return dal.AddComm(PhotoID);
        }

        /// <summary>
        /// 取得照片被查看次数
        /// </summary>
        /// <param name="PhotoID">相片编号</param>
        /// <returns>返回查看次数</returns>
        public int ViewsCount(int PhotoID)
        {
            return dal.ViewsCount(PhotoID);
        }

        /// <summary>
        /// 取得照片评论次数
        /// </summary>
        /// <param name="PhotoID">相片编号</param>
        /// <returns>返回照片评论次数</returns>
        public int CommCount(int PhotoID)
        {
            return dal.CommCount(PhotoID);
        }

        /// <summary>
        /// 删除相片(后台)
        /// </summary>
        /// <param name="PhotoID">相片编号</param>
        /// <returns>删除成功返回1</returns>
        public int Del(int PhotoID)
        {
            PhotoInfo info = new PhotoInfo();
            info = Info(PhotoID);
            int n = dal.Del(PhotoID);
            if (n == 1)
            {
                if (info.PhotoType == 1)
                {
                    Public.DelFile(info.FilePath,1);
                }
                else if (info.PhotoType == 0)
                {
                    Public.DelFile(info.FilePath,0);
                }
            }
            return n;
        }

        /// <summary>
        /// 删除照片(前台)
        /// </summary>
        /// <param name="PhotoID">照片编号</param>
        /// <param name="UploadUser">照片上传者编号</param>
        /// <returns></returns>
        public int Del(int PhotoID, int UploadUser)
        {
            PhotoInfo info = new PhotoInfo();
            info = Info(PhotoID);
            //同时删除文件
            if (info.PhotoType == 1)
            {
                Public.DelFile(info.FilePath, 1);
            }
            else
            {
                Public.DelFile(info.FilePath, 0);
            }
            int n = dal.Del(PhotoID, UploadUser);
            if (n == 1)
            {
                string s_Rootpath = ServerInfo.GetRootPath();
                Common.Public.DelFile(s_Rootpath + info.FilePath);
            }
            return n;
        }

        /// <summary>
        /// 取得会员当前头像地址
        /// </summary>
        /// <param name="UserID">会员编号</param>
        /// <returns>返回头像地址</returns>
        public string NonceHead(int UserID)
        {
            return dal.NonceHead(UserID);
        }

        /// <summary>
        /// 照片信息
        /// </summary>
        /// <param name="PhotoID">照片编号</param>
        /// <returns>返回照片实体类</returns>
        public PhotoInfo Info(int PhotoID)
        {
            return dal.Info(PhotoID);
        }

        /// <summary>
        /// 照片信息列表
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <param name="UserID">用户编号</param>
        /// <returns>返回照片集</returns>
        public List<PhotoInfo> InfoList(int AlbumID, int UserID)
        {
            return dal.InfoList(AlbumID,UserID);
        }

        /// <summary>
        /// 照片信息列表
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <returns>返回照片集</returns>
        public List<PhotoInfo> InfoList(int AlbumID)
        {
            return dal.InfoList(AlbumID);
        }
        /// <summary>
        /// 头像照片信息列表
        /// </summary>
        /// <param name="AlbumID">相册编号</param>
        /// <param name="UserID">用户编号</param>
        /// <returns>返回照片集</returns>
        public List<PhotoInfo> HeadInfoList(int AlbumID, int UserID)
        {
            return dal.HeadInfoList(AlbumID, UserID);
        }

        /// <summary>
        /// 同一个相册照片数量
        /// </summary>
        /// <param name="photoID">照片ID</param>
        /// <returns></returns>
        public int PhotoCount(int photoID)
        {
            return dal.PhotoCount(photoID);
        }

        /// <summary>
        /// 同一相册上一张照片ID
        /// </summary>
        /// <param name="photoID">照片ID</param>
        /// <returns></returns>
        public int NextPhotoID(int photoID)
        {
            return dal.NextPhotoID(photoID);
        }
        /// <summary>
        /// 头像像册下一张照片
        /// </summary>
        /// <param name="photoID">照片ID</param>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public int NextPhotoID(int photoID, int UserID)
        {
            return dal.NextPhotoID(photoID, UserID);
        }
        /// <summary>
        /// 同一相册上一张照片ID
        /// </summary>
        /// <param name="photoID">照片ID</param>
        /// <returns></returns>
        public int PrePhotoID(int photoID)
        {
            return dal.PrePhotoID(photoID);
        }
        /// <summary>
        /// 同一相册上一张照片ID,头像相册中
        /// </summary>
        /// <param name="photoID">照片ID</param>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public int PrePhotoID(int photoID, int UserID)
        {
            return dal.PrePhotoID(photoID, UserID);
        }

        /// <summary>
        /// 照片位于相册中的第几张
        /// </summary>
        /// <param name="photoID"></param>
        /// <returns></returns>
        public int TheNumber(int photoID)
        {
            return dal.TheNumber(photoID);
        }
        /// <summary>
        /// 照片位于相册中的第几张,头像相册中
        /// </summary>
        /// <param name="photoID">照片ID</param>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public int TheNumber(int photoID, int UserID)
        {
            return dal.TheNumber(photoID, UserID);
        }
        /// <summary>
        /// 锁定
        /// </summary>
        /// <param name="PhotoID">照片ID</param>
        /// <returns></returns>
        public int Lock(int PhotoID)
        {
            return dal.Lock(PhotoID);
        }        
        /// <summary>
        /// 取消锁定
        /// </summary>
        /// <param name="PhotoID">照片ID</param>
        /// <returns></returns>
        public int unLock(int PhotoID)
        {
            return dal.unLock(PhotoID);
        }

        /// <summary>
        /// 设置封面照片
        /// </summary>
        /// <param name="photoID">相片编号</param>
        /// <param name="UserID">会员编号</param>
        /// <param name="tf">true代表是头像</param>
        public void SetCover(int photoID, int UserID, bool tf)
        {
            dal.SetCover(photoID, UserID, tf);
        }
        /// <summary>
        /// 返回头像数目
        /// </summary>
        /// <param name="PhotoID">照片id</param>
        /// <param name="UserID">用户ID</param>
        /// <returns></returns>
        public int HeadCount(int PhotoID, int UserID)
        {
           return dal.HeadCount(PhotoID,UserID);
        }

        /// <summary>
        /// 群组照片
        /// </summary>
        /// <param name="GroupID">群组ID</param>
        /// <returns></returns>
        public List<PhotoInfo> GroupInfoList(int GroupID)
        {
            return dal.GroupInfoList(GroupID);
        }

    }
}
