Пример #1
0
        public ActionResult Details(int id)
        {
            //all object that we want to map with tryupdatemodel
            TaskDetailsVM model = new TaskDetailsVM();

            model.PagerComments = new Pager();
            model.PagerWorkLog  = new Pager();
            TryUpdateModel(model);

            //All repositories
            TasksRepository    taskRepo    = new TasksRepository();
            UsersRepository    userRepo    = new UsersRepository();
            TimeRepository     timeRepo    = new TimeRepository();
            CommentsRepository commentRepo = new CommentsRepository();

            //get the specific name that we show (inache kazano da ne e int kakto vika Bai Georgi)
            TaskEntity task            = (id <= 0) ? new TaskEntity() : taskRepo.GetById(id);
            UserEntity creatorUser     = null;
            UserEntity responsibleUser = null;

            if (id == 0)
            {
                creatorUser     = userRepo.GetById(AuthenticationManager.LoggedUser.Id);
                responsibleUser = userRepo.GetById(AuthenticationManager.LoggedUser.Id);
            }
            else
            {
                creatorUser     = userRepo.GetById(task.CreatorId);
                responsibleUser = userRepo.GetById(task.ResponsibleUsers);
            }

            //fill the model
            model.Id              = task.Id;
            model.CreatorName     = creatorUser.FirstName + " " + creatorUser.LastName;
            model.ResponsibleName = responsibleUser.FirstName + " " + responsibleUser.LastName;
            model.Content         = task.Content;
            model.Title           = task.Title;
            model.CreateTime      = task.CreateTime;
            UserEntity Users = userRepo.GetAll().FirstOrDefault(u => u.Id == task.CreatorId);

            //fill the model's list that give to the partialsViews
            model.CommentsList = commentRepo.GetAll(c => c.TaskId == model.Id, model.PagerComments.CurrentPage, model.PagerComments.PageSize).ToList();
            model.WorkLogList  = timeRepo.GetAll(w => w.TaskId == model.Id, model.PagerWorkLog.CurrentPage, model.PagerWorkLog.PageSize).ToList();

            //fill the pager with the specific data //Yanka beshe tuk :D :D :D kaza da go iztriq ama nqma da e

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

            model.PagerComments = new Pager(commentRepo.GetAll().Count(c => c.TaskId == model.Id), model.PagerComments.CurrentPage, "PagerComments.", action, controller, model.PagerComments.PageSize);

            model.PagerWorkLog = new Pager(timeRepo.GetAll().Count(l => l.TaskId == model.Id), model.PagerWorkLog.CurrentPage, "PagerWorkLog.", action, controller, model.PagerWorkLog.PageSize);

            return(View(model));
        }
        public ActionResult Details(TaskDetailsVM model)
        {
            TasksRepository tasksRepository = new TasksRepository();

            model.Item = tasksRepository.GetById(model.Id);
            if (model == null)
            {
                return(RedirectToAction("Index", "Tasks"));
            }

            UsersRepository usersRepository = new UsersRepository();

            model.Users = usersRepository.GetAll();
            CommentsRepository commentsRepo = new CommentsRepository();
            LogworksRepository logworkRepo  = new LogworksRepository();

            model.CommentsPager     = model.CommentsPager ?? new PagerVM();
            model.CommentsFilter    = model.CommentsFilter ?? new CommentsFilterVM();
            model.CommentsFilter.Id = model.Id;
            var filter = model.CommentsFilter.BuildFilter();

            model.CommentsPager.Prefix       = "CommentsPager";
            model.CommentsFilter.Prefix      = "CommentsFilter";
            model.CommentsPager.ItemsPerPage = model.CommentsPager.ItemsPerPage == 0 ? 5 : model.CommentsPager.ItemsPerPage;
            model.CommentsPager.PageCount    = (int)Math.Ceiling(commentsRepo.Count(filter) / (decimal)model.CommentsPager.ItemsPerPage);
            model.CommentsPager.PageCount    = model.CommentsPager.PageCount == 0 ? 1 : model.CommentsPager.PageCount;
            model.Comments = commentsRepo.GetAll(filter, model.CommentsPager.CurrentPage, model.CommentsPager.ItemsPerPage);

            model.LogworksPager    = model.LogworksPager ?? new PagerVM();
            model.LogworkFilter    = model.LogworkFilter ?? new LogworkFilterVM();
            model.LogworkFilter.Id = model.Id;
            var logworkFilter = model.LogworkFilter.BuildFilter();

            model.LogworksPager.Prefix       = "LogworksPager";
            model.LogworkFilter.Prefix       = "LogworkFilter";
            model.LogworksPager.ItemsPerPage = model.LogworksPager.ItemsPerPage == 0 ? 5 : model.LogworksPager.ItemsPerPage;
            model.LogworksPager.PageCount    = (int)Math.Ceiling(logworkRepo.Count(logworkFilter) / (decimal)model.LogworksPager.ItemsPerPage);
            model.LogworksPager.PageCount    = model.LogworksPager.PageCount == 0 ? 1 : model.LogworksPager.PageCount;
            model.Logworks = logworkRepo.GetAll(logworkFilter, model.LogworksPager.CurrentPage, model.LogworksPager.ItemsPerPage);

            return(View(model));
        }