Exemplo n.º 1
0
        public bool CreateNewDashboardByExistingDashboard(int dashboardID, int userID, string dashboardName, string description)
        {
            StoredProcedureDataContext dbmlObject = new StoredProcedureDataContext();
            var result            = dbmlObject.GetDashboardByID(dashboardID).ToList();
            var dashboardDetails  = result.FirstOrDefault();
            var resNewDashboardID = dbmlObject.CreateDashboard(dashboardName, dashboardDetails.StartMonth, dashboardDetails.StartYear, dashboardDetails.EndMonth, dashboardDetails.EndYear, userID, "ADMIN", description).ToList();
            int newDashboardID    = Convert.ToInt32(resNewDashboardID.FirstOrDefault().Column1);
            //Dashboard Source
            var resDashboardSources = dbmlObject.RetreiveSource(dashboardID).ToList();

            foreach (var i in resDashboardSources)
            {
                dbmlObject.AddDashboardSources(i.Source, newDashboardID);
            }
            //dashboard Status
            var resStatus = dbmlObject.RetreiveStatus(dashboardID);

            foreach (var i in resStatus)
            {
                dbmlObject.AddDashboardStatus(i.Status, i.Color, newDashboardID);
            }
            var resultItems = dbmlObject.RetreiveExistingDashboardItems(dashboardID, "StartDate").ToList();

            foreach (var i in resultItems)
            {
                var resItemID = dbmlObject.AddDataItem(i.ItemName, i.StartDate, i.EndDate, newDashboardID, i.StatusID).ToList();
                int itemID    = Convert.ToInt32(resItemID.FirstOrDefault().Column1);
                var resTeams  = dbmlObject.RetreiveTeamsWorkingOnItem(i.ItemID).ToArray();
                for (var j = 0; j < resTeams.Length; j++)
                {
                    dbmlObject.AddTeamToDashboardItem(itemID, resTeams[j].TeamID);
                }
                var resSources = dbmlObject.GetSourcesByItemID(i.ItemID).ToArray();
                for (var j = 0; j < resSources.Length; j++)
                {
                    dbmlObject.AddDataItemSource(itemID, resSources[j].SourceID);
                }
            }
            dbmlObject.SubmitChanges();
            return(true);
        }