Exemplo n.º 1
0
        private bool UpdateComponentDetails()
        {
            var components = _context.GENERAL_EQ_UNIT.Where(m => m.module_ucsub_auto == Params.Id);

            foreach (var component in components)
            {
                OldComponentsCMU.Add(new OldCMU
                {
                    Id           = (int)component.equnit_auto,
                    SmuAtInstall = (int)(component.eq_smu_at_install ?? 0),
                    CMU          = (int)(component.cmu ?? 0)
                });
                component.cmu = Params.Components.Where(m => m.Id == component.equnit_auto).Select(m => m.HoursAtInstall).FirstOrDefault();
                if (!ReplacedComponentIds.Any(k => component.equnit_auto == k))
                {
                    component.smu_at_install    = Params.SmuAtInstall;
                    component.eq_smu_at_install = Params.SmuAtInstall;
                    component.date_installed    = Params.InstallationDate.ToLocalTime().Date;
                }
                _context.Entry(component).State = EntityState.Modified;
            }
            try
            {
                _context.SaveChanges();
                ActionLog += "Components detials updated successfully!" + Environment.NewLine;
                return(true);
            }
            catch (Exception ex)
            {
                ActionLog += "Updating components details failed! " + ex.ToDetailedString() + Environment.NewLine;
                Message    = "Action failed when updating components details!";
                return(false);
            }
        }
Exemplo n.º 2
0
        private void AdjustLives()
        {
            var _ids = ActionHistoryModifiedIds.Select(m => m.HistoryId);

            if (OldSystemCMU != null && DALSystem != null)
            {
                var _difference = (int)(((DALSystem.CMU ?? 0) - OldSystemCMU.CMU) + (OldSystemCMU.SmuAtInstall - (DALSystem.SMU_at_install ?? 0)));
                var lives       = _context.UCSYSTEM_LIFE.Where(m => m.SystemId == OldSystemCMU.Id && !_ids.Any(k => m.ActionId == k) && m.ACTION_TAKEN_HISTORY.recordStatus == (int)RecordStatus.TemporarilyDisabled);
                foreach (var life in lives)
                {
                    life.ActualLife           += _difference;
                    _context.Entry(life).State = EntityState.Modified;
                }
            }
            var components = _context.GENERAL_EQ_UNIT.Where(m => m.module_ucsub_auto == Params.Id).ToList();
            var _compIds   = components.Select(m => m.equnit_auto);

            foreach (var component in components)
            {
                var _item = OldComponentsCMU.Where(m => m.Id == component.equnit_auto).FirstOrDefault();
                if (_item == null)
                {
                    continue;
                }
                int _difference = 0;
                if (ReplacedComponentIds.Any(k => component.equnit_auto == k))
                {
                    _difference = (int)(((component.cmu ?? 0) - _item.CMU));
                }
                else
                {
                    _difference = (int)(((component.cmu ?? 0) - _item.CMU) + (_item.SmuAtInstall - (component.eq_smu_at_install ?? 0)));
                }
                var lives = _context.COMPONENT_LIFE.Where(m => m.ComponentId == _item.Id && !_ids.Any(k => m.ActionId == k) && m.ACTION_TAKEN_HISTORY.recordStatus == (int)RecordStatus.TemporarilyDisabled);
                foreach (var life in lives)
                {
                    life.ActualLife           += _difference;
                    _context.Entry(life).State = EntityState.Modified;
                }
            }

            var inspections = _context.TRACK_INSPECTION_DETAIL.Where(m => _compIds.Any(k => m.track_unit_auto == k));

            foreach (var inspection in inspections)
            {
                int _difference = 0;
                var _item       = OldComponentsCMU.Where(m => m.Id == inspection.track_unit_auto).FirstOrDefault();
                if (_item == null)
                {
                    continue;
                }
                if (ReplacedComponentIds.Any(k => inspection.track_unit_auto == k))
                {
                    _difference = (int)(((inspection.GENERAL_EQ_UNIT.cmu ?? 0) - _item.CMU));
                }
                else
                {
                    _difference = (int)(((inspection.GENERAL_EQ_UNIT.cmu ?? 0) - _item.CMU) + (_item.SmuAtInstall - (inspection.GENERAL_EQ_UNIT.eq_smu_at_install ?? 0)));
                }
                inspection.hours_on_surface += _difference;

                _context.Entry(inspection).State = EntityState.Modified;
            }
            try
            {
                _context.SaveChanges();
                ActionLog += "lives adjusted successfully!" + Environment.NewLine;
            }
            catch (Exception ex)
            {
                ActionLog += "Updating lives failed! " + ex.ToDetailedString() + Environment.NewLine;
            }
        }