示例#1
0
        public Release UpdateDates(ReleaseInputModel obj)
        {
            var conn = new SqlConnection("Data Source=localhost\\SQLENTERPRISE;Initial Catalog=Planner;Integrated Security=SSPI;MultipleActiveResultSets=true");
            try
            {
                using (conn)
                {
                    conn.Open();

                    var cmd = new SqlCommand("sp_update_phase_dates", conn);
                    cmd.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = obj.Id;
                    cmd.Parameters.Add("@StartDate", System.Data.SqlDbType.DateTime).Value = obj.StartDate.ToDateTimeFromDutchString();
                    cmd.Parameters.Add("@EndDate", System.Data.SqlDbType.DateTime).Value = obj.EndDate.ToDateTimeFromDutchString();
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.ExecuteNonQuery();
                }
                var rel = this.GetReleaseSummary(obj.Id);
                return rel;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
 public JsonResult Save(ReleaseInputModel obj)
 {
     var rep = new ReleaseRepository();
     var rel = rep.Save(obj);
     return this.Json(rel, JsonRequestBehavior.AllowGet);
 }
示例#3
0
        public Release Save(ReleaseInputModel obj)
        {
            var conn = new SqlConnection("Data Source=localhost\\SQLENTERPRISE;Initial Catalog=Planner;Integrated Security=SSPI;MultipleActiveResultSets=true");
            int newId = 0;
            try
            {
                using (conn)
                {
                    conn.Open();

                    var cmd = new SqlCommand("sp_upsert_release", conn);
                    cmd.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = obj.Id;
                    cmd.Parameters.Add("@Title", System.Data.SqlDbType.VarChar).Value = obj.Title;
                    cmd.Parameters.Add("@Descr", System.Data.SqlDbType.VarChar).Value = "";// obj.Descr;
                    cmd.Parameters.Add("@StartDate", System.Data.SqlDbType.DateTime).Value = obj.StartDate.ToDateTimeFromDutchString();
                    cmd.Parameters.Add("@EndDate", System.Data.SqlDbType.DateTime).Value = obj.EndDate.ToDateTimeFromDutchString();
                    cmd.Parameters.Add("@ParentId", System.Data.SqlDbType.Int).Value = obj.ParentId;
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    var result = cmd.ExecuteScalar().ToString();

                    if (result == string.Empty && obj.ParentId == 0)
                    // it's an update of a root node
                    {
                        newId = obj.Id;
                    }
                    else if (result != string.Empty && obj.ParentId == 0)
                    // it's an insert of a root node
                    {
                        newId = int.Parse(result);
                    }
                    else
                    // it's a child; return parentId
                    {
                        newId = obj.ParentId;
                    }

                    // completely renew the Projects for the Release as set in the client app
                    var cmdDelCross = new SqlCommand(string.Format("Delete from ReleaseProjects where PhaseId = {0}", newId), conn);
                    cmdDelCross.ExecuteNonQuery();

                    if (obj.Projects != null && obj.Projects.Count > 0)
                    {
                        var cmdInsertReleaseProject = new SqlCommand("sp_insert_releaseproject", conn);
                        cmdInsertReleaseProject.Parameters.Add("@ReleaseId", System.Data.SqlDbType.Int).Value = newId;
                        cmdInsertReleaseProject.Parameters.Add("@ProjectId", System.Data.SqlDbType.Int).Value = 0;
                        cmdInsertReleaseProject.CommandType = System.Data.CommandType.StoredProcedure;

                        foreach (var proj in obj.Projects)
                        {
                            cmdInsertReleaseProject.Parameters["@ProjectId"].Value = proj.Id;
                            cmdInsertReleaseProject.ExecuteNonQuery();
                        }
                    }
                }
                var rel = this.GetReleaseSummary(newId);
                this.GenerateStatusRecords(rel);

                return rel;
            }
            catch (Exception ex)
            {
                throw;
            }
        }