コード例 #1
0
        public async Task <bool> CreateAgileItem(CreateAgileItemDto agileItem)
        {
            // Create item with necessary server side properties
            var fullItem = CreateServerSideAgileItem(agileItem);

            try
            {
                if (fullItem.AgileItemType != Models.Types.AgileItemType.SuperStory)
                {
                    var parent = await _context.AgileItems.Where(i => i.Id == fullItem.ParentId).FirstOrDefaultAsync();

                    var board = await _context.Boards.Where(b => b.Id == fullItem.BoardId).FirstOrDefaultAsync();

                    if (parent == null || board == null)
                    {
                        throw new Exception("Invalid parent or board Id");
                    }
                }

                await _context.AgileItems.AddAsync(fullItem);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError("Exception when creating agile item, Exception:" + e + "Stack trace:" + e.StackTrace, "item: " + agileItem);
            }
            return(false);
        }
コード例 #2
0
        // called by the background service every 24 hours
        // not performance important, can take as long as it needs as work is done on inexpensive background thread.
        public async Task <bool> SaveDailyChartData()
        {
            try
            {
                var boardIds = await _context.Boards.Where(b => b.IsActive == true)
                               .Select(i => i.Id)
                               .ToListAsync();

                foreach (var boardId in boardIds)
                {
                    var loggedTimes = await _context.AgileItems.Where(s => s.BoardId == boardId && s.IsActive == true).Select(t => t.LoggedTime).ToListAsync();

                    int totalTime = 0;
                    foreach (var loggedTime in loggedTimes)
                    {
                        if (loggedTime != null)
                        {
                            totalTime += Convert.ToInt32(loggedTime);
                        }
                    }
                    var completeTasks = await _context.AgileItems.Where(s => s.BoardId == boardId == s.IsActive == true && s.Status == Models.Types.Status.Complete).CountAsync();

                    var dailyData = new DailyDataDto
                    {
                        Id            = Guid.NewGuid(),
                        BoardId       = boardId,
                        Date          = DateTime.Now,
                        LoggedHours   = totalTime,
                        TasksComplete = completeTasks,
                    };

                    _context.DailyData.Add(dailyData);
                    await _context.SaveChangesAsync();
                }
                return(true);
            }
            catch (Exception e)
            {
                // exception saving daily data
            }
            return(false);
        }