예제 #1
0
        public static List <TaskViewModel> Search(DateTime?startDate, DateTime?endDate, string orderno = "", string idsend = "", string idrevc = "")
        {
            IQueryable <Task>    queryable  = CommonSearch(startDate, endDate, orderno, idsend, idrevc);
            List <Task>          entities   = queryable.ToList();
            List <TaskViewModel> viewModels = new List <TaskViewModel>();

            viewModels = entities.Select(mod =>
            {
                TaskViewModel viewModel = new TaskViewModel();
                viewModel.CopyFromBase(mod);
                return(viewModel);
            }).ToList();
            viewModels = viewModels.Distinct(new TaskViewModel()).ToList();

            TN db = new TN();
            List <TaskRecver>          taskRecvers          = db.TaskRecvers.ToList();
            List <TaskRecverViewModel> taskRecverViewModels = taskRecvers.Select(mod =>
            {
                TaskRecverViewModel viewModel = new TaskRecverViewModel();
                viewModel.CopyFromBase(mod);
                return(viewModel);
            }).ToList();

            viewModels = viewModels.Select(mod =>
            {
                mod.TaskRecvers = taskRecverViewModels.Where(en => en.idtask == mod.idtask).ToList();
                return(mod);
            }).ToList();

            return(viewModels);
        }
예제 #2
0
        public static TaskViewModel GetViewModel(string idtask)
        {
            TN            db        = new TN();
            TaskViewModel viewModel = null;
            Task          task      = db.Tasks.Where(en => en.idtask == idtask).FirstOrDefault();

            if (task != null)
            {
                viewModel = new TaskViewModel();
                viewModel.CopyFromBase(task);
                List <TaskRecver> taskRecvers = db.TaskRecvers.Where(en => en.idtask == idtask).ToList();
                viewModel.TaskRecvers = taskRecvers.Select(mod => {
                    TaskRecverViewModel model = new TaskRecverViewModel();
                    model.CopyFromBase(mod);
                    return(model);
                }).ToList();
            }

            return(viewModel);
        }