public void CalculateMassPOF()
        {
            List <PipeMaster> pipeMasterList = (from p in _unitOfWork.PipeMaster.FindAll() select p).ToList <PipeMaster>();

            foreach (PipeMaster pipe in pipeMasterList)
            {
                POFIC pof = new POFIC
                {
                    ID               = 0,
                    PipeMasterID     = pipe.ID,
                    EquipmentNo      = pipe.EquipmentNo,
                    InjectionPoints  = "N",
                    TheoriticalCR    = 1M,
                    EffectiveCR      = 1M,
                    EffectiveAge     = DateTime.Now.Year - pipe.YearInService,
                    MeasuredLCR      = 1M,
                    MeasuredSCR      = 1M,
                    UseMeasuredLCR   = "N",
                    UseMeasuredSCR   = "N",
                    VeryHigh         = 0,
                    High             = 0,
                    Medium           = 0,
                    Low              = 0,
                    Found            = 0,
                    DamageFactor     = 1,
                    POF              = 1,
                    LastMeasuredYear = null
                };

                _unitOfWork.POFIC.Create(pof);
                _unitOfWork.SaveChanges();
            }
        }
        public void Create(POFICDTO POFICDTO)
        {
            POFIC obj = _mapper.Map <POFIC>(POFICDTO);

            obj.CreatedDate = DateTime.Now;
            _unitOfWork.POFIC.Create(obj);
            _unitOfWork.SaveChanges();
        }
        public void Update(POFICDTO POFICDTO)
        {
            int   ID       = POFICDTO.ID;
            POFIC pipeline = _unitOfWork.POFIC.FindById(ID);

            if (pipeline != null)
            {
                int yearInService = (from p in _unitOfWork.PipeMaster.FindAll().Where(p => p.EquipmentNo == pipeline.EquipmentNo)
                                     select p.YearInService
                                     ).FirstOrDefault();


                int?lastMeasuredYear = (from p in _unitOfWork.PipeMaster.FindAll().Where(p => p.EquipmentNo == pipeline.EquipmentNo)
                                        select p.LastMeasuredYear_LMY
                                        ).FirstOrDefault();

                if (!pipeline.AnalysisYear.HasValue)
                {
                    pipeline.AnalysisYear = DateTime.Now.Year;
                }
                pipeline.InjectionPoints  = POFICDTO.InjectionPoints;
                pipeline.TheoriticalCR    = POFICDTO.TheoriticalCR;
                pipeline.EffectiveCR      = POFICDTO.EffectiveCR;
                pipeline.EffectiveAge     = POFICDTO.EffectiveAge;
                pipeline.MeasuredLCR      = POFICDTO.MeasuredLCR;
                pipeline.MeasuredSCR      = POFICDTO.MeasuredSCR;
                pipeline.UseMeasuredLCR   = POFICDTO.UseMeasuredLCR;
                pipeline.UseMeasuredSCR   = POFICDTO.UseMeasuredSCR;
                pipeline.VeryHigh         = POFICDTO.VeryHigh;
                pipeline.High             = POFICDTO.High;
                pipeline.Medium           = POFICDTO.Medium;
                pipeline.Low              = POFICDTO.Low;
                pipeline.Found            = POFICDTO.Found;
                pipeline.DamageFactor     = POFICDTO.DamageFactor;
                pipeline.POF              = POFICDTO.POF;
                pipeline.LastMeasuredYear = POFICDTO.LastMeasuredYear;

                pipeline.ModifiedBy   = POFICDTO.ModifiedBy;
                pipeline.ModifiedDate = DateTime.Now;
                // EffectiveCR
                if (pipeline.UseMeasuredLCR == "Y")
                {
                    pipeline.EffectiveCR = pipeline.MeasuredLCR;
                }
                else if (pipeline.UseMeasuredSCR == "Y")
                {
                    pipeline.EffectiveCR = pipeline.MeasuredSCR;
                }
                else if (pipeline.InjectionPoints == "Y")
                {
                    pipeline.EffectiveCR = 2 * pipeline.TheoriticalCR;
                }
                else if (pipeline.InjectionPoints == "N")
                {
                    pipeline.EffectiveCR = pipeline.TheoriticalCR;
                }

                // EffectiveAge
                if (lastMeasuredYear.HasValue)
                {
                    pipeline.EffectiveAge = pipeline.AnalysisYear - lastMeasuredYear;
                }
                else
                {
                    pipeline.EffectiveAge = pipeline.AnalysisYear - yearInService;
                }
            }
            _unitOfWork.POFIC.Update(pipeline);
            _unitOfWork.SaveChanges();

            Update(pipeline.EquipmentNo, pipeline.AnalysisYear.Value);
        }