コード例 #1
0
        public async Task <ContentDetailReturn> Handle(GetContentDetailRequest request, CancellationToken cancellationToken)
        {
            var content = _context.Tasks.AsNoTracking()
                          .Where(x => x.Id == request.IdTask)
                          .Select(x => new
            {
                x,
                Contents  = x.Contents.Where(c => c.IsActive == true).FirstOrDefault(),
                TasksTags = x.TasksTags.ToList(),
            }).FirstOrDefault();
            List <string> imgs = getImage(content.Contents.TheContent);

            if (imgs.Count == 0)
            {
                imgs.Add("https://marketingland.com/wp-content/ml-loads/2015/11/content-marketing-idea-lightbulb-ss-1920.jpg");
            }
            var Cnt = new ContentModels
            {
                Id      = content.Contents.Id,
                Content = content.Contents.TheContent,
                Name    = content.Contents.Name
            };
            var Writter = new UsersModels
            {
                Id   = content.x.IdWriter,
                Name = _context.Users.Find(content.x.IdWriter).Name
            };
            var lstTag = new List <TagsViewModel>();

            foreach (var item in content.TasksTags)
            {
                var Tag = new TagsViewModel
                {
                    Id   = item.IdTag,
                    Name = _context.Tags.Find(item.IdTag).Name
                };
                lstTag.Add(Tag);
            }
            var ContentReturn = new ContentDetailReturn
            {
                IdTask      = content.x.Id,
                PublishTime = content.x.PublishTime,
                Contents    = Cnt,
                Image       = imgs,
                ListTags    = lstTag,
                Writer      = Writter
            };

            return(ContentReturn);
        }
コード例 #2
0
        public async Task <ContentDirectoryInfo> GetAllDirectoryContentAsync(
            string directoryPath, ContentTypeToFind contentType)
        {
            directoryPath.ThrowIfNullOrWhiteSpace(nameof(directoryPath));

            // TODO: get paging info parameters from View.
            IReadOnlyDictionary <string, IReadOnlyList <string> > result = await ContentFinder
                                                                           .FindContentForDirWithPagingAsync(
                directoryName : directoryPath,
                contentType : contentType.ConvertToLibraryEnum(),
                pagingInfo : ContentModels.CreateOption(new ContentModels.PagingInfo(0, 10))
                )
                                                                           .ConfigureAwait(continueOnCapturedContext: false);

            return(new ContentDirectoryInfo(directoryPath, contentType, result));
        }
コード例 #3
0
        public async Task <List <ContentViewer> > Handle(GetContentViewerRequest request, CancellationToken cancellationToken)
        {
            if (request.Tags.Count > 0 && !request.Tags.Contains(0))
            {
                var content = _context.Tasks.AsNoTracking()
                              .Where(x => x.Status == 7 &&
                                     x.Contents.Any(t => t.IsActive == true) &&
                                     x.TasksChannels.Any(t => t.IdChannel == 1) &&
                                     x.TasksTags.Any(z => request.Tags.Contains(z.IdTag)))
                              .OrderByDescending(x => x.PublishTime)
                              .Select(x => new
                {
                    x,
                    Contents  = x.Contents.Where(c => c.IsActive == true).FirstOrDefault(),
                    TasksTags = x.TasksTags.ToList()
                }).ToList();
                var lstContentReturn = new List <ContentViewer>();
                foreach (var item in content)
                {
                    List <string> imgs = getImage(item.Contents.TheContent);
                    if (imgs.Count == 0)
                    {
                        imgs.Add("https://marketingland.com/wp-content/ml-loads/2015/11/content-marketing-idea-lightbulb-ss-1920.jpg");
                    }
                    var Cnt = new ContentModels
                    {
                        Id   = item.Contents.Id,
                        Name = item.Contents.Name
                    };
                    var lstTag = new List <TagsViewModel>();
                    foreach (var item1 in item.TasksTags)
                    {
                        var Tag = new TagsViewModel
                        {
                            Id   = item1.IdTag,
                            Name = _context.Tags.Find(item1.IdTag).Name
                        };
                        lstTag.Add(Tag);
                    }
                    var ContentReturn = new ContentViewer
                    {
                        IdTask      = item.x.Id,
                        PublishTime = item.x.PublishTime,
                        Contents    = Cnt,
                        Image       = imgs,
                        ListTags    = lstTag
                    };
                    lstContentReturn.Add(ContentReturn);
                }

                return(lstContentReturn);
            }
            else
            {
                var content = _context.Tasks.AsNoTracking()
                              .Where(x => x.Status == 7 &&
                                     x.Contents.Any(t => t.IsActive == true) &&
                                     x.TasksChannels.Any(t => t.IdChannel == 1))
                              .OrderByDescending(x => x.PublishTime)
                              .Select(x => new
                {
                    x,
                    Contents  = x.Contents.Where(c => c.IsActive == true).FirstOrDefault(),
                    TasksTags = x.TasksTags.ToList()
                }).ToList();
                var lstContentReturn = new List <ContentViewer>();
                foreach (var item in content)
                {
                    List <string> imgs = getImage(item.Contents.TheContent);
                    if (imgs.Count == 0)
                    {
                        imgs.Add("https://marketingland.com/wp-content/ml-loads/2015/11/content-marketing-idea-lightbulb-ss-1920.jpg");
                    }
                    var Cnt = new ContentModels
                    {
                        Id   = item.Contents.Id,
                        Name = item.Contents.Name
                    };
                    var lstTag = new List <TagsViewModel>();
                    foreach (var item1 in item.TasksTags)
                    {
                        var Tag = new TagsViewModel
                        {
                            Id   = item1.IdTag,
                            Name = _context.Tags.Find(item1.IdTag).Name
                        };
                        lstTag.Add(Tag);
                    }
                    var ContentReturn = new ContentViewer
                    {
                        IdTask      = item.x.Id,
                        PublishTime = item.x.PublishTime,
                        Contents    = Cnt,
                        Image       = imgs,
                        ListTags    = lstTag
                    };
                    lstContentReturn.Add(ContentReturn);
                }

                return(lstContentReturn);
            }
        }
コード例 #4
0
        public async Task <TasksViewModel> Handle(GetTaskDetailRequest request, CancellationToken cancellationToken)
        {
            var task = await _context.Tasks.AsNoTracking().Include(i => i.Contents)
                       .FirstOrDefaultAsync(x => x.Id == request.IdTask);

            var edtId    = _context.Campaign.Find(task.IdCampaign).IdEditor;
            var content  = task.Contents.Where(x => x.IsActive == true).FirstOrDefault();
            var campaign = _context.Campaign.Find(task.IdCampaign).Title;
            var lstTag   = new List <TagsViewModel>();
            var lstTags  = _context.TasksTags.Where(x => x.IdTask == request.IdTask).ToList();

            foreach (var item in lstTags)
            {
                var tag = new TagsViewModel();
                tag.Name = _context.Tags.FirstOrDefault(x => x.Id == item.IdTag).Name;
                tag.Id   = item.IdTag;
                lstTag.Add(tag);
            }
            var Writter = new UsersModels
            {
                Id   = task.IdWriter,
                Name = _context.Users.FirstOrDefault(x => x.Id == task.IdWriter).Name
            };
            var Status = new StatusModels
            {
                Id    = task.Status,
                Name  = _context.StatusTasks.FirstOrDefault(x => x.Id == task.Status).Name,
                Color = _context.StatusTasks.FirstOrDefault(x => x.Id == task.Status).Color
            };
            var Editor = new UsersModels
            {
                Id   = edtId,
                Name = _context.Users.FirstOrDefault(x => x.Id == edtId).Name
            };
            var Content = new ContentModels
            {
                Id      = content.Id,
                Content = content.TheContent,
                Name    = content.Name
            };
            var Comment = new Comments();

            if (task.Contents.FirstOrDefault(x => x.IsActive == true).IdComment != null)
            {
                Comment.Comment = _context.Comments.FirstOrDefault(x => x.Id == content.IdComment).Comment;
            }

            var taskView = new TasksViewModel()
            {
                Title       = task.Title,
                Deadline    = task.Deadline,
                PublishTime = task.PublishTime,
                Writer      = Writter,
                Description = task.Description,
                Status      = Status,
                StartedDate = task.StartedDate,
                Editor      = Editor,
                Content     = Content,
                Comment     = Comment,
                Id          = task.Id,
                Tags        = lstTag,
                Campaign    = campaign
            };

            return(taskView);
        }
コード例 #5
0
        public async Task <TasksViewModel> Handle(StartTaskCommand request, CancellationToken cancellationToken)
        {
            var transaction = _context.Database.BeginTransaction();

            try
            {
                var newContent = new Contents
                {
                    CreatedDate = DateTime.UtcNow,
                    Version     = 1,
                    IdTask      = request.IdTask,
                    IsActive    = true
                };
                _context.Contents.Add(newContent);
                var upTask = _context.Tasks.AsNoTracking().Include(y => y.Contents).FirstOrDefault(x => x.Id == request.IdTask);
                upTask.Status = 2;
                _context.Attach(upTask);
                _context.Entry(upTask).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                // get detail task
                var task = await _context.Tasks.AsNoTracking().Include(i => i.Contents).FirstOrDefaultAsync(x => x.Id == request.IdTask);

                var content  = task.Contents.Where(x => x.IsActive == true).FirstOrDefault();
                var edtId    = _context.Campaign.Find(task.IdCampaign).IdEditor;
                var campaign = _context.Campaign.Find(task.IdCampaign).Title;
                var lstTag   = new List <TagsViewModel>();
                var lstTags  = _context.TasksTags.Where(x => x.IdTask == request.IdTask).ToList();
                foreach (var item in lstTags)
                {
                    var tag = new TagsViewModel();
                    tag.Name = _context.Tags.FirstOrDefault(x => x.Id == item.IdTag).Name;
                    tag.Id   = item.IdTag;
                    lstTag.Add(tag);
                }
                var Writter = new UsersModels
                {
                    Id   = task.IdWriter,
                    Name = _context.Users.FirstOrDefault(x => x.Id == task.IdWriter).Name
                };
                var Status = new StatusModels
                {
                    Id    = task.Status,
                    Name  = _context.StatusTasks.FirstOrDefault(x => x.Id == task.Status).Name,
                    Color = _context.StatusTasks.FirstOrDefault(x => x.Id == task.Status).Color
                };
                var Editor = new UsersModels
                {
                    Id   = edtId,
                    Name = _context.Users.FirstOrDefault(x => x.Id == edtId).Name
                };
                var Content = new ContentModels
                {
                    Id      = content.Id,
                    Content = content.TheContent,
                    Name    = content.Name
                };
                var taskView = new TasksViewModel()
                {
                    Title       = task.Title,
                    Deadline    = task.Deadline,
                    PublishTime = task.PublishTime,
                    Writer      = Writter,
                    Description = task.Description,
                    Status      = Status,
                    StartedDate = task.StartedDate,
                    Editor      = Editor,
                    Content     = Content,
                    Id          = task.Id,
                    Tags        = lstTag,
                    Campaign    = campaign
                };
                transaction.Commit();
                return(taskView);
            }
            catch (Exception)
            {
                transaction.Rollback();
                return(null);
            }
        }