/*
        public List<ActivityVM> GetTeamActivityVMs(int teamId)
        {
            List<ActivityVM> activityVMList = new List<ActivityVM>();
            try
            {
                var activityList = repo.GetTeamActivity(teamId).OrderByDescending(s => s.CreatedDate).ToList();
                
                ActivityVM activityVM=new ActivityVM();
                foreach (var item in activityList)
                {
                    if (item.ObjectType.ToUpper() == "ISSUE")
                    {
                        activityVM = GetActivityVM(item);
                    }
                    else if (item.ObjectType.ToUpper() == "ISSUECOMMENT")
                    {
                        activityVM = new CommentService(repo,SiteBaseURL).GetActivityVM(item);
                    }

                    activityVMList.Add(activityVM);
                }
            }
            catch (Exception ex)
            {
                
            }
            return activityVMList;
        }
        */
        
        /*
        public ActivityVM GetActivityVM(Activity item)
        {
            var activityVM = new ActivityVM() { Author = item.User.FirstName, CreatedDateRelative = item.CreatedDate.ToString() };
            if (item.ActivityDesc.ToUpper() == "CREATED")
            {
                activityVM.Activity = item.ActivityDesc;
                activityVM.ObjectTite = item.NewState;
                activityVM.ObjectURL = String.Format("{0}Issues/details/{1}", SiteBaseURL, item.ObjectID);
            }
            return activityVM;
        }*/

        public DashBoardItemSummaryVM GetDashboardSummaryVM(int teamId)
        {
            var vm = new DashBoardItemSummaryVM();
            var issues = repo.GetIssues(teamId);
            vm.CurrentItems = issues.Where(s => s.Location == LocationType.SPRNT.ToString()).Count();
            vm.CompletedItems = issues.Where(s => s.Location == LocationType.ARCHV.ToString()).Count();
            vm.BacklogItems = issues.Where(s => s.Location == LocationType.BKLOG.ToString()).Count();
            vm.ItemsInProgress = issues.Where(s => s.Status.Name.ToUpper() == "IN PROGRESS").Count();
            vm.NewItems = issues.Where(s => s.Status.Name.ToUpper() == "NEW").Count();
            return vm;
        }
        //var issueVM = new IssueVM { ID = bug.ID, Title = bug.Title, Description = bug.Description };
        //issueVM.OpenedBy = bug.CreatedBy.FirstName;
        //    issueVM.PriorityName = bug.PriorityName.Name;
        //    issueVM.StatusName = bug.StatusName.Name;
        //    issueVM.CategoryName = bug.CategoryName.Name;
        //    issueVM.Project = (bug.Project!=null?bug.Project.Name:"");
        //    issueVM.CreatedDate = bug.CreatedDate.ToShortDateString();
        public DashBoardItemSummaryVM GetDashboardSummaryVM(int teamId)
        {
            var vm = new DashBoardItemSummaryVM();
            using (var db = new TeamEntitiesConn())
            {
                var statusCounts = db.Issues
                    .Where(s => s.TeamID == teamId)
                    .GroupBy(d => d.Status, g => g.ID, (k, i) => new
                ItemCount
                    {
                        ItemId = k.ID,
                        ItemName = k.Name,
                        Count = i.Count()
                    }).ToList();

                vm.IssueCountsByStatus = statusCounts;
            }

            return vm;
        }