ProjectController.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity;
  9. using wispro.sp.share;
  10. namespace wispro.sp.api.Controllers
  11. {
  12. [Route("api/[controller]/[action]")]
  13. [ApiController]
  14. public class ProjectController : ControllerBase
  15. {
  16. spDbContext Context;
  17. public ProjectController(spDbContext context)
  18. {
  19. Context = context;
  20. }
  21. public List<ProjectInfo> GetProjects(int state)
  22. {
  23. return Context.ProjectInfos
  24. .Include(p => p.Customer)
  25. .Include(p=>p.Reviewer)
  26. .Include(p => p.WorkflowUser)
  27. .Where(s => s.CaseState == state).ToList();
  28. }
  29. public List<ProjectInfo> GetAll()
  30. {
  31. var retList = Context.ProjectInfos
  32. .Include(p => p.Customer)
  33. .Include(p => p.Reviewer)
  34. .Include(p => p.WorkflowUser)
  35. .ToList();
  36. return retList;
  37. }
  38. public bool SetFinished(string caseNo)
  39. {
  40. var obj = Context.ProjectInfos.FirstOrDefault(s=>s.CaseNo == caseNo );
  41. if(obj != null)
  42. {
  43. try
  44. {
  45. obj.CaseState = 4;
  46. Context.SaveChanges();
  47. return true;
  48. }
  49. catch(Exception ex)
  50. {
  51. return false;
  52. }
  53. }
  54. else
  55. {
  56. return false;
  57. }
  58. }
  59. public List<ProjectContentRecord> GetMyProjects()
  60. {
  61. return Context.ProjectContentRecords
  62. .Include(p=>p.CalMonth)
  63. .Include(p => p.Reviewer)
  64. .Include(p => p.Project)
  65. .Include(p=>p.ProjectWorkContents)
  66. .Where(p => p.Staff.Name == User.Identity.Name).ToList();
  67. }
  68. public ProjectContents getProjectWorkContent(int Id)
  69. {
  70. var retObj = Context.ProjectContentRecords
  71. .Include(p => p.CalMonth)
  72. .Include(p => p.Reviewer)
  73. .Include(p => p.Project)
  74. .Include(p => p.ProjectWorkContents)
  75. .FirstOrDefault(p=>p.Id == Id);
  76. if(retObj != null)
  77. {
  78. ProjectContents ret = new ProjectContents();
  79. ret.ProjectContentRecord = retObj;
  80. ret.ProjectWorkContents = new List<ViewProjectWorkContent>();
  81. foreach(var wContent in retObj.ProjectWorkContents)
  82. {
  83. ViewProjectWorkContent tem = new ViewProjectWorkContent();
  84. tem.modifyState = ModifyState.UnChanged;
  85. tem.Content = wContent.Content;
  86. tem.ActualPerformance = wContent.ActualPerformance;
  87. tem.ContentRecordId = wContent.ContentRecordId;
  88. tem.FinalPerformance = wContent.FinalPerformance;
  89. tem.TakeTime = wContent.TakeTime;
  90. tem.TimeSpan = wContent.TimeSpan;
  91. tem.WorkDate = wContent.WorkDate;
  92. ret.ProjectWorkContents.Add(tem);
  93. }
  94. return ret;
  95. }
  96. return null;
  97. }
  98. public ApiSaveResponse SaveProjectWorkContent(ProjectContents saveObj)
  99. {
  100. return null;
  101. }
  102. }
  103. }