SycnJavaUsersService.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.PxcModels;
  5. using Library;
  6. using LitJson;
  7. using System.Threading;
  8. namespace MySystem
  9. {
  10. public class SycnJavaUsersService
  11. {
  12. public readonly static SycnJavaUsersService Instance = new SycnJavaUsersService();
  13. private SycnJavaUsersService()
  14. { }
  15. public bool Add(string content)
  16. {
  17. try
  18. {
  19. JsonData jsonObj = JsonMapper.ToObject(content);
  20. WebCMSEntities db = new WebCMSEntities();
  21. int id = int.Parse(jsonObj["id"].ToString());
  22. string pidPath = jsonObj["pidPath"].ToString();
  23. pidPath = "," + pidPath.Substring(1).Replace(",",",,").Trim(',') + ",";
  24. int pid = int.Parse(jsonObj["pid"].ToString());
  25. DateTime CreateDate = DateTime.Parse(jsonObj["createTime"].ToString());
  26. string MakerCode = jsonObj["userCode"].ToString();
  27. string Mobile = jsonObj["phone"].ToString();
  28. Users add = db.Users.Add(new Users()
  29. {
  30. Id = id,
  31. ParentUserId = pid,
  32. ParentNav = pidPath,
  33. CreateDate = CreateDate,
  34. MakerCode = MakerCode,
  35. Mobile = Mobile,
  36. }).Entity;
  37. db.SaveChanges();
  38. db.UserForMobile.Add(new UserForMobile()
  39. {
  40. Mobile = Mobile,
  41. UserId = add.Id
  42. });
  43. db.UserForMakerCode.Add(new UserForMakerCode()
  44. {
  45. MakerCode = MakerCode,
  46. UserId = add.Id
  47. });
  48. db.SaveChanges();
  49. db.Dispose();
  50. return true;
  51. }
  52. catch (Exception ex)
  53. {
  54. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步创客信息异常");
  55. return false;
  56. }
  57. }
  58. }
  59. }