Ejemplo n.º 1
0
        public ActionResult PollAnswerAdd(int pollId, [Bind(Exclude = "Id")] PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult()
                {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var poll = _pollService.GetPollById(pollId);

            if (poll == null)
            {
                throw new ArgumentException("No poll found with the specified id", "pollId");
            }

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder
            });
            _pollService.UpdatePoll(poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 2
0
        public virtual IActionResult PollAnswerUpdate(PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = 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.Name                = model.Name;
            pollAnswer.DisplayOrder        = model.DisplayOrder;
            pollAnswer.PollAnswerImagePath = model.PollAnswerImagePath;
            pollAnswer.PollProductId       = model.PollProductId;
            _pollService.UpdatePoll(pollAnswer.Poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 3
0
        public virtual IActionResult PollAnswerAdd(int pollId, PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = 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));

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder
            });
            _pollService.UpdatePoll(poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 4
0
        public ActionResult OptionCreatePopup(string btnId, string formId, PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

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

            if (poll == null)
            {
                throw new ArgumentException("No poll found with the specified id", "pollId");
            }

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder
            });
            _pollService.UpdatePoll(poll);
            ViewBag.RefreshPage = true;
            ViewBag.btnId       = btnId;
            ViewBag.formId      = formId;
            return(View(model));
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        public ActionResult PollAnswerAdd(int pollId, PollAnswerModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var poll = _pollService.GetPollById(pollId);

            if (poll == null)
            {
                throw new ArgumentException("No poll found with the specified id", "pollId");
            }

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder1
            });
            _pollService.UpdatePoll(poll);

            return(PollAnswers(poll.Id, command));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public ActionResult PollAnswerAdd(int pollId, PollAnswerModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(new JsonResult {
                    Data = "error"
                });
            }

            var poll = _pollService.GetPollById(pollId);

            if (poll == null)
            {
                throw new ArgumentException("No poll found with the specified id", "pollId");
            }

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder1
            });
            _pollService.UpdatePoll(poll);

            return(PollAnswers(poll.Id, command));
        }
Ejemplo n.º 9
0
        public ActionResult PollAnswerUpdate(PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult()
                {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var pollAnswer = _pollService.GetPollAnswerById(model.Id);

            if (pollAnswer == null)
            {
                throw new ArgumentException("No poll answer found with the specified id", "id");
            }

            pollAnswer.Name         = model.Name;
            pollAnswer.DisplayOrder = model.DisplayOrder;
            _pollService.UpdatePoll(pollAnswer.Poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 10
0
        public ActionResult PollAnswerUpdate(PollAnswerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }
            var poll       = _pollService.GetPollById(model.PollId);
            var pollAnswer = poll.PollAnswers.FirstOrDefault(x => x.Id == model.Id);

            if (pollAnswer == null)
            {
                throw new ArgumentException("No poll answer found with the specified id");
            }
            pollAnswer._id          = ObjectId.GenerateNewId().ToString();
            pollAnswer.Id           = poll.PollAnswers.Count > 0 ? poll.PollAnswers.Max(x => x.Id) + 1 : 1;
            pollAnswer.Name         = model.Name;
            pollAnswer.DisplayOrder = model.DisplayOrder;
            _pollService.UpdatePoll(poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 11
0
        //create
        public IActionResult PollAnswerCreatePopup(string pollId)
        {
            var model = new PollAnswerModel();

            model.PollId = pollId;

            //locales
            AddLocales(_languageService, model.Locales);
            return(View(model));
        }
Ejemplo n.º 12
0
        //create
        public async Task <IActionResult> PollAnswerCreatePopup(string pollId)
        {
            var model = new PollAnswerModel
            {
                PollId = pollId
            };

            //locales
            await AddLocales(_languageService, model.Locales);

            return(View(model));
        }
Ejemplo n.º 13
0
        public ActionResult OptionCreatePopup(int pollId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }
            var model = new PollAnswerModel();

            model.DisplayOrder = 1;
            model.PollId       = pollId;
            return(View(model));
        }
Ejemplo n.º 14
0
        public ActionResult OptionEditPopup(int id)
        {
            var pollAnswer = _pollService.GetPollAnswerById(id);

            if (pollAnswer == null)
            {
                throw new ArgumentException("No poll answer found with the specified id", "id");
            }
            var model = new PollAnswerModel();

            model.DisplayOrder = pollAnswer.DisplayOrder;
            model.Name         = pollAnswer.Name;
            return(View(model));
        }
Ejemplo n.º 15
0
        //create
        public IActionResult PollAnswerCreatePopup(string pollId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            var model = new PollAnswerModel();

            model.PollId = pollId;

            //locales
            AddLocales(_languageService, model.Locales);
            return(View(model));
        }
Ejemplo n.º 16
0
        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 }));
        }
Ejemplo n.º 17
0
        public ActionResult PollAnswerUpdate(PollAnswerModel model, GridCommand command)
        {
            var pollAnswer = _pollService.GetPollAnswerById(model.Id);

            if (!ModelState.IsValid)
            {
                var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            pollAnswer.Name         = model.Name;
            pollAnswer.DisplayOrder = model.DisplayOrder1;

            _pollService.UpdatePoll(pollAnswer.Poll);

            return(PollAnswers(pollAnswer.PollId, command));
        }
Ejemplo n.º 18
0
        public virtual IActionResult PollAnswerUpdate(PollAnswerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

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

            pollAnswer.Name         = model.Name;
            pollAnswer.DisplayOrder = model.DisplayOrder;
            _pollService.UpdatePoll(pollAnswer.Poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 19
0
        public ActionResult PollAnswerAdd(int pollId, PollAnswerModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var poll = _pollService.GetPollById(pollId);

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder1
            });

            _pollService.UpdatePoll(poll);

            return(PollAnswers(pollId, command));
        }
Ejemplo n.º 20
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());
        }
Ejemplo n.º 21
0
        public virtual IActionResult PollAnswerAdd(int pollId, PollAnswerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

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

            poll.PollAnswers.Add(new PollAnswer
            {
                Name         = model.Name,
                DisplayOrder = model.DisplayOrder
            });
            _pollService.UpdatePoll(poll);

            return(new NullJsonResult());
        }
Ejemplo n.º 22
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));
        }
Ejemplo n.º 23
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));
        }
Ejemplo n.º 24
0
        public ActionResult PollAnswerUpdate(PollAnswerModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePolls))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(new JsonResult {
                    Data = "error"
                });
            }

            var pollAnswer = _pollService.GetPollAnswerById(model.Id);

            pollAnswer.Name         = model.Name;
            pollAnswer.DisplayOrder = model.DisplayOrder1;
            _pollService.UpdatePoll(pollAnswer.Poll);

            return(PollAnswers(pollAnswer.PollId, command));
        }
Ejemplo n.º 25
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 }));
        }
 public static PollAnswer ToEntity(this PollAnswerModel model, PollAnswer destination)
 {
     return(model.MapTo(destination));
 }
Ejemplo n.º 27
0
        protected virtual List <LocalizedProperty> UpdateOptionLocales(PollAnswer pollanswer, PollAnswerModel model)
        {
            List <LocalizedProperty> localized = new List <LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                if (!(String.IsNullOrEmpty(local.Name)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Name",
                        LocaleValue = local.Name,
                    });
                }
            }
            return(localized);
        }
 public static PollAnswer ToEntity(this PollAnswerModel model)
 {
     return(model.MapTo <PollAnswerModel, PollAnswer>());
 }