Esempio n. 1
0
 public IActionResult Upload(UploadXmlFileModel model)
 {
     if (null == model)
     {
         model = new UploadXmlFileModel {
             Error = Error.NoErrors
         }
     }
     ;
     return(View(model));
 }
Esempio n. 2
0
        public IActionResult Upload(IFormFile file)
        {
            var xmlFileModel = new UploadXmlFileModel {
                XmlQuestion = file
            };

            if (null == file)
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.NullFile));
            }
            if (!xmlFileModel.IsXml())
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.NonXmlFile));
            }
            if (xmlFileModel.IsEmpty())
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.EmptyFile));
            }
            if (!xmlFileModel.IsWellFormattedXml())
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.XmlBadFormed));
            }
            if (!xmlFileModel.HasOnlyOneQuestion())
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.ZeroOrMoreQuestions));
            }
            if (!xmlFileModel.HasQuestionText())
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.ZeroOrMoreQuestions));
            }
            if (!xmlFileModel.HasAnswer())
            {
                return(SetErrorAndReturnToView(xmlFileModel, Error.ZeroAnswers));
            }
            xmlFileModel.TakeParameters();

            HttpContext.Session.SetString(SessionNameFieldConst.SessionXmlDocument, xmlFileModel.XmlFile.OuterXml);
            HttpContext.Session.SetObjectAsJson(SessionNameFieldConst.SessionQuestionList, xmlFileModel.QuestionParametersList);
            HttpContext.Session.SetObjectAsJson(SessionNameFieldConst.SessionAnswerList, xmlFileModel.AnswerParametersList);

            return(View(PathToSummaryPageView, xmlFileModel));
        }
Esempio n. 3
0
 private IActionResult SetErrorAndReturnToView(UploadXmlFileModel model, Error error)
 {
     model.Error = error;
     return(View(PathToRandomQuestionView, model));
 }