StudentFamilyServices.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Students;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel.Students;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. namespace EMIS.CommonLogic.Students
  12. {
  13. public class StudentFamilyServices : BaseServices, IStudentFamilyServices
  14. {
  15. public StudentFamilyDAL StudentFamilyDAL { get; set; }
  16. public IGridResultSet<StudentFamilyView> GetTopStudentFamilyGridView(Guid userID, int rowCount, int? pageIndex, int? pageSize)
  17. {
  18. Expression<Func<CF_StudentFamily, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  19. && x.UserID == userID);
  20. var result = this.StudentFamilyDAL.GetStudentFamilyViewQueryable(exp).Take(rowCount).ToList();
  21. var newRowCount = rowCount - result.Count;
  22. for (var i = 0; i < newRowCount; i++)
  23. {
  24. result.Add(new StudentFamilyView
  25. {
  26. StudentFamilyID = Guid.NewGuid(),
  27. UserID = userID
  28. });
  29. }
  30. return new GridResultSet<StudentFamilyView> { rows = result, total = result.Count };
  31. }
  32. public void Save(Guid userID, IList<StudentFamilyView> studentFamilyViewList)
  33. {
  34. UnitOfWork.Remove<CF_StudentFamily>(x => x.UserID == userID);
  35. var studentFamilyList = new List<CF_StudentFamily>();
  36. for (int i = 1; i <= studentFamilyViewList.Count; i++)
  37. {
  38. var family = studentFamilyViewList[i - 1];
  39. var studentFamily = new CF_StudentFamily
  40. {
  41. StudentFamilyID = Guid.NewGuid(),
  42. UserID = userID,
  43. Name = family.Name,
  44. Relation = family.Relation,
  45. Age = family.Age,
  46. Politics = family.Politics,
  47. Unit = family.Unit,
  48. PhoneNumber = family.PhoneNumber,
  49. OrderNo = i
  50. };
  51. this.SetNewStatus(studentFamily);
  52. studentFamilyList.Add(studentFamily);
  53. }
  54. UnitOfWork.AddRange(studentFamilyList);
  55. UnitOfWork.Commit();
  56. }
  57. }
  58. }