Exemplo n.º 1
0
        public async Task <ActionResult> Details(long id = 0)
        {
            using (_entities = new DBEntities())
            {
                var taskDetailsVm = new TaskDetailsVm();

                var taskMaster = await _entities.TaskMasters.Where(s => s.TaskMasterId == id && !s.IsDelete)
                                 .FirstOrDefaultAsync();

                if (taskMaster != null)
                {
                    //Assigny task details to view model
                    taskDetailsVm.CopyProperties(taskMaster);

                    //Convert data to string format
                    taskDetailsVm.StartDateString = taskMaster.StartDate.ToString("dd/MM/yyyy");
                    if (taskMaster.EndDate != null)
                    {
                        taskDetailsVm.EndDateString = taskMaster.EndDate.Value.ToString("dd/MM/yyyy");
                    }

                    //Get task attachments
                    taskDetailsVm.TaskAttachments = await _entities.TaskAttachments
                                                    .Where(s => s.TaskMasterId == taskMaster.TaskMasterId).ToListAsync();

                    //Get task comments
                    taskDetailsVm.CommentMasters = await _entities.CommentMasters
                                                   .Where(s => s.TaskMasterId == taskMaster.TaskMasterId).ToListAsync();

                    return(View(taskDetailsVm));
                }

                return(RedirectToAction("Create"));
            }
        }
        public ActionResult Details(int?id)
        {
            TaskDetailsVm model = new TaskDetailsVm();

            model.PagerComment      = model.PagerComment ?? new Pager();
            model.PagerLogWork      = model.PagerLogWork ?? new Pager();
            model.FilterComment     = model.FilterComment ?? new CommentsFilter();
            model.FilterLoggedWorks = model.FilterLoggedWorks ?? new LoggedWorksFilter();
            TryUpdateModel(model);

            TaskRepo repository = RepositoryFactory.GetTasksRepository();
            Task     task       = repository.GetById(Convert.ToInt32(id));

            model.Id              = task.Id;
            model.UserId          = task.UserId;
            model.Title           = task.Title;
            model.Description     = task.Description;
            model.ResponsibleUser = task.ResponsibleUser;
            model.Creator         = task.Creator;
            model.Status          = task.Status;
            model.LastChange      = task.LastChange;
            model.CreateTime      = task.CreateTime;

            CommentRepo    comRepo     = RepositoryFactory.GetCommentsRepository();
            LoggedWorkRepo logWorkRepo = RepositoryFactory.GetLoggedWorksRepository();

            string action     = this.ControllerContext.RouteData.Values["action"].ToString();
            string controller = this.ControllerContext.RouteData.Values["controller"].ToString();

            //comments
            model.FilterComment.Prefix = "FilterComment.";
            string commentsPrefix = "PagerComment.";

            model.FilterComment.TaskId = task.Id;
            int commentsResultCount = comRepo.Count(model.FilterComment.BuildFilter());

            model.PagerComment = new Pager(commentsResultCount, model.PagerComment.CurrentPage, model.PagerComment.PageSize, commentsPrefix, action, controller);
            model.FilterComment.ParentPager = model.PagerComment;
            model.CommentsList = comRepo.GetAll(model.FilterComment.BuildFilter(), model.PagerComment.CurrentPage, model.PagerComment.PageSize.Value).ToList();

            //loggedwork
            model.FilterLoggedWorks.Prefix = "FilterLoggedWorks.";
            string loggedWorkPrefix = "PagerLogWork.";

            model.FilterLoggedWorks.TaskId = task.Id;
            int loggedWorkResultCount = logWorkRepo.Count(model.FilterLoggedWorks.BuildFilter());

            model.PagerLogWork = new Pager(loggedWorkResultCount, model.PagerLogWork.CurrentPage, model.PagerLogWork.PageSize, loggedWorkPrefix, action, controller);
            model.FilterLoggedWorks.ParentPager = model.PagerLogWork;
            model.LoggedWorkList = logWorkRepo.GetAll(model.FilterLoggedWorks.BuildFilter(), model.PagerLogWork.CurrentPage, model.PagerLogWork.PageSize.Value).ToList();

            return(View(model));
        }