Exemplo n.º 1
0
        /// <summary>
        /// Update value for property of model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel UpdatePollAnswerData(XEditableModel model)
        {
            var pollAnswer = GetById(model.Pk);

            if (pollAnswer != null)
            {
                var property =
                    ReflectionUtilities.GetAllPropertiesOfType(typeof(PollAnswerManageModel))
                    .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 PollAnswerManageModel(pollAnswer);
                    manageModel.SetProperty(model.Name, value);

                    var validationResults = manageModel.ValidateModel();

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

                    #endregion

                    pollAnswer.SetProperty(model.Name, value);

                    var response = Update(pollAnswer);
                    return(response.SetMessage(response.Success
                        ? T("PollAnswer_Message_UpdatePollAnswerInfoSuccessfully")
                        : T("PollAnswer_Message_UpdatePollAnswerInfoFailure")));
                }
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("PollAnswer_Message_PropertyNotFound")
                });
            }
            return(new ResponseModel
            {
                Success = false,
                Message = T("PollAnswer_Message_ObjectNotFound")
            });
        }
Exemplo n.º 2
0
        public ActionResult PopupEdit(PollAnswerManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _pollAnswerService.SavePollAnswer(model);
                SetResponseMessage(response);
                if (response.Success)
                {
                    switch (submit)
                    {
                    case SubmitType.PopupSave:
                        return(View("CloseFancyBox", new CloseFancyBoxViewModel()));

                    case SubmitType.SaveAndContinueEdit:
                        return(RedirectToAction("PopupEdit", new { id = model.Id }));
                    }
                }
            }
            SetupPopupAction();
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Create(PollAnswerManageModel model, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _pollAnswerService.SavePollAnswer(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));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Save poll answer
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel SavePollAnswer(PollAnswerManageModel model)
        {
            ResponseModel response;
            var           pollAnswer = GetById(model.Id);

            if (pollAnswer != null)
            {
                pollAnswer             = GetById(model.Id);
                pollAnswer.AnswerText  = model.AnswerText;
                pollAnswer.Total       = model.Total;
                pollAnswer.PollId      = model.PollId;
                pollAnswer.RecordOrder = model.RecordOrder;
                response = Update(pollAnswer);
                return(response.SetMessage(response.Success
                    ? T("PollAnswer_Message_UpdateSuccessfully")
                    : T("PollAnswer_Message_UpdateFailure")));
            }
            Mapper.CreateMap <PollAnswerManageModel, PollAnswer>();
            pollAnswer = Mapper.Map <PollAnswerManageModel, PollAnswer>(model);
            response   = Insert(pollAnswer);
            return(response.SetMessage(response.Success
                ? T("PollAnswer_Message_CreateSuccessfully")
                : T("PollAnswer_Message_CreateFailure")));
        }
Exemplo n.º 5
0
        public ActionResult Edit(PollAnswerManageModel model, string returnUrl, SubmitType submit)
        {
            if (ModelState.IsValid)
            {
                var response = _pollAnswerService.SavePollAnswer(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 }));
                    }
                }
            }
            return(View(model));
        }