Esempio n. 1
0
        public async Task <ActionResult <IEnumerable <ResponseTaskList> > > GetTasks()
        {
            var tasks = await _context.Tasks
                        .Include(x => x.Status)
                        .Include(x => x.Difficulty)
                        .Include(x => x.Priorirty)
                        .Include(x => x.Worker)
                        .ThenInclude(x => x.Speciality)
                        .ToListAsync();

            return(Ok(tasks.Select(x =>
            {
                var isExpired = DateTime.Now > x.ExpirationDate;
                var iconName = x.Status.IconUrl.Replace(Constans.ApiUrl + Constans.FileDownloadPart, string.Empty);
                var icon = isExpired ?
                           _context.Files.SingleOrDefault(y => y.Name == "Expired.png") :
                           _context.Files.SingleOrDefault(y => y.Name == iconName);
                var author = _context.Workers
                             .Include(x => x.Speciality)
                             .SingleOrDefault(y => y.Id == x.AuthorId);


                return ResponseTaskList.FromApiTask(x,
                                                    author: author,
                                                    icon: icon,
                                                    avatarWorker: _getAvatar(x.Worker.AvatarUrl),
                                                    avatarAuthor: _getAvatar(author.AvatarUrl)
                                                    );
            }).ToList()));
        }
Esempio n. 2
0
        public async Task <ActionResult <IEnumerable <ResponseTaskList> > > GetMyTasksStatus([FromQuery] string status)
        {
            var email = User.Identity.Name;
            var tasks = await _context.Tasks
                        .Include(x => x.Status)
                        .Include(x => x.Difficulty)
                        .Include(x => x.Priorirty)
                        .Include(x => x.Worker)
                        .ThenInclude(x => x.Speciality)
                        .Where(x => x.Worker.Email == email && x.Status.Name == status && x.ExpirationDate < DateTime.Now)
                        .ToListAsync();

            return(Ok(tasks.Select(x =>
            {
                var iconName = x.Status.IconUrl.Replace(Constans.ApiUrl + Constans.FileDownloadPart, string.Empty);
                var icon = _context.Files.SingleOrDefault(y => y.Name == iconName);
                var author = _context.Workers
                             .Include(x => x.Speciality)
                             .SingleOrDefault(y => y.Id == x.AuthorId);
                return ResponseTaskList.FromApiTask(x,
                                                    author: author,
                                                    icon: icon,
                                                    avatarWorker: _getAvatar(x.Worker.AvatarUrl),
                                                    avatarAuthor: _getAvatar(author.AvatarUrl)
                                                    );
            }).ToList()));
        }