public async Task <ActionResult> SaveFileAnswer(IFormFile file)
        {
            var questionId          = int.Parse(Request.Form["QuestionId"].ToString());
            var answerId            = int.Parse(Request.Form["Id"]);
            var plannedInspectionId = int.Parse(Request.Form["PlannedInspectionId"].ToString());

            var path    = (await UploadFile(file)).Replace(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\"), "");
            var comment = Request.Form["AnswerContents"].ToString();

            if (answerId != 0)
            {
                var answer = await _questionnaireService.GetAnswer <FileAnswer>(answerId);

                if (answer != null)
                {
                    answer.UploadedFilePath = path;
                    answer.AnswerContents   = comment;
                }

                await _questionnaireService.SaveChangesAsync();
            }
            else
            {
                var fileAnswer = new FileAnswer
                {
                    Question          = await _questionnaireService.GetQuestion(questionId),
                    PlannedInspection = await _questionnaireService.GetPlannedInspection(plannedInspectionId)
                };

                await _questionnaireService.CreateAnswer(fileAnswer);
            }


            return(RedirectToAction("Details", new { id = plannedInspectionId }));
        }
        public async Task <ActionResult> SaveDrawAnswer(FileAnswer fileAnswer)
        {
            var questionId = int.Parse(Request.Form["QuestionId"].ToString());

            if (fileAnswer.Id != 0)
            {
                var answer = await _questionnaireService.GetAnswer <FileAnswer>(fileAnswer.Id);

                if (answer != null)
                {
                    answer.UploadedFilePath = fileAnswer.UploadedFilePath;
                }

                await _questionnaireService.SaveChangesAsync();
            }
            else
            {
                fileAnswer.Question = await _questionnaireService.GetQuestion(questionId);

                fileAnswer.PlannedInspection =
                    await _questionnaireService.GetPlannedInspection(fileAnswer.PlannedInspection.Id);

                fileAnswer = await _questionnaireService.CreateAnswer(fileAnswer) as FileAnswer;
            }


            return(RedirectToAction("Draw", "Draw", new { id = fileAnswer?.Id }));
        }
        private Image CreateImage(FileAnswer answer)
        {
            var image = new Image();

            if (answer.UploadedFilePath == null)
            {
                return(null);
            }


            try
            {
                var baseUri = new Uri(_config["Urls:WebApp"]);
                var source  = new BitmapImage(new Uri(baseUri, answer.UploadedFilePath));

                image.Source = source;
                _imageSources.Add(image, source.UriSource.ToString());
                return(image);
            }

            catch (Exception)
            {
                OpenValidationPopup("Afbeelding is niet gevonden, vraag aan de administrator voor hulp.");
                return(null);
            }
        }
 private void ReadoutAnswers(IEnumerable <Answer> answers)
 {
     foreach (Answer answer in answers)
     {
         _pdfHtml += answer switch
         {
             FileAnswer fileAnswer => $"<p>{GetEmployee(fileAnswer).Name}: {fileAnswer.UploadedFilePath}",
             StringAnswer stringAnswer => $"<p>{GetEmployee(stringAnswer).Name}: {stringAnswer.AnswerContents}</p>",
             NumericAnswer numericAnswer => $"<p>{GetEmployee(numericAnswer).Name}: {numericAnswer.IntAnswer}</p>",
             MultipleChoiceAnswer multiplechoiceAnswer => $"<p>{GetEmployee(multiplechoiceAnswer).Name}: {((MultipleChoiceQuestion)multiplechoiceAnswer.Question).OptionCollection[multiplechoiceAnswer.MultipleChoiceAnswerKey].Value}</p>",
                     _ => ""
         };
     }
 }
Exemplo n.º 5
0
        protected override void Seed(FestispecContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.


            //  context.SaveChanges();

            try
            {
                var address = new Address
                {
                    Id          = 1,
                    StreetName  = "Isolatorweg",
                    HouseNumber = 36,
                    ZipCode     = "1014AS",
                    City        = "Amsterdam",
                    Country     = "Nederland",
                    Latitude    = 52.39399f,
                    Longitude   = 4.8507514f
                };

                var address2 = new Address
                {
                    Id          = 2,
                    Country     = "Duitsland",
                    StreetName  = "Flughafen-Ring",
                    HouseNumber = 16,
                    City        = "Weeze",
                    ZipCode     = "NW47652",
                    Latitude    = 51.5924149f,
                    Longitude   = 6.1545434f
                };

                var address3 = new Address
                {
                    Id          = 3,
                    City        = "Utrecht",
                    Country     = "Nederland",
                    HouseNumber = 59,
                    StreetName  = "Chopinstraat",
                    ZipCode     = "3533EL",
                    Latitude    = 52.0857048f,
                    Longitude   = 5.08541441f
                };

                var address4 = new Address
                {
                    City        = "Amsterdam",
                    Country     = "Nederland",
                    HouseNumber = 14,
                    StreetName  = "Lutmastraat",
                    ZipCode     = "1072JL",
                    Latitude    = 52.350400f,
                    Longitude   = 4.892710f
                };

                context.Addresses.AddOrUpdate(address, address2, address3, address4);

                Employee employee = CreateEmployee(context, address3);

                var customer = new Customer
                {
                    Id             = 1,
                    CustomerName   = "Q-DANCE",
                    KvkNr          = 34212891,
                    Address        = address,
                    ContactDetails = new ContactDetails
                    {
                        EmailAddress = "*****@*****.**",
                        PhoneNumber  = "+31204877300"
                    }
                };

                context.Customers.AddOrUpdate(customer);

                var now      = DateTime.Now;
                var festival = new Festival
                {
                    Id           = 1,
                    FestivalName = "Q-BASE",
                    Customer     = customer,
                    Description  = "Nachtfestival over de grens",
                    Address      = address2,
                    OpeningHours = new OpeningHours
                    {
                        StartTime = new TimeSpan(now.Hour, now.Minute, now.Second),
                        EndTime   = new TimeSpan(8, 0, 0),
                        StartDate = new DateTime(2020, 1, 1),
                        EndDate   = new DateTime(2020, 9, 6)
                    }
                };

                context.Festivals.AddOrUpdate(festival);

                customer.Festivals = new List <Festival>
                {
                    festival
                };

                context.Customers.AddOrUpdate(customer);

                var questionnaire = new Questionnaire
                {
                    Id       = 1,
                    Name     = "Tester",
                    Festival = festival
                };

                context.Questionnaires.AddOrUpdate(questionnaire);

                var employeeInspector = new Employee
                {
                    Id   = 2,
                    Iban = "NL01RABO12789410",
                    Name = new FullName
                    {
                        First = "Jan",
                        Last  = "Dirksen"
                    },
                    Account = new Account
                    {
                        Id = 1,

                        // Voorletter + Achternaam + geboortejaar
                        Username = "******",
                        Password = BCrypt.Net.BCrypt.HashPassword("TestWachtwoord"),
                        Role     = Role.Inspector
                    },
                    Address        = address4,
                    ContactDetails = new ContactDetails
                    {
                        EmailAddress = "*****@*****.**",
                        PhoneNumber  = "+31987654321"
                    },
                    Certificates = new List <Certificate>
                    {
                        new Certificate
                        {
                            Id = 2,
                            CertificateTitle  = "Inspection Certificate",
                            CertificationDate = new DateTime(2019, 3, 4, 00, 00, 00),
                            ExpirationDate    = new DateTime(2021, 3, 4, 00, 00, 00)
                        }
                    }
                };

                var plannedInspection = new PlannedInspection
                {
                    Id            = 1,
                    Employee      = employeeInspector,
                    Festival      = festival,
                    EventTitle    = "Inspection " + festival.FestivalName,
                    StartTime     = DateTime.Now.Date.Add(new TimeSpan(0, 10, 0, 0)),
                    EndTime       = DateTime.Now.Date.Add(new TimeSpan(0, 20, 0, 0)),
                    Questionnaire = questionnaire,
                };

                context.PlannedInspections.AddOrUpdate(plannedInspection);


                #region DrawQuestion

                var drawQuestion = new DrawQuestion
                {
                    Id            = 1,
                    PicturePath   = "/Uploads/grasso.png",
                    Questionnaire = questionnaire,
                    Contents      = "Wat is de kortste looproute van de mainstage naar de nooduitgang?"
                };

                var drawQuestionAnswer = new FileAnswer
                {
                    Id                = 1,
                    Question          = drawQuestion,
                    UploadedFilePath  = "/Uploads/inspection_adsfadfs.png",
                    PlannedInspection = plannedInspection
                };

                context.Answers.AddOrUpdate(drawQuestionAnswer);
                context.Questions.AddOrUpdate(drawQuestion);

                #endregion

                #region MultipleChoiceQuestion

                var multipleChoiceQuestion = new MultipleChoiceQuestion
                {
                    Id               = 2,
                    Contents         = "Zijn er evacuatieplannen zichtbaar opgesteld?",
                    Options          = "Ja~Nee",
                    OptionCollection = new ObservableCollection <StringObject>
                    {
                        new StringObject("Option1")
                    },
                    Questionnaire = questionnaire
                };

                var multipleChoiceQuestionAnswer = new MultipleChoiceAnswer
                {
                    Id = 2,
                    MultipleChoiceAnswerKey = 0,
                    PlannedInspection       = plannedInspection,
                    Question = multipleChoiceQuestion
                };

                context.Answers.AddOrUpdate(multipleChoiceQuestionAnswer);
                context.Questions.AddOrUpdate(multipleChoiceQuestion);

                #endregion

                #region NumericQuestion

                var numericQuestion = new NumericQuestion
                {
                    Id            = 3,
                    Contents      = "Hoeveel EHBO-posten zijn er aanwezig?",
                    Minimum       = 0,
                    Maximum       = 99,
                    Questionnaire = questionnaire
                };

                var numericQuestionAnswer = new NumericAnswer
                {
                    Id                = 3,
                    Question          = numericQuestion,
                    IntAnswer         = 3,
                    PlannedInspection = plannedInspection
                };

                context.Answers.AddOrUpdate(numericQuestionAnswer);
                context.Questions.AddOrUpdate(numericQuestion);

                #endregion

                #region RatingQuestion

                var ratingQuestion = new RatingQuestion
                {
                    Id       = 4,
                    Contents = "Op een schaal van 1 tot 5, is de beveiliging voldoende aanwezig op het terrein?",
                    HighRatingDescription = "Er is veel beveiliging",
                    LowRatingDescription  = "Er is amper beveiliging",
                    Questionnaire         = questionnaire
                };

                var ratingQuestionAnswer = new NumericAnswer
                {
                    Id                = 3,
                    Question          = numericQuestion,
                    IntAnswer         = 4,
                    PlannedInspection = plannedInspection
                };

                context.Answers.AddOrUpdate(ratingQuestionAnswer);
                context.Questions.AddOrUpdate(ratingQuestion);

                #endregion

                #region StringQuestion

                var stringQuestion = new StringQuestion
                {
                    Id            = 5,
                    Contents      = "Geef een korte samenvatting van het vluchtplan.",
                    IsMultiline   = true,
                    Questionnaire = questionnaire
                };

                var stringQuestionAnswer = new StringAnswer
                {
                    Id             = 5,
                    Question       = stringQuestion,
                    AnswerContents =
                        "In geval van een calamiteit is voor de bezoekers duidelijk te zien dat er vanaf de mainstage al vier vluchtroutes bestaan.",
                    PlannedInspection = plannedInspection
                };

                context.Answers.AddOrUpdate(stringQuestionAnswer);
                context.Questions.AddOrUpdate(stringQuestion);

                #endregion

                #region PictureQuestion

                var pictureQuestion = new UploadPictureQuestion
                {
                    Id            = 6,
                    Contents      = "Plaats een foto van de vluchtroutes op het calamiteitenplan.",
                    Questionnaire = questionnaire
                };

                var pictureQuestionAnswer = new FileAnswer
                {
                    Id                = 6,
                    Question          = pictureQuestion,
                    UploadedFilePath  = "/uploads/inspection_adsfadfs.png",
                    PlannedInspection = plannedInspection
                };

                context.Answers.AddOrUpdate(pictureQuestionAnswer);
                context.Questions.AddOrUpdate(pictureQuestion);

                #endregion

                #region ReferenceQuestion

                var referenceQuestion = new ReferenceQuestion
                {
                    Id            = 7,
                    Question      = pictureQuestion,
                    Contents      = pictureQuestion.Contents,
                    Questionnaire = questionnaire
                };

                var referenceQuestionAnswer = new FileAnswer
                {
                    Id                = 7,
                    Question          = referenceQuestion,
                    UploadedFilePath  = "/uploads/inspection_eruwioeiruwoio.png",
                    PlannedInspection = plannedInspection
                };

                context.Answers.AddOrUpdate(referenceQuestionAnswer);
                context.Questions.AddOrUpdate(referenceQuestion);

                #endregion


                context.Employees.AddOrUpdate(employeeInspector);

                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (DbEntityValidationResult eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (DbValidationError ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }

                throw;
            }
        }