public string insertMaintenanceType(MaintenanceTypeDto maintenanceType)
        {
            GFI_AMM_VehicleMaintTypes maintType = new GFI_AMM_VehicleMaintTypes();

            if (maintenanceType.MaintenanceTypeId != 0)
            {
                maintType = dbCon.GFI_AMM_VehicleMaintTypes.SingleOrDefault(c => c.MaintTypeId == maintenanceType.MaintenanceTypeId);
            }
            maintType.MaintCatId_cbo        = maintenanceType.CategoryId;
            maintType.Description           = maintenanceType.Description;
            maintType.OccurrenceEngineHrsTh = maintenanceType.EngineHrsBasedAlertThreshold;
            maintType.OccurrenceEngineHrs   = maintenanceType.EngineHrsBasedMaintenanceDue;
            maintType.OccurrenceDuration    = maintenanceType.OccurrenceDuration;
            maintType.OccurrenceDurationTh  = maintenanceType.TimeBasedAlertThreshold;
            maintType.OccurrenceFixedDate   = maintenanceType.OccurenceFixedDate;
            maintType.OccurrenceFixedDateTh = maintenanceType.OccurenceFixedDateThreshold;
            maintType.OccurrenceKM          = maintenanceType.KMBasedMaintenanceDue;
            maintType.OccurrenceKMTh        = maintenanceType.KMBasedAlertThreshold;
            maintType.OccurrencePeriod_cbo  = maintenanceType.TimeBasedPeriod;
            maintType.OccurrenceType        = maintenanceType.IsFixedDateChecked == true?0:1;
            maintType.One_Off     = maintenanceType.One_Off;
            maintType.UpdatedDate = System.DateTime.Now;
            if (maintenanceType.MaintenanceTypeId == 0)
            {
                dbCon.GFI_AMM_VehicleMaintTypes.Add(maintType);
            }
            dbCon.SaveChanges();
            return("");
        }
        public ActionResult CreateMaintenanceType(MaintenanceTypeDto maintType)
        {
            var maintTypeRepo = new MaintenanceTypeRepo();
            var statusLst     = maintTypeRepo.insertMaintenanceType(maintType);

            return(Json("Record saved successfully."));
        }
        public MaintenanceTypeDto getMaintenanceTypeByID(int maintenanceType)
        {
            var maintenanceResult = dbCon.GFI_AMM_VehicleMaintTypes.Where(x => x.MaintTypeId == maintenanceType).Select(x => new MaintenanceTypeDto
            {
                MaintenanceTypeId            = x.MaintTypeId,
                CategoryId                   = x.MaintCatId_cbo ?? 0,
                Description                  = x.Description,
                EngineHrsBasedMaintenanceDue = x.OccurrenceEngineHrs ?? 0,
                EngineHrsBasedAlertThreshold = x.OccurrenceEngineHrsTh ?? 0,
                KMBasedMaintenanceDue        = x.OccurrenceKM ?? 0,
                KMBasedAlertThreshold        = x.OccurrenceKMTh ?? 0,
                TimeBasedMaintenanceDue      = x.OccurrenceDuration ?? 0,
                TimeBasedAlertThreshold      = x.OccurrenceDurationTh ?? 0,
                OccurenceFixedDateThreshold  = (int)x.OccurrenceFixedDateTh,
                OccurenceFixedDate           = x.OccurrenceFixedDate,
                IsFixedDateChecked           = x.OccurrenceType == 0 ? true : false,
                IsRecurringChecked           = x.OccurrenceType == 1 ? true : false,
                One_Off         = x.One_Off,
                TimeBasedPeriod = x.OccurrencePeriod_cbo,
            }).FirstOrDefault();

            if (maintenanceResult == null)
            {
                maintenanceResult = new MaintenanceTypeDto();
            }
            maintenanceResult.CategoryList = categoryRepo.getAllCategories();
            return(maintenanceResult);
        }
        public MaintenanceTypeDto GetMaintenanceTypeDetailsById(int maintenanceTypeId)
        {
            var maintenanceTypeDetail = new MaintenanceTypeDto();

            maintenanceTypeDetail = dbCon.GFI_AMM_VehicleMaintTypes.
                                    Where(x => x.MaintTypeId == maintenanceTypeId).Select(x => new MaintenanceTypeDto
            {
                KMBasedAlertThreshold        = x.OccurrenceKMTh ?? 0,
                KMBasedMaintenanceDue        = x.OccurrenceKM ?? 0,
                EngineHrsBasedMaintenanceDue = x.OccurrenceEngineHrs ?? 0,
                EngineHrsBasedAlertThreshold = x.OccurrenceEngineHrsTh ?? 0,
                OccurrenceDuration           = x.OccurrenceDuration ?? 0,
                OccurenceFixedDateThreshold  = x.OccurrenceDurationTh ?? 0,
                MaintenanceTypeId            = x.MaintTypeId
            })
                                    .FirstOrDefault();

            return(maintenanceTypeDetail);
        }