Exemple #1
0
        //
        // GET: /Page/
        public ActionResult Index(int page = 1)
        {
            var matrices = _matrixRepository.GetAll()
                           .OrderByDescending(m => m.Id)
                           .Skip((page - 1) * PAGE_SIZE)
                           .Take(PAGE_SIZE);

            var matrixListViewModel = new MatrixListViewModel()
            {
                Matrices   = new List <MatrixViewModel>(),
                PagingInfo = new PagingInfo {
                    CurrentPage  = page,
                    ItemsPerPage = PAGE_SIZE,
                    TotalItems   = _matrixRepository.GetAll().Count()
                }
            };


            if (matrices.Any())
            {
                foreach (var matrix in matrices)
                {
                    var model = new MatrixViewModel();

                    var buildingPart = (matrix.BuildingPartId.HasValue)
                        ? _buildingPartRepository.SingleOrDefault(matrix.BuildingPartId.Value)
                        : null;

                    var defectDescription = (matrix.DefectDescriptionId.HasValue)
                        ? _defectDescriptionRepository.SingleOrDefault(matrix.DefectDescriptionId.Value)
                        : null;

                    model.Id = matrix.Id;
                    model.BuildingPartCode = (buildingPart != null) ? (double?)buildingPart.Code : null;
                    model.BuildingPartText = (buildingPart != null) ? buildingPart.Name : null;

                    model.DefectDescriptionText = (defectDescription != null) ? defectDescription.Description : null;

                    model.Gebr      = matrix.ImportanceId;
                    model.Intencity = matrix.IntencityId;
                    model.Omvang    = matrix.ExtentId;
                    model.Condition = matrix.Condition;

                    if (matrix.ActieId.HasValue)
                    {
                        model.Action = _actionRepository.SingleOrDefault(matrix.ActieId.Value).Name;
                    }

                    model.CountHvh = matrix.HvhId;
                    model.Eenh     = ((Eenh)matrix.EenhId).ToString();
                    model.Percent  = matrix.Percent.HasValue ? matrix.Percent.Value.ToString() : string.Empty;

                    model.Cost  = matrix.Cost;
                    model.Total = matrix.Total.HasValue ? matrix.Total.Value : 0;
                    model.BTW   = matrix.BTW;
                    model.Cycle = matrix.Cycle;

                    model.StartYear = matrix.StartYear;


                    // render calendar cost
                    model.CalendarBuilder = RenderCalendarCostString(model.Total, matrix.BTW, matrix.Cycle,
                                                                     matrix.StartYear);

                    // append to list
                    matrixListViewModel.Matrices.Add(model);
                }
            }


            return(View(matrixListViewModel));
        }