Example #1
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <param name="entity">The milestone to save.</param>
        /// <returns></returns>
        public static bool SaveOrUpdate(Milestone entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            if (entity.ProjectId <= Globals.NEW_ID) throw (new ArgumentException("Cannot save milestone, the project id is invalid"));
            if (string.IsNullOrEmpty(entity.Name)) throw (new ArgumentException("The milestone name cannot be empty or null"));

            if (entity.Id > Globals.NEW_ID)
                return DataProviderManager.Provider.UpdateMilestone(entity);

            var tempId = DataProviderManager.Provider.CreateNewMilestone(entity);
            if (tempId <= 0) return false;

            entity.Id = tempId;
            return true;
        }
Example #2
0
        /// <summary>
        /// Updates the milestone.
        /// </summary>
        /// <param name="milestoneToUpdate">The milestone to update.</param>
        /// <returns></returns>
        public override bool UpdateMilestone(Milestone milestoneToUpdate)
        {
            // Validate Parameters
            if (milestoneToUpdate == null) throw (new ArgumentNullException("milestoneToUpdate"));

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                AddParamToSqlCmd(sqlCmd, "@MilestoneId", SqlDbType.Int, 0, ParameterDirection.Input, milestoneToUpdate.Id);
                AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, milestoneToUpdate.ProjectId);
                AddParamToSqlCmd(sqlCmd, "@SortOrder", SqlDbType.Int, 0, ParameterDirection.Input, milestoneToUpdate.SortOrder);
                AddParamToSqlCmd(sqlCmd, "@MilestoneName", SqlDbType.NText, 50, ParameterDirection.Input, milestoneToUpdate.Name);
                AddParamToSqlCmd(sqlCmd, "@MilestoneImageUrl", SqlDbType.NText, 50, ParameterDirection.Input, milestoneToUpdate.ImageUrl);
                AddParamToSqlCmd(sqlCmd, "@MilestoneCompleted", SqlDbType.Bit, 0, ParameterDirection.Input, milestoneToUpdate.IsCompleted);
                AddParamToSqlCmd(sqlCmd, "@MilestoneNotes", SqlDbType.NText, 255, ParameterDirection.Input, milestoneToUpdate.Notes);

                //Bypass to AddParamToSQLCmd method which doesn't handle null values properly
                if (milestoneToUpdate.DueDate.HasValue)
                    AddParamToSqlCmd(sqlCmd, "@MilestoneDueDate", SqlDbType.DateTime, 0, ParameterDirection.Input, milestoneToUpdate.DueDate);
                else
                    sqlCmd.Parameters.AddWithValue("@MilestoneDueDate", DBNull.Value);

                if (milestoneToUpdate.ReleaseDate.HasValue)
                    AddParamToSqlCmd(sqlCmd, "@MilestoneReleaseDate", SqlDbType.DateTime, 0, ParameterDirection.Input, milestoneToUpdate.ReleaseDate);
                else
                    sqlCmd.Parameters.AddWithValue("@MilestoneReleaseDate", DBNull.Value);

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_MILESTONE_UPDATE);
                ExecuteScalarCmd(sqlCmd);
                var returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
                return (returnValue == 0);   
            }
        }
Example #3
0
        /// <summary>
        /// Adds the milestone.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddMilestone(Object s, EventArgs e)
        {
            var newName = txtName.Text.Trim();

            if (newName == String.Empty)
                return;

            var newMilestone = new Milestone
                                   {
                                       ProjectId = ProjectId,
                                       Name = newName,
                                       ImageUrl = lstImages.SelectedValue,
                                       DueDate = DueDate.SelectedValue,
                                       ReleaseDate = ReleaseDate.SelectedValue,
                                       IsCompleted = chkCompletedMilestone.Checked,
                                       Notes = txtMilestoneNotes.Text
                                   };

            if (MilestoneManager.SaveOrUpdate(newMilestone))
            {
                txtMilestoneNotes.Text = string.Empty;
                txtName.Text = string.Empty;
                DueDate.SelectedValue = null;
                chkCompletedMilestone.Checked = false;
                ReleaseDate.SelectedValue = null;
                BindMilestones();
                lstImages.SelectedValue = String.Empty;
            }
            else
            {
                ActionMessage.ShowErrorMessage(LoggingManager.GetErrorMessageResource("SaveMilestoneError"));
            }
        }
Example #4
0
 public abstract bool UpdateMilestone(Milestone milestoneToUpdate);
Example #5
0
 // Milestone
 public abstract int CreateNewMilestone(Milestone newMileStone);