public async Task <TasksViewModel> Handle(GetTaskDetailUpdateRequest request, CancellationToken cancellationToken)
        {
            var task = await _context.Tasks.AsNoTracking()
                       .FirstOrDefaultAsync(x => x.Id == request.IdTask);

            var edtId   = _context.Campaign.Find(task.IdCampaign).IdEditor;
            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 taskView = new TasksViewModel()
            {
                Title       = task.Title,
                Deadline    = task.Deadline,
                PublishTime = task.PublishTime,
                Writer      = Writter,
                Description = task.Description,
                Status      = Status,
                StartedDate = task.StartedDate,
                Id          = task.Id,
                Tags        = lstTag
            };

            return(taskView);
        }
Exemplo n.º 2
0
        public async Task <List <TasksViewModel> > Handle(GetListTaskByIdMarketerRequest request, CancellationToken cancellationToken)
        {
            var lstIdCampaign = await _context.Campaign.AsNoTracking().Where(x => x.IdMarketer == request.IdMartketer).ToListAsync();

            var lstTask = new List <TasksViewModel>();

            foreach (var item in lstIdCampaign)
            {
                var task = _context.Tasks.Where(x => x.IdCampaign == item.Id && (x.Status == 5 || x.Status == 6 || x.Status == 7)).ToList();
                foreach (var itemtask in task)
                {
                    var Writter = new UsersModels
                    {
                        Id   = itemtask.IdWriter,
                        Name = _context.Users.FirstOrDefault(x => x.Id == itemtask.IdWriter).Name
                    };
                    var Status = new StatusModels
                    {
                        Id    = itemtask.Status,
                        Name  = _context.StatusTasks.FirstOrDefault(x => x.Id == itemtask.Status).Name,
                        Color = _context.StatusTasks.FirstOrDefault(x => x.Id == itemtask.Status).Color
                    };
                    var taskView = new TasksViewModel()
                    {
                        Title       = itemtask.Title,
                        Deadline    = itemtask.Deadline,
                        PublishTime = itemtask.PublishTime,
                        Writer      = Writter,
                        //Description = itemtask.Description,
                        Status      = Status,
                        StartedDate = itemtask.StartedDate,
                        Id          = itemtask.Id
                    };
                    lstTask.Add(taskView);
                }
            }
            return(lstTask);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public async Task <TasksViewModel> Handle(CreateTaskRequest request, CancellationToken cancellationToken)
        {
            //var task = new Tasks
            //{
            //    IdCampaign = request.Task.IdCampaign,
            //    IdWriter = request.Task.IdWriter,
            //    Description = request.Task.Description,
            //    Deadline = request.Task.Deadline,
            //    PublishTime = request.Task.PublishTime,
            //    Title = request.Task.Title,
            //    StartedDate = DateTime.UtcNow,
            //    ModifiedDate = DateTime.UtcNow,
            //    Status = 1
            //};
            //contentodbContext.Tasks.Add(task);
            //await contentodbContext.SaveChangesAsync();
            //return task;
            var transaction = contentodbContext.Database.BeginTransaction();

            try
            {
                var Tags = new List <TasksTags>();

                foreach (var item in request.Task.Tags)
                {
                    var tag = new TasksTags {
                        IdTag = item.Id, CreatedDate = DateTime.UtcNow
                    };
                    Tags.Add(tag);
                }
                var task = new Tasks
                {
                    IdCampaign   = request.Task.IdCampaign,
                    IdWriter     = request.Task.IdWriter,
                    Deadline     = request.Task.Deadline,
                    Description  = request.Task.Description,
                    PublishTime  = request.Task.PublishTime,
                    Title        = request.Task.Title,
                    StartedDate  = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    TasksTags    = Tags,
                    Status       = 1
                };
                contentodbContext.Attach(task);
                contentodbContext.Tasks.Add(task);
                await contentodbContext.SaveChangesAsync(cancellationToken);

                var ReturnTags = new List <TagsViewModel>();

                foreach (var item in task.TasksTags)
                {
                    var tag = new TagsViewModel {
                        Id = item.IdTag, Name = contentodbContext.Tags.Find(item.IdTag).Name
                    };
                    ReturnTags.Add(tag);
                }
                var status = new StatusModels();

                status.Id    = task.Status;
                status.Name  = contentodbContext.StatusTasks.FirstOrDefault(x => x.Id == task.Status).Name;
                status.Color = contentodbContext.StatusTasks.FirstOrDefault(x => x.Id == task.Status).Color;

                var writer = new UsersModels
                {
                    Id   = task.IdWriter,
                    Name = contentodbContext.Users.FirstOrDefault(x => x.Id == task.IdWriter).Name
                };
                var taskModel = new TasksViewModel
                {
                    Deadline    = task.Deadline,
                    Writer      = writer,
                    Id          = task.Id,
                    Description = task.Description,
                    StartedDate = task.StartedDate,
                    PublishTime = task.PublishTime,
                    Tags        = ReturnTags,
                    Status      = status,
                    Title       = task.Title,
                };
                var upStatus = contentodbContext.Campaign.FirstOrDefault(y => y.Id == request.Task.IdCampaign);
                if (upStatus.Status == 1)
                {
                    upStatus.Status = 2;
                    contentodbContext.Attach(upStatus);
                    contentodbContext.Entry(upStatus).Property(x => x.Status).IsModified = true;
                    await contentodbContext.SaveChangesAsync(cancellationToken);
                }

                transaction.Commit();
                return(taskModel);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                return(null);
            }
        }
        public async Task <ReturnUpdateTaskModel> Handle(UpdateTaskEditorCommand request, CancellationToken cancellationToken)
        {
            var transaction = contentodbContext.Database.BeginTransaction();

            try
            {
                var upTask       = contentodbContext.Tasks.AsNoTracking().Include(y => y.TasksTags).FirstOrDefault(x => x.Id == request.IdTask);
                var resultReturn = new ReturnUpdateTaskModel();
                var Tags         = new List <TasksTags>();
                var TagsReturn   = new List <TagsViewModel>();
                var writer       = new UsersModels();
                if (upTask == null)
                {
                    return(null);
                }
                if (upTask.Status == 1)
                {
                    foreach (var item in request.Tags)
                    {
                        var tag = new TasksTags {
                            IdTag = item.Id, ModifiedDate = DateTime.UtcNow
                        };
                        var tagReturn = new TagsViewModel {
                            Id = item.Id, Name = contentodbContext.Tags.FirstOrDefault(x => x.Id == item.Id).Name
                        };
                        Tags.Add(tag);
                        TagsReturn.Add(tagReturn);
                    }
                    contentodbContext.TasksTags.RemoveRange(upTask.TasksTags);
                    upTask.Title       = request.Title;
                    upTask.IdWriter    = request.IdWriter;
                    upTask.Description = request.Description;
                    upTask.Deadline    = request.Deadline;
                    upTask.PublishTime = request.PublishTime;
                    upTask.TasksTags   = Tags;

                    upTask.ModifiedDate = DateTime.UtcNow;
                    contentodbContext.Attach(upTask);
                    contentodbContext.Entry(upTask).State = EntityState.Modified;

                    await contentodbContext.SaveChangesAsync(cancellationToken);

                    writer.Id   = upTask.IdWriter;
                    writer.Name = contentodbContext.Users.FirstOrDefault(x => x.Id == upTask.IdWriter).Name;

                    resultReturn.Title       = upTask.Title;
                    resultReturn.Writer      = writer;
                    resultReturn.Description = upTask.Description;
                    resultReturn.Deadline    = upTask.Deadline;
                    resultReturn.PublishTime = upTask.PublishTime;
                    resultReturn.Tags        = TagsReturn;
                    resultReturn.Id          = request.IdTask;
                    transaction.Commit();
                    return(resultReturn);
                }
                //update with status !=1
                foreach (var item in request.Tags)
                {
                    var tag = new TasksTags {
                        IdTag = item.Id, ModifiedDate = DateTime.UtcNow
                    };
                    var tagReturn = new TagsViewModel {
                        Id = item.Id, Name = contentodbContext.Tags.FirstOrDefault(x => x.Id == item.Id).Name
                    };
                    Tags.Add(tag);
                    TagsReturn.Add(tagReturn);
                }
                upTask.Deadline    = request.Deadline;
                upTask.PublishTime = request.PublishTime;
                if (request.Deadline > DateTime.UtcNow)
                {
                    upTask.Status = 2;
                }
                contentodbContext.Attach(upTask);
                contentodbContext.Entry(upTask).State = EntityState.Modified;
                await contentodbContext.SaveChangesAsync(cancellationToken);

                var Status = new StatusModels()
                {
                    Id    = upTask.Status,
                    Name  = contentodbContext.StatusTasks.FirstOrDefault(x => x.Id == upTask.Status).Name,
                    Color = contentodbContext.StatusTasks.FirstOrDefault(x => x.Id == upTask.Status).Color
                };
                writer.Id   = upTask.IdWriter;
                writer.Name = contentodbContext.Users.FirstOrDefault(x => x.Id == upTask.IdWriter).Name;

                resultReturn.Title       = upTask.Title;
                resultReturn.Writer      = writer;
                resultReturn.Description = upTask.Description;
                resultReturn.Deadline    = upTask.Deadline;
                resultReturn.PublishTime = upTask.PublishTime;
                resultReturn.Tags        = TagsReturn;
                resultReturn.Status      = Status;
                resultReturn.Id          = request.IdTask;
                resultReturn.Deadline    = upTask.Deadline;
                transaction.Commit();
                return(resultReturn);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                return(null);
            }
        }