Esempio n. 1
0
        public async Task <ActionResult <List <ProjectTaskViewModel> > > GetItems()
        {
            try
            {
                var items = await _projectTaskRepository.ProjectTasksAsync();

                return(items.Select(e => _mapper.Map <ProjectTaskViewModel>(e)).ToList());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 2
0
        //например как https://localhost:44301/api/GanttChart
        public async Task <string> GetGanttItems()
        {
            var taskList = await _projectTaskRepository.ProjectTasksAsync();

            //TODO:тут - формировать лист для возврата!
            var srcList = new List <GanttItemModel>();

            foreach (ProjectTask item in taskList)
            {
                var newGanttItem = new GanttItemModel()
                {
                    Id            = item.ProjectTaskId,
                    Label         = item.Details,
                    TaskCompleted = item.EndFact != null ? true : false,
                    ProjectName   = item.Project?.ProjectName
                };
                newGanttItem.Duration = 1;
                //newGanttItem.Start = DateTime.Now;//TODO: возможно нужна какая-то минимальная дата по умолчанию иначе будет сыпаться ошибка
                DateTime?start = item.StartFact ?? item.StartPlan;
                DateTime?end   = item.EndFact ?? item.EndPlan;
                if (end != null && start != null)
                {
                    var duration1 = (int)((DateTime)end).Subtract((DateTime)start).TotalHours;
                    newGanttItem.Duration  = duration1 > 0 ? duration1 : newGanttItem.Duration;
                    newGanttItem.Duration *= 60 * 60 * 1000;
                }

                foreach (var performer in item.ProjectTaskPerformers.Where(q => !q.Deleted))
                {
                    newGanttItem.User += performer.User.ShortName + "; ";
                }
                //newGanttItem.User
                if (start != null)
                {
                    newGanttItem.Start = (DateTime)start; //(int) ((DateTime) start).Subtract(DateTime.Now).TotalHours;
                }
                if (end != null)
                {
                    newGanttItem.End = end;
                }
                newGanttItem.Percent = newGanttItem.TaskCompleted ? 100 : 0;
                newGanttItem.Type    = "project";
                srcList.Add(newGanttItem);
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            srcList = srcList.OrderByDescending(q => q.Start).ThenByDescending(q => q.End).ToList();
            return(JsonConvert.SerializeObject(srcList, settings));
        }