Beispiel #1
0
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdatePollData(XEditableModel model)
        {
            var poll = GetById(model.Pk);

            if (poll != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(PollManageModel))
                    .FirstOrDefault(p => p.Name.Equals(model.Name, StringComparison.CurrentCultureIgnoreCase));
                if (property != null)
                {
                    object value = model.Value.ToType(property, WorkContext.CurrentTimezone);

                    #region Validate

                    var manageModel = new PollManageModel(poll);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

                    if (validationResults.Any())
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = validationResults.BuildValidationMessages()
                        });
                    }

                    #endregion

                    poll.SetProperty(model.Name, value);

                    var response = Update(poll);
                    return(response.SetMessage(response.Success
                        ? T("Poll_Message_UpdatePollInfoSuccessfully")
                        : T("Poll_Message_UpdatePollInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("Poll_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("Poll_Message_ObjectNotFound")
            });
        }
Beispiel #2
0
        public ActionResult Create(PollManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _pollService.SavePoll(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    var id = (int)response.Data;
                    switch (submit)
                    {
                    case SubmitType.Save:
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id }));
                    }
                }
            }
            return(View(model));
        }
Beispiel #3
0
        /// <summary>
        /// Save poll
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SavePoll(PollManageModel model)
        {
            ResponseModel response;
            var           poll = GetById(model.Id);

            if (poll != null)
            {
                poll.PollQuestion = model.PollQuestion;
                poll.PollSummary  = model.PollSummary;
                poll.IsMultiple   = model.IsMultiple;
                poll.ThankyouText = model.ThankyouText;
                response          = Update(poll);
                return(response.SetMessage(response.Success
                    ? T("Poll_Message_UpdateSuccessfully")
                    : T("Poll_Message_UpdateFailure")));
            }
            Mapper.CreateMap <PollManageModel, Poll>();
            poll     = Mapper.Map <PollManageModel, Poll>(model);
            response = Insert(poll);
            return(response.SetMessage(response.Success
                ? T("Poll_Message_CreateSuccessfully")
                : T("Poll_Message_CreateFailure")));
        }
Beispiel #4
0
        public ActionResult Edit(PollManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _pollService.SavePoll(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.Save:
                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        return(RedirectToAction("Index"));

                    default:
                        return(RedirectToAction("Edit", new { id = model.Id, returnUrl }));
                    }
                }
            }
            return(View(model));
        }