public object Cancel(int requestId) { var request = uow.RequestRepository.Get(r => r.id == requestId, includeProperties: "ExamRequests.Exam").FirstOrDefault(); if (request != null) { request.statusId = RequestStatus.CodeApprovedPendingExam; var er = request.ExamRequests.FirstOrDefault(r => r.Exam.courseId == request.courseId && (r.dateCancelled == null || r.dateApplied > r.dateCancelled)); if (er != null) { er.dateCancelled = DateTime.UtcNow; var log = new RequestLog { createdById = CurrentUser.id, dateCreated = DateTime.UtcNow, requestId = request.id, requestStatusId = request.statusId, Description = $"Korisnik {CurrentUser.name} {CurrentUser.surname} je odjavio obranu iz predmeta {request.Course.name}. Datum obrane: {Utilities.GetUserTime(er.Exam.examDateTime)?.ToString("dd.MM.yyyy HH:mm")}", requestChanged = true }; uow.RequestLogRepository.Insert(log); uow.Save(); uow.RequestRepository.LoadReference(request, "Status"); log.CreatedBy = CurrentUser; log.Request = request; SendMailForRequest(request, $"Odjavljena obrana - {CurrentUser.name} {CurrentUser.surname} - {request.Course.shortname}", log.Description); return(new { exam = GetUIObject(er.Exam), log = RequestController.GetLogUIObject(log) }); } } return(null); }
public object Apply(int examId) { var userid = CurrentUser.id; var exam = uow.ExamRepository.Get(e => e.id == examId, includeProperties: "Requests").FirstOrDefault(); if (exam != null) { var existing = uow.ExamRepository.Get(e => e.Requests.Any(r => r.Request.statusId != RequestStatus.PassedExam && r.Request.courseId == exam.courseId && r.Request.createdById == userid && (r.dateCancelled == null || r.dateApplied > r.dateCancelled)), includeProperties: "Requests.Request").ToList(); if (existing.Count > 0 && existing.Count(e => e.id != examId) > 0) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Već ste prijavljeni na drugi ispit iz ovog predmeta.") }); } var request = uow.RequestRepository.Get(r => r.createdById == CurrentUser.id && r.courseId == exam.courseId && r.statusId == RequestStatus.CodeApprovedPendingExam, includeProperties: "Course").FirstOrDefault(); if (request != null) { request.statusId = RequestStatus.ExamTimeSlotDecided; var er = exam.Requests.FirstOrDefault(r => r.requestId == request.id); if (er == null) { er = new ExamRequest { examId = examId, requestId = request.id, dateApplied = DateTime.UtcNow }; exam.Requests.Add(er); } else { er.dateApplied = DateTime.UtcNow; } var log = new RequestLog { createdById = CurrentUser.id, dateCreated = DateTime.UtcNow, requestId = request.id, requestStatusId = request.statusId, Description = $"Korisnik {CurrentUser.name} {CurrentUser.surname} je prijavio obranu iz predmeta {request.Course.name}. Datum obrane: {Utilities.GetUserTime(exam.examDateTime)?.ToString("dd.MM.yyyy HH:mm")}", requestChanged = true }; uow.RequestLogRepository.Insert(log); uow.Save(); uow.RequestRepository.LoadReference(request, "Status"); request.examDateTime = exam.examDateTime; log.CreatedBy = CurrentUser; log.Request = request; SendMailForRequest(request, $"Prijavljena obrana - {CurrentUser.name} {CurrentUser.surname} - {request.Course.shortname}", log.Description); return(new { exam = GetUIObject(exam), log = RequestController.GetLogUIObject(log) }); } } return(null); }