예제 #1
0
        public override bool Save()
        {
            bool result = false;

            if (SelectedSession == null)
            {
                ShowFeedback("Cannot save changes. No Selected Session found.", FeedbackType.Error);
                return(result);
            }
            if (DateTime.Now >= SelectedSession.StartTime && DateTime.Now <= SelectedSession.EndTime)
            {
                ClearFeedback();
                try
                {
                    if (FormContextQuestion == FormContext.Create)
                    {
                        //create new  answer
                        result = User.AskQuestion(SelectedQuestion, UnitOfWork);
                        UpdateQuestionsList(QuestionSearchTxt);
                        FormContextQuestion = FormContext.Update;//selected item now has an id go to update mode
                        ShowFeedback($"Added question: {SelectedQuestion.Name}.", FeedbackType.Success);
                    }
                    else
                    {
                        //Update Selected Answer
                        result = SelectedQuestion.Validate(UnitOfWork);
                        if (result)
                        {
                            result = (UnitOfWork.Complete() > 0) ? true : false;
                            ShowFeedback($"Updated question: {SelectedQuestion.Name}", FeedbackType.Success);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    ShowFeedback(ex.Message, FeedbackType.Error);
                }
                catch (SqlException ex)
                {
                    ShowFeedback(ex.Message, FeedbackType.Error);
                }
                catch (Exception ex)
                {
                    ShowFeedback(ex.Message, FeedbackType.Error);
                }
            }
            else
            {
                ShowFeedback($"Cannot Save: \nSession: {SelectedSession.Name} is closed. Start: {SelectedSession.StartTime} - {SelectedSession.EndTime}", FeedbackType.Error);
                result = false;
            }

            return(result);
        }