using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //using System.Web.Mvc; using Song.Entities; using Song.ServiceInterfaces; using Song.ViewData.Attri; using WeiSha.Common; namespace Song.ViewData.Methods { /// /// 管理账号 /// [HttpGet] public class Account : IViewAPI { /// /// 根据ID查询学员账号 /// /// 为了安全,返回的对象密码不显示 /// /// 学员账户的映射对象 public Song.Entities.Accounts ForID(int id) { Song.Entities.Accounts acc= Business.Do().AccountsSingle(id); return _tran(acc); } /// /// 当前登录的学员 /// /// 登录状态通过cookies或session保持 /// [Student] public Song.Entities.Accounts Current() { Song.Entities.Accounts acc = Extend.LoginState.Accounts.CurrentUser; return _tran(acc); } /// /// 根据账号获取学员,不支持模糊查询 /// /// 学员账号 /// public Song.Entities.Accounts ForAcc(string acc) { if (string.IsNullOrWhiteSpace(acc)) throw new Exception("学员账号不得为空"); Song.Entities.Accounts account = Business.Do().AccountsSingle(acc, -1); return _tran(account); } /// /// 根据学员名称获取学员信息,支持模糊查询 /// /// 学员名称 /// public Song.Entities.Accounts[] ForName(string name) { if (string.IsNullOrWhiteSpace(name)) throw new Exception("学员名称不得为空"); Song.Entities.Accounts[] accs= Business.Do().Account4Name(name); if (accs == null) return accs; for (int i = 0; i < accs.Length; i++) { accs[i] = _tran(accs[i]); } return accs; } /// /// 按账号和姓名查询学员 /// /// 学员账号 /// 姓名,可模糊查询 /// public Song.Entities.Accounts[] Seach(string acc, string name) { List list = new List(); Song.Entities.Accounts[] accs = Business.Do().Account4Name(name); foreach (Song.Entities.Accounts ac in accs) list.Add(ac); Song.Entities.Accounts account = Business.Do().AccountsSingle(acc, -1); if (account != null) { bool isExist = false; foreach (Song.Entities.Accounts ac in accs) { if (ac.Ac_ID == account.Ac_ID) { isExist = true; break; } } if (!isExist) list.Add(account); } // for (int i = 0; i < list.Count; i++) { list[i] = _tran(list[i]); } return list.ToArray(); } /// /// 从学习记录中获取学员记录 /// /// 学员账号 /// 学员姓名 /// public Song.Entities.LogForStudentStudy[] ForLogs(string acc, string name) { string sql = @"select Ac_ID,Ac_AccName, Ac_Name from ( select logs.* from Accounts right join (select * from LogForStudentStudy where {name} and {acc}) as logs on Accounts.Ac_ID=Logs.Ac_ID) as tm group by Ac_ID,Ac_AccName,Ac_Name"; sql = sql.Replace("{name}", string.IsNullOrWhiteSpace(name) ? "1=1" : "Ac_Name like '%" + name + "%'"); sql = sql.Replace("{acc}", string.IsNullOrWhiteSpace(acc) ? "1=1" : "Ac_AccName='" + acc + "'"); Song.Entities.LogForStudentStudy[] accs = Business.Do().ForSql(sql).ToArray(); return accs; } /// /// 学员的视频学习记录 /// /// 学员id /// 课程id /// public Song.Entities.LogForStudentStudy[] StudyLog(int acid, int couid) { return Business.Do().LogForStudyCount(-1, couid, -1, acid, null, 0); } /// /// 分页获取学员信息 /// /// 页码,即第几页 /// 每页多少条记录 /// public ListResult Pager(int index, int size) { int sum = 0; Song.Entities.Accounts[] accs = Business.Do().AccountsPager(-1, size, index, out sum); for (int i = 0; i < accs.Length; i++) { accs[i] = _tran(accs[i]); } Song.ViewData.ListResult result = new ListResult(accs); result.Index = index; result.Size = size; result.Total = sum; return result; } #region 私有方法,处理学员信息 /// /// 处理学员信息,密码清空、头像转为全路径,并生成clone对象 /// /// 学员账户的clone对象 /// private Song.Entities.Accounts _tran(Song.Entities.Accounts acc) { if (acc == null) return acc; Song.Entities.Accounts curr = acc.Clone(); if (curr != null) curr.Ac_Pw = string.Empty; curr.Ac_Photo = WeiSha.Common.Upload.Get["Accounts"].Virtual + curr.Ac_Photo; return curr; } #endregion } }