Ejemplo n.º 1
0
        public ActionResult UpdateAnswer(int id, UpdateAnswer updateAnswer)
        {
            var db         = new DatabaseContext();
            var prevAnswer = db.Answers.FirstOrDefault(a => a.Id == updateAnswer.Id);

            if (prevAnswer == null)
            {
                return(NotFound(new { error = "No answer with Id" + updateAnswer.Id + " found." }));
            }
            else
            if (db.Questions.FirstOrDefault(q => q.Id == updateAnswer.QuestionId) == null)
            {
                return(NotFound(new { error = "No question with QuestionId " + updateAnswer.QuestionId + " found." }));
            }
            else

            if (updateAnswer.Id != id)
            {
                return(NotFound(new { error = $"Endpoint Id ({id}) and object Id ({updateAnswer.Id}) differ." }));
            }

            else
            {
                prevAnswer.QuestionId           = updateAnswer.QuestionId;
                prevAnswer.AnswerText           = updateAnswer.AnswerText;
                prevAnswer.VoteValue            = updateAnswer.VoteValue;
                prevAnswer.LastModifiedDateTime = DateTime.UtcNow;
                db.SaveChanges();
                return(Ok(prevAnswer));
            }
        }
Ejemplo n.º 2
0
        public static void DoPoliticianUpdate(string politicianKey, PoliticianUpdateData data,
                                              List <UpdateAnswer.UpdateAnswerFeedback> feedback)
        {
            // handle bio & issues
            var updateAnswer = new UpdateAnswer(UpdateAnswer.Usage.ForAll);

            updateAnswer.UpdateAllAnswersNew(politicianKey, data.Issues, feedback);
        }
Ejemplo n.º 3
0
        // shared by Reasons tab
        private void ProcessQuestions(Control parent, string tabName,
                                      IEnumerable <IGrouping <string, AnswersViewRow> > questions,
                                      UpdateAnswer updateAnswer,
                                      IDictionary <string, string> alternateTabLabels = null,
                                      Dictionary <string, string> alternateHeadings   = null)
        {
            var tabs = AddTabContainer(parent, null, "tabs vtabs unselectable");

            foreach (var question in questions)
            {
                CreateQuestion(parent, question.ToList(), tabs, tabName, updateAnswer,
                               alternateTabLabels, alternateHeadings);
            }
        }
Ejemplo n.º 4
0
        public IApiResult Update(UpdateAnswer operation)
        {
            var result = operation.ExecuteAsync().Result;

            if (result is ValidationsOutput)
            {
                return(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                });
            }
            else
            {
                return(new ApiResult <object>()
                {
                    Status = ApiResult <object> .ApiStatus.Success
                });
            }
        }
Ejemplo n.º 5
0
        private void CreateQuestion(Control parent, IList <AnswersViewRow> responses,
                                    Control tabs, string tabName, UpdateAnswer updateAnswer,
                                    IDictionary <string, string> alternateTabLabels = null,
                                    Dictionary <string, string> alternateHeadings   = null)
        {
            var row = responses.First();

            if (_QuestionTabFont == null)
            {
                _QuestionTabFont = new Font(QuestionTabFontFamily, QuestionTabFontSize,
                                            FontStyle.Bold);
            }

            var monitor = MonitorFactory.GetMonitorInstance(row.QuestionKey);

            var panel = AddContainer(parent, "tab-" + tabName + "-" + row.QuestionKey.ToLowerInvariant(),
                                     "content-panel tab-panel vtab-panel");

            panel.ClientIDMode = ClientIDMode.Static;

            // create vertical tab
            var tabLabel = alternateTabLabels?.ContainsKey(row.QuestionKey) == true
        ? alternateTabLabels[row.QuestionKey]
        : BreakForTab(row.Question, _QuestionTabFont, QuestionTabMaxWidth);
            var verticalTab = AddVertTab(tabs, "#" + panel.ClientID, tabLabel, " vcentered-tab");

            // center the a tag -- the first child of the tab always
            Center(verticalTab.Controls[0], false, true);

            AddAsteriskIndicator(verticalTab, "Ast" + row.QuestionKey,
                                 monitor.GetAsteriskClass(null),
                                 $"There are unsaved changes to \"{row.Question}\"");

            AddStarIndicator(verticalTab, "Star" + row.QuestionKey,
                             monitor.GetStarClass(null, "hasvalue"),
                             $"We have a response from you for \"{row.Question}\"");

            updateAnswer.CreateControls(panel, responses, monitor, alternateHeadings);
        }
Ejemplo n.º 6
0
        public async Task Execute(PangulDbContext db, UpdateAnswer command)
        {
            command.Validate();

            // Fetch the answer
            var answer = await _getAnswer.Execute(db, new GetAnswer()
            {
                UserContext = command.UserContext,
                AnswerId    = command.AnswerId,
                RowVersion  = command.RowVersion
            });

            if (answer == null)
            {
                throw new PangulCommandFailedException(CommandFailureType.MissingData, $"No such answer ({command.AnswerId}, {command.RowVersion})");
            }

            // Verify user has permission
            await _permissionService.RequireWriteAccessFor(answer, command.UserContext);

            // Update the answer
            answer.Body = command.NewBody;
        }
Ejemplo n.º 7
0
        public async Task <Answer> UpdateExistingAnswer(PangulDbContext db, UserContext user, UpdateAnswer model)
        {
            model.UserContext = user;
            await _updateAnswer.Execute(db, model);

            return(await GetAnswer(db, user, model.AnswerId));
        }