UserServices.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Utility;
  7. using Bowin.Common.Linq;
  8. using EMISOnline.DataLogic.SystemDAL;
  9. using EMISOnline.ViewModel;
  10. using EMISOnline.Entities;
  11. using EMISOnline.ViewModel.SystemView;
  12. using EMISOnline.DataLogic.Repositories;
  13. using EMISOnline.DataLogic.Student;
  14. namespace EMISOnline.CommonLogic.SystemServices
  15. {
  16. public class UserServices : BaseServices, IUserServices
  17. {
  18. public UserDAL UserDAL { get; set; }
  19. public LoginCountRepository loginCountRepository { get; set; }
  20. public SchoolyearDAL schoolyearDAL { get; set; }
  21. public bool Login(string loginID, string password)
  22. {
  23. var encryptPassword = Bowin.Common.Utility.StringEx.MD5(password);
  24. return UserDAL.UserRepository.Entities.Any(u => u.RecordStatus == (int)SYS_STATUS.USABLE && u.LoginID == loginID && u.Password == encryptPassword);
  25. }
  26. public UserView GetUserByLoginID(string loginID, bool isNeedEnable = true)
  27. {
  28. Expression<Func<Sys_User, bool>> user = p => p.LoginID == loginID.Trim();
  29. if (isNeedEnable)
  30. {
  31. user = user.And(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. }
  33. var UserView=UserDAL.GetUserView(user, (x => true)).FirstOrDefault();
  34. var curSchoolyear=schoolyearDAL.GetCurSchoolyear();
  35. var logincout=loginCountRepository.GetSingle(w => w.UserID == UserView.UserID && w.SchoolyearID == curSchoolyear.SchoolyearID);
  36. if (logincout == null)
  37. {
  38. loginCountRepository.UnitOfWork.Add(new Sys_LoginCount()
  39. {
  40. UserID = UserView.UserID,
  41. SchoolyearID = curSchoolyear.SchoolyearID,
  42. lastLoginTime = DateTime.Now,
  43. LoginCount = 1
  44. });
  45. loginCountRepository.UnitOfWork.SaveChanges();
  46. }
  47. else
  48. {
  49. //超过1天才能计算登陆次数
  50. if ((DateTime.Now - logincout.lastLoginTime.Value).TotalDays >= 1)
  51. {
  52. logincout.LoginCount = +1;
  53. logincout.lastLoginTime = DateTime.Now;
  54. loginCountRepository.UnitOfWork.Update(logincout);
  55. loginCountRepository.UnitOfWork.SaveChanges();
  56. }
  57. }
  58. return UserView;
  59. }
  60. public void BatchInitPassword(IList<Guid?> userID)
  61. {
  62. if (userID.Count > 0)
  63. {
  64. UnitOfWork.Update<Sys_User>(
  65. x => new Sys_User { Password = ("A" + x.LoginID).MD5() },
  66. x => userID.Contains(x.UserID)
  67. );
  68. }
  69. }
  70. //public IList<ViewModel.SystemView.RoleView> GetUserRolesView(Guid userID)
  71. //{
  72. // throw new NotImplementedException();
  73. //}
  74. //public string GetUserEmail(Guid userID)
  75. //{
  76. // throw new NotImplementedException();
  77. //}
  78. //public void ChangePassword(ViewModel.SystemView.ChangePasswordView password, Guid userID)
  79. //{
  80. // throw new NotImplementedException();
  81. //}
  82. public Entities.Sys_User GetUserByID(Guid userID)
  83. {
  84. return this.UserDAL.UserRepository.Entities.Where(x => x.UserID == userID).FirstOrDefault();
  85. }
  86. public IList<Sys_Role> GetUserRoles(Guid userID)
  87. {
  88. var roleList = this.UserDAL.GetUserRoles(x => x.UserID == userID, (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)).ToList();
  89. return roleList;
  90. }
  91. }
  92. }