123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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<Func<Sys_User, bool>> 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<Guid?> userID)
- {
- if (userID.Count > 0)
- {
- UnitOfWork.Update<Sys_User>(
- x => new Sys_User { Password = ("A" + x.LoginID).MD5() },
- x => userID.Contains(x.UserID)
- );
- }
- }
- //public IList<ViewModel.SystemView.RoleView> 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<Sys_Role> GetUserRoles(Guid userID)
- {
- var roleList = this.UserDAL.GetUserRoles(x => x.UserID == userID, (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)).ToList();
- return roleList;
- }
- }
- }
|