Guest User

Untitled

a guest
Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public class ProjectTypeDTO {
  2. public string Type { get; set; }
  3. }
  4.  
  5. public class CourseDTO {
  6. public string CourseCode { get; set; }
  7. public string CourseTitle { get; set; }
  8. }
  9.  
  10. public class ProjectDTO {
  11. public int Id { get; set; }
  12. public ProjectTypeDTO ProjectType { get; set; }
  13. public CourseDTO Course { get; set; }
  14. public string StartTerm { get; set; }
  15. public DateTime SignOff { get; set; }
  16. public DateTime StartDateTime { get; set; }
  17. }
  18.  
  19. [HttpGet("getallprojects")]
  20. public IActionResult GetAllProjects()
  21. {
  22. var projects = _context.Projects
  23. .Select(p => new ProjectDTO
  24. {
  25. Id = p.Id,
  26. ProjectType = { Type = p.ProjectType.Type },
  27. Course = { CourseCode = p.Course.CourseCode, CourseTitle = p.Course.CourseTitle },
  28. StartTerm = p.StartTerm,
  29. SignOff = p.SignOff,
  30. StartDateTime = p.StartDateTime,
  31. }).ToList();
  32.  
  33. return Ok(projects);
  34. }
  35.  
  36. var projects = _context.Projects
  37. .Select(p => new
  38. {
  39. p.Id,
  40. p.ProjectType.Type,
  41. p.SignOff,
  42. p.StartDateTime,
  43. p.Course.CourseCode,
  44. p.Course.CourseTitle,
  45. p.StartTerm
  46. }).ToList();
Add Comment
Please, Sign In to add comment