Ejemplo n.º 1
0
        /// <summary>
        /// Saves the goal to the database.  This method is invoked by the SaveCommand.
        /// </summary>
        public override void Save()
        {
            if (!_goal.IsValid)
            {
                throw new InvalidOperationException(Properties.Resources.GoalViewModel_Exception_CannotSave);
            }

            if (this.IsNewGoal)
            {
                CreatedDate = DateTime.Now;

                if (StatusId == Statuses.Completed)
                {
                    CompletedDate = DateTime.Now;
                }

                GoalId = _goalData.AddGoal(_goal);
            }
            else
            {
                if (StatusId != _originalStatusId && StatusId == Statuses.Completed)
                {
                    CompletedDate = DateTime.Now;
                }
                else if (StatusId != Statuses.Completed && _originalStatusId == Statuses.Completed)
                {
                    CompletedDate = null;
                }

                _goalData.UpdateGoal(_goal, _projectData);
            }

            _originalStatusId = StatusId;
            _isSaved          = true;
        }