コード例 #1
0
        public IActionResult PollAnswerCreatePopup(PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            var poll = _pollService.GetPollById(model.PollId);

            if (poll == null)
            {
                //No poll found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var pa = model.ToEntity();
                pa.Locales = UpdateOptionLocales(pa, model);
                poll.PollAnswers.Add(pa);
                _pollService.UpdatePoll(poll);
                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> PollAnswerEditPopup(PollAnswerModel model)
        {
            var poll = await _pollService.GetPollById(model.PollId);

            if (poll == null)
            {
                //No poll found with the specified id
                return(RedirectToAction("List"));
            }

            var pollAnswer = poll.PollAnswers.Where(x => x.Id == model.Id).FirstOrDefault();

            if (pollAnswer == null)
            {
                //No poll answer found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                pollAnswer = model.ToEntity(pollAnswer);
                await _pollService.UpdatePoll(poll);

                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
ファイル: PollController.cs プロジェクト: BoyFaceGirl/NopShop
        public virtual IActionResult PollAnswerAdd(int pollId, [Validate] PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            //fill entity from model
            _pollService.InsertPollAnswer(model.ToEntity <PollAnswer>());

            return(Json(new { Result = true }));
        }
コード例 #4
0
        public virtual IActionResult PollAnswerUpdate([Validate] PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            //try to get a poll answer with the specified id
            var pollAnswer = _pollService.GetPollAnswerById(model.Id)
                             ?? throw new ArgumentException("No poll answer found with the specified id");

            pollAnswer = model.ToEntity(pollAnswer);
            _pollService.UpdatePoll(pollAnswer.Poll);

            return(new NullJsonResult());
        }
コード例 #5
0
        public IActionResult PollAnswerCreatePopup(PollAnswerModel model)
        {
            var poll = _pollService.GetPollById(model.PollId);

            if (poll == null)
            {
                //No poll found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var pa = model.ToEntity();
                poll.PollAnswers.Add(pa);
                _pollService.UpdatePoll(poll);
                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #6
0
        public virtual IActionResult PollAnswerAdd(int pollId, [Validate] PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            //try to get a poll with the specified id
            var poll = _pollService.GetPollById(pollId)
                       ?? throw new ArgumentException("No poll found with the specified id", nameof(pollId));

            //fill entity from model
            poll.PollAnswers.Add(model.ToEntity <PollAnswer>());
            _pollService.UpdatePoll(poll);

            return(Json(new { Result = true }));
        }
コード例 #7
0
        public IActionResult PollAnswerEditPopup(string btnId, string formId, PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            var poll = _pollService.GetPollById(model.PollId);

            if (poll == null)
            {
                //No poll found with the specified id
                return(RedirectToAction("List"));
            }

            var pollAnswer = poll.PollAnswers.Where(x => x.Id == model.Id).FirstOrDefault();

            if (pollAnswer == null)
            {
                //No poll answer found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                pollAnswer         = model.ToEntity(pollAnswer);
                pollAnswer.Locales = UpdateOptionLocales(pollAnswer, model);

                _pollService.UpdatePoll(poll);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }