Пример #1
0
        public HttpResponseMessage Get(string id)
        {
            try
            {
                if (id == null || id == "")
                {
                    NLogConfig.logger.Error("Invalid examID");
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid examID"));
                }

                WCF.ExamTemplate template = client.getExamTemplate(id);
                NLogConfig.logger.Log(new LogEventInfo(LogLevel.Info, "WebAPILogger", $"Retreived {id} exam template"));
                return(Request.CreateResponse(HttpStatusCode.OK, template));
            }
            catch (System.ServiceModel.FaultException ex)
            {
                NLogConfig.logger.Error(ex, "This exam template does not exist.");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "This exam template does not exist."));
            }
            catch (Exception ex)
            {
                NLogConfig.logger.Error(ex, ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Пример #2
0
        public HttpResponseMessage GetExamSubjects(string id)
        {
            try
            {
                List <WCF.Subject> sub      = client.GetAllSubject().ToList(); // all the subjects
                List <WCF.Subject> result   = new List <WCF.Subject>();        // the results of the subjects
                WCF.ExamTemplate   template = client.getExamTemplate(id);

                foreach (var subject in sub)
                {
                    bool foundSubject = false;
                    foreach (var subjectcategory in subject.listCat)
                    {
                        foreach (var examquestion in template.ExamQuestions)
                        {
                            foreach (var category in examquestion.ExamQuestion_Categories)
                            {
                                if (subjectcategory.Categories_ID == category.Categories_ID)
                                {
                                    if (foundSubject == false)
                                    {
                                        result.Add(subject);
                                        foundSubject = true;
                                        NLogConfig.logger.Log(new LogEventInfo(LogLevel.Info, "WebAPILogger", $"{subject.Subject_Name} is a subject in the {id} exam template"));
                                    }
                                }
                            }
                        }
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, result.Distinct().ToList()));
            }
            catch (System.ServiceModel.FaultException ex)
            {
                NLogConfig.logger.Error(ex, "There is no exam template with this ID. Enter a correct exam template ID.");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "There is no exam template with this ID. Enter a correct exam template ID."));
            }
            catch (Exception ex)
            {
                NLogConfig.logger.Error(ex, ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Пример #3
0
 public HttpResponseMessage AddExam([FromBody] WCF.ExamTemplate exam)
 {
     try
     {
         if (exam == null || exam.ExamTemplateID == null || exam.ExamTemplateID == "" || exam.ExamTemplateName == null || exam.ExamTemplateName == "")
         {
             NLogConfig.logger.Error("Invalid Exam Template.");
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Exam Template"));
         }
         client.AddNewExam(exam.ExamTemplateName, exam.ExamTemplateID, exam.ExamType.ExamTypeName);
         NLogConfig.logger.Log(new LogEventInfo(LogLevel.Info, "WebAPILogger", $"{exam.ExamTemplateID} was added as an exam template."));
         return(Request.CreateResponse(HttpStatusCode.OK, "Template Added"));
     }
     catch (Exception ex)
     {
         NLogConfig.logger.Error(ex, "Invalid Exam Template");
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }