コード例 #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, Question, QuizId")] QuizQuestionViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                result.Question = vm.Question;
                result.QuizId   = vm.QuizId;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    return(OperationErrorBackToIndex(updateOperation.Exception));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly updated"));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public void TestUpdateQuizQuestionAsync()
        {
            BoraNowSeeder.Seed();
            var qqbo    = new QuizQuestionBusinessObject();
            var resList = qqbo.List();
            var item    = resList.Result.FirstOrDefault();

            var qbo = new QuizBusinessObject();

            var quiz = new Quiz("This quiz rocks");

            qbo.Create(quiz);

            item.QuizId   = quiz.Id;
            item.Question = "viewpoint?";


            var resUpdate = qqbo.UpdateAsync(item).Result;

            resList = qqbo.ListAsync().Result;

            Assert.IsTrue(resUpdate.Success && resList.Success && resList.Result.First().Question == "viewpoint?" &&
                          resList.Result.First().QuizId == quiz.Id);
        }