public HttpResponseMessage GetNotificationsByTeacherId(GetNotificationsByTeacherIdRequest request) { var responseModel = _businessLogic.GetNotificationsByTeacherId(request); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(responseModel), Encoding.UTF8, "application/json");; return(response); }
public GetNotificationsByTeacherIdResponse GetNotificationsByTeacherId(GetNotificationsByTeacherIdRequest request) { GetNotificationsByTeacherIdResponse response = new GetNotificationsByTeacherIdResponse(); var twoDaysBefore = DateTime.Now.Date.AddDays(-2); var notificationList = _context.Schedules .Where(s => s.TeacherId == request.UserId && s.ReportStatus == "Reported" && s.Date >= twoDaysBefore) .Select(s => new { ScheduleId = s.ScheduleId, ClassId = s.Class.ClassId, ClassName = s.Class.ClassName, StudentId = s.StudentId, CourseId = s.CourseId, CourseName = s.Course.CourseName, SlotId = s.SlotId, StartTime = s.Slot.StartTime, EndTime = s.Slot.EndTime, Date = s.Date }) .Select(s => new NotificationInfo() { ScheduleId = s.ScheduleId, Classes = new ClassDto() { ClassId = s.ClassId, ClassName = s.ClassName }, StudentId = s.StudentId, Course = new CourseDto() { CourseId = s.CourseId, CourseName = s.CourseName }, Slot = new SlotDto() { SlotId = s.SlotId, StartTime = s.StartTime, EndTime = s.EndTime }, Date = SqlFunctions.DateName("day", s.Date) + "/" + SqlFunctions.DateName("month", s.Date) + "/" + SqlFunctions.DateName("year", s.Date) }).ToList(); response.Notifications = notificationList; return(response); }