Ejemplo n.º 1
0
        /// <summary>
        /// Gets the equipment details information for the given equipment ID. This is displayed at the top of the page.
        /// </summary>
        /// <returns>General details about the given equipment Id. </returns>
        public async Task <ManageEquipmentDetailsViewModel> GetEquipmentDetails(long equipmentId)
        {
            var equipment = await this._context.EQUIPMENTs.FindAsync(equipmentId);

            var    equipment2            = new BLL.Core.Domain.Equipment(_context, (int)equipmentId);
            var    lastInspection        = equipment.TRACK_INSPECTION.LastOrDefault();
            string lastInspectionDate    = lastInspection == null ? "Never" : lastInspection.inspection_date.ToString("dd/MMM/yyyy");
            var    nextInpectionForecast = CalculateNextInspectionDate(lastInspection, equipment);
            var    equipmentImage        = Convert.ToBase64String(equipment2.GetEquipmentImage());

            return(new ManageEquipmentDetailsViewModel()
            {
                CustomerName = equipment.Jobsite.Customer.cust_name,
                JobsiteName = equipment.Jobsite.site_name,
                Family = equipment.LU_MMTA.TYPE.typedesc,
                LastInspectionDate = lastInspectionDate,
                Ltd = equipment2.GetEquipmentLife(DateTime.Now),
                Make = equipment.LU_MMTA.MAKE.makedesc,
                Model = equipment.LU_MMTA.MODEL.modeldesc,
                NextInspectionDate = equipment.NextInspectionDate.ToString("dd/MMM/yyyy"),
                PercentWorn = Math.Round(equipment2.getEquipmentComponentsWorn(DateTime.Now).Select(c => c.wornPercentage).OrderByDescending(c => c).FirstOrDefault()),
                SerialNumber = equipment.serialno,
                Smu = equipment.currentsmu != null ? (int)equipment.currentsmu : 0,
                UnitNumber = equipment.unitno,
                EquipmentPhoto = equipmentImage,
                CustomerId = equipment.Jobsite.customer_auto,
                JobsiteId = equipment.crsf_auto,
                InspectEvery = equipment.InspectEvery,
                InspectEveryUnitTypeId = equipment.InspectEveryUnitTypeId,
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is obsolete please use Dashboard.cs/GetTotalCostOfRepairs
        /// </summary>
        /// <param name="searchItems"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <CostOfRepairsViewModel> GetTotalCostOfRepairs(List <ViewModel.SearchItem> searchItems, long userId)
        {
            SearchResult eq = new SearchResult();

            if (searchItems != null)
            {
                eq = new GETCore.Classes.GETEquipment().getEquipmentIdAndDateAdvancedSearch(1, 999999, searchItems, Convert.ToInt32(userId));
            }
            CostOfRepairsViewModel[] repairs = new CostOfRepairsViewModel[12];

            var initialDate = DateTime.Now.AddYears(-1).AddMonths(1);

            for (int i = 0; i < 12; i++)
            {
                repairs[i] = new CostOfRepairsViewModel()
                {
                    Cost  = 0,
                    Month = initialDate.AddMonths(i).ToString("MMM yy")
                };
            }

            eq.Result.ForEach(id =>
            {
                var equip = new BLL.Core.Domain.Equipment(new UndercarriageContext(), id.Id);
                var costs = equip.GetEquipmentRepairsCostForGivenYear(initialDate);
                for (int i = 0; i < 12; i++)
                {
                    repairs[i].Cost += costs.Where(c => c.Date.Month == initialDate.AddMonths(i).Month&& c.Date.Year == initialDate.AddMonths(i).Year).Select(c => c.Cost).Sum();   //equip.GetEquipmentRepairsCostForGivenMonth(initialDate.AddMonths(i));
                }
            });
            return(repairs.ToList());
        }