UserService.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. using OrderSystem.Entity;
  6. using OrderSystem.Entity.ViewModel;
  7. using System.Linq.Expressions;
  8. using Bowin.Common.Linq.Entity;
  9. using OrderSystem.Entity.ViewModel.SystemSetting;
  10. using Bowin.Common.Linq;
  11. using System.Threading.Tasks;
  12. using Microsoft.EntityFrameworkCore;
  13. using System.Security.Cryptography;
  14. using Microsoft.VisualBasic;
  15. using Z.EntityFramework.Plus;
  16. using OrderSystem.Entity.Extensions;
  17. using Bowin.Common.Utility;
  18. using OrderSystem.Services.Common;
  19. namespace OrderSystem.Services.SystemSetting
  20. {
  21. public class UserService : IUserService
  22. {
  23. private OrderSystemContext DbContext { get; set; }
  24. public UserService(OrderSystemContext dbContext)
  25. {
  26. DbContext = dbContext;
  27. }
  28. public LoginUser GetLoginUserById(string mobile, string contractNo)
  29. {
  30. var sql = from u in DbContext.CVxIdClientPhoneMerge
  31. where u.ClientPhoneNo == mobile && u.ContractNo == contractNo
  32. select new LoginUser
  33. {
  34. UserID = u.ClientPhoneNo,
  35. UserName = u.ClientName,
  36. Mobile = u.ClientPhoneNo
  37. };
  38. return sql.FirstOrDefault();
  39. }
  40. public LoginUser GetLoginUserByVxId(string openID)
  41. {
  42. var sql = from u in DbContext.CVxIdClientPhoneMerge
  43. where u.VxId == openID
  44. select new LoginUser
  45. {
  46. UserID = u.ClientPhoneNo,
  47. UserName = u.ClientName,
  48. Mobile = u.ClientPhoneNo
  49. };
  50. return sql.FirstOrDefault();
  51. }
  52. public LoginUser GetUserById(string userID)
  53. {
  54. var sql = from u in DbContext.CVxIdClientPhoneMerge
  55. where u.ClientPhoneNo == userID
  56. select new LoginUser
  57. {
  58. UserID = u.ClientPhoneNo,
  59. UserName = u.ClientName,
  60. Mobile = u.ClientPhoneNo
  61. };
  62. return sql.FirstOrDefault();
  63. }
  64. public int UpdateUserOpenID(string userID, string openID) {
  65. /*var list = DbContext.CVxIdClientPhoneMerge.Where(e => e.ClientPhoneNo == userID).ToList();
  66. list.ForEach(item =>
  67. {
  68. item.VxId = openID;
  69. this.DbContext.CVxIdClientPhoneMerge.Update(item);
  70. });*/
  71. this.DbContext.Database.SqlQuery<CVxIdClientPhoneMerge>($"update C_VxIdClientPhoneMerge set VxId='{openID}' where ClientPhoneNo = '{userID}'", null);
  72. return this.DbContext.SaveChanges();
  73. }
  74. }
  75. }