Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,MyAudio,MyImage,Answeres,CorrectAnswer,SerieId")] QuestionCreateViewModel question)
        {
            if (ModelState.IsValid)
            {
                var uploads = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\images\Questions"));

                var Imagefile = DateTime.Now.ToString("MMddyyyyHHmmss-") + question.MyImage.FileName;
                var filePath  = Path.Combine(uploads, Imagefile);
                await question.MyImage.CopyToAsync(new FileStream(filePath, FileMode.Create));

                var Audiofile = DateTime.Now.ToString("MMddyyyyHHmmss-") + question.MyAudio.FileName;
                filePath = Path.Combine(uploads, Audiofile);
                await question.MyAudio.CopyToAsync(new FileStream(filePath, FileMode.Create));

                Question Q = new Question
                {
                    Name          = question.Name,
                    SerieId       = question.SerieId,
                    Image         = @"images\Questions\Image\" + Imagefile,
                    Audio         = @"images\Questions\Audio\" + Audiofile,
                    Answeres      = question.Answeres,
                    CorrectAnswer = question.CorrectAnswer
                };
                await _Questions.AddNewAsync(Q);

                await _Questions.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(question));
        }