using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Utility; using Bowin.Common.Linq; using EMISOnline.DataLogic.SystemDAL; using EMISOnline.ViewModel; using EMISOnline.Entities; using EMISOnline.ViewModel.SystemView; using EMISOnline.DataLogic.Repositories; using EMISOnline.DataLogic.Student; namespace EMISOnline.CommonLogic.SystemServices { public class UserServices : BaseServices, IUserServices { public UserDAL UserDAL { get; set; } public LoginCountRepository loginCountRepository { get; set; } public SchoolyearDAL schoolyearDAL { get; set; } public bool Login(string loginID, string password) { var encryptPassword = Bowin.Common.Utility.StringEx.MD5(password); return UserDAL.UserRepository.Entities.Any(u => u.RecordStatus == (int)SYS_STATUS.USABLE && u.LoginID == loginID && u.Password == encryptPassword); } public UserView GetUserByLoginID(string loginID, bool isNeedEnable = true) { Expression> user = p => p.LoginID == loginID.Trim(); if (isNeedEnable) { user = user.And(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); } var UserView=UserDAL.GetUserView(user, (x => true)).FirstOrDefault(); var curSchoolyear=schoolyearDAL.GetCurSchoolyear(); var logincout=loginCountRepository.GetSingle(w => w.UserID == UserView.UserID && w.SchoolyearID == curSchoolyear.SchoolyearID); if (logincout == null) { loginCountRepository.UnitOfWork.Add(new Sys_LoginCount() { UserID = UserView.UserID, SchoolyearID = curSchoolyear.SchoolyearID, lastLoginTime = DateTime.Now, LoginCount = 1 }); loginCountRepository.UnitOfWork.SaveChanges(); } else { //超过1天才能计算登陆次数 if ((DateTime.Now - logincout.lastLoginTime.Value).TotalDays >= 1) { logincout.LoginCount = +1; logincout.lastLoginTime = DateTime.Now; loginCountRepository.UnitOfWork.Update(logincout); loginCountRepository.UnitOfWork.SaveChanges(); } } return UserView; } public void BatchInitPassword(IList userID) { if (userID.Count > 0) { UnitOfWork.Update( x => new Sys_User { Password = ("A" + x.LoginID).MD5() }, x => userID.Contains(x.UserID) ); } } //public IList GetUserRolesView(Guid userID) //{ // throw new NotImplementedException(); //} //public string GetUserEmail(Guid userID) //{ // throw new NotImplementedException(); //} //public void ChangePassword(ViewModel.SystemView.ChangePasswordView password, Guid userID) //{ // throw new NotImplementedException(); //} public Entities.Sys_User GetUserByID(Guid userID) { return this.UserDAL.UserRepository.Entities.Where(x => x.UserID == userID).FirstOrDefault(); } public IList GetUserRoles(Guid userID) { var roleList = this.UserDAL.GetUserRoles(x => x.UserID == userID, (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)).ToList(); return roleList; } } }