Exemple #1
0
        public CorrosionStudyResponseDTO Update(CorrosionStudyRequestDTO CorrosionStudyRequestDTO)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    CorrosionStudy tempObj = _unitOfWork.CorrosionStudy.FindById(CorrosionStudyRequestDTO.CorrosionStudyDTO.ID);

                    if (tempObj != null)
                    {
                        tempObj.ModifiedBy   = "SYSADMIN";
                        tempObj.ModifiedDate = DateTime.Now;
                        _unitOfWork.CorrosionStudy.Update(tempObj);

                        foreach (COFMasterDTO cofMasterDTO in CorrosionStudyRequestDTO.COFMasterDTOList)
                        {
                            COFMaster cofMaster = new COFMaster();
                            if (cofMasterDTO.ID > 0)
                            {
                                cofMaster = _unitOfWork.COFMaster.FindById(cofMasterDTO.ID);
                                cofMaster.DetectionRating     = cofMasterDTO.DetectionRating;
                                cofMaster.ToxicFluidFraction  = cofMasterDTO.ToxicFluidFraction;
                                cofMaster.ToxicReferenceFluid = cofMasterDTO.ToxicReferenceFluid;
                                cofMaster.RefresentativeFluid = cofMasterDTO.RefresentativeFluid;
                                cofMaster.MitigationFactor    = cofMasterDTO.MitigationFactor;
                                cofMaster.IsolationRating     = cofMasterDTO.IsolationRating;
                                cofMaster.ModifiedBy          = "SYSADMIN";
                                cofMaster.ModifiedDate        = DateTime.Now;
                                _unitOfWork.COFMaster.Update(cofMaster);
                            }
                            else
                            {
                                cofMaster                  = _mapper.Map <COFMaster>(cofMasterDTO);
                                cofMaster.ID               = 0;
                                cofMaster.LoopNo           = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo;
                                cofMaster.CorrosionStudyID = tempObj.ID;
                                cofMaster.CreatedDate      = DateTime.Now;
                                cofMaster.CreatedBy        = "SYSADMIN";
                                _unitOfWork.COFMaster.Create(cofMaster);
                            }
                        }

                        foreach (IOWDTO iowDTO in CorrosionStudyRequestDTO.IOWDTOList)
                        {
                            IOW iow = new IOW();
                            if (iowDTO.ID > 0)
                            {
                                iow.Unit          = iowDTO.Unit;
                                iow.IOWNo         = iowDTO.IOWNo;
                                iow.Min           = iowDTO.Min;
                                iow.Max           = iowDTO.Max;
                                iow.Parameter     = iowDTO.Parameter;
                                iow.TagNo         = iowDTO.TagNo;
                                iow.RelatedUnitNo = iowDTO.RelatedUnitNo;
                                iow.ModifiedBy    = "SYSADMIN";
                                iow.ModifiedDate  = DateTime.Now;
                                _unitOfWork.IOW.Update(iow);
                            }
                            else
                            {
                                iow                  = _mapper.Map <IOW>(iowDTO);
                                iow.ID               = 0;
                                iow.LoopNo           = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo;
                                iow.CorrosionStudyID = tempObj.ID;
                                iow.CreatedDate      = DateTime.Now;
                                iow.CreatedBy        = "SYSADMIN";
                                _unitOfWork.IOW.Create(iow);
                            }
                        }

                        foreach (PipeClusterPOFDTO pipeClusterPOFDTO in CorrosionStudyRequestDTO.PipeClusterPOFDTOList)
                        {
                            foreach (DMGuideDTO dmGuide in pipeClusterPOFDTO.DMGuideList)
                            {
                                PipeClusterPOF pipeClusterPOF = new PipeClusterPOF();
                                if (dmGuide.DMGuideID.HasValue && dmGuide.DMGuideID.Value > 0)
                                {
                                    pipeClusterPOF                 = _unitOfWork.PipeClusterPOF.FindById(dmGuide.DMGuideID.Value);
                                    pipeClusterPOF.MinPressure     = pipeClusterPOFDTO.MinPressure;
                                    pipeClusterPOF.MaxPressure     = pipeClusterPOFDTO.MaxPressure;
                                    pipeClusterPOF.MinTemperature  = pipeClusterPOFDTO.MinTemperature;
                                    pipeClusterPOF.MaxTemperature  = pipeClusterPOFDTO.MaxTemperature;
                                    pipeClusterPOF.MaterialCode    = pipeClusterPOFDTO.MaterialCode;
                                    pipeClusterPOF.Fluid           = pipeClusterPOFDTO.Fluid;
                                    pipeClusterPOF.DMCode          = dmGuide.DMCode;
                                    pipeClusterPOF.DMDescription   = dmGuide.DMDescription;
                                    pipeClusterPOF.DMRate          = dmGuide.DMRate;
                                    pipeClusterPOF.DMSeverity      = dmGuide.DMSeverity;
                                    pipeClusterPOF.DMSuceptability = dmGuide.DMSuceptability;
                                    pipeClusterPOF.DMType          = dmGuide.DMType;
                                    pipeClusterPOF.DMGuideDocument = dmGuide.DMGuideDocument;
                                    pipeClusterPOF.ModifiedDate    = DateTime.Now;
                                    pipeClusterPOF.ModifiedBy      = "SYSADMIN";
                                    _unitOfWork.PipeClusterPOF.Update(pipeClusterPOF);
                                }
                                else
                                {
                                    pipeClusterPOF.ID = 0;
                                    pipeClusterPOF.CorrosionStudyID = tempObj.ID;
                                    pipeClusterPOF.CreatedDate      = DateTime.Now;
                                    pipeClusterPOF.CreatedBy        = "SYSADMIN";
                                    pipeClusterPOF.ClusterNo        = pipeClusterPOFDTO.ClusterNo;
                                    pipeClusterPOF.MinPressure      = pipeClusterPOFDTO.MinPressure;
                                    pipeClusterPOF.MaxPressure      = pipeClusterPOFDTO.MaxPressure;
                                    pipeClusterPOF.MinTemperature   = pipeClusterPOFDTO.MinTemperature;
                                    pipeClusterPOF.MaxTemperature   = pipeClusterPOFDTO.MaxTemperature;
                                    pipeClusterPOF.MaterialCode     = pipeClusterPOFDTO.MaterialCode;
                                    pipeClusterPOF.Fluid            = pipeClusterPOFDTO.Fluid;
                                    pipeClusterPOF.DMCode           = dmGuide.DMCode;
                                    pipeClusterPOF.DMDescription    = dmGuide.DMDescription;
                                    pipeClusterPOF.DMRate           = dmGuide.DMRate;
                                    pipeClusterPOF.DMSeverity       = dmGuide.DMSeverity;
                                    pipeClusterPOF.DMSuceptability  = dmGuide.DMSuceptability;
                                    pipeClusterPOF.DMType           = dmGuide.DMType;
                                    pipeClusterPOF.DMGuideDocument  = dmGuide.DMGuideDocument;
                                    _unitOfWork.PipeClusterPOF.Create(pipeClusterPOF);
                                }
                            }
                        }

                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new CorrosionStudyResponseDTO
                        {
                            LoopNo = tempObj.LoopNo,
                            Status = true,
                            StatusMessage = "Successfully created",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new CorrosionStudyResponseDTO
                        {
                            LoopNo = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo,
                            Status = false,
                            StatusMessage = "Error - Duplicate Loop No - " + CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo,
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new CorrosionStudyResponseDTO()
                    {
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }
Exemple #2
0
        public CorrosionStudyResponseDTO Create(CorrosionStudyRequestDTO CorrosionStudyRequestDTO)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    CorrosionStudy tempObj = (from s in _unitOfWork.CorrosionStudy.GenerateEntityAsIQueryable()
                                              where s.LoopNo == CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo
                                              select s).FirstOrDefault();

                    if (tempObj == null)
                    {
                        CorrosionStudy CorrosionStudy = _mapper.Map <CorrosionStudy>(CorrosionStudyRequestDTO.CorrosionStudyDTO);
                        CorrosionStudy.ID          = 0;
                        CorrosionStudy.CreatedDate = DateTime.Now;
                        CorrosionStudy.CreatedBy   = "SYSADMIN";
                        CorrosionStudy cr = _unitOfWork.CorrosionStudy.CreateWithReturnEntity(CorrosionStudy);

                        foreach (COFMasterDTO cofMasterDTO in CorrosionStudyRequestDTO.COFMasterDTOList)
                        {
                            COFMaster cofMaster = _mapper.Map <COFMaster>(cofMasterDTO);
                            cofMaster.ID = 0;
                            cofMaster.CorrosionStudyID = cr.ID;
                            cofMaster.LoopNo           = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo;
                            cofMaster.CreatedDate      = DateTime.Now;
                            cofMaster.CreatedBy        = "SYSADMIN";
                            _unitOfWork.COFMaster.Create(cofMaster);
                        }

                        foreach (IOWDTO iowDTO in CorrosionStudyRequestDTO.IOWDTOList)
                        {
                            IOW iow = _mapper.Map <IOW>(iowDTO);
                            iow.ID = 0;
                            iow.CorrosionStudyID = cr.ID;
                            iow.LoopNo           = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo;
                            iow.CreatedDate      = DateTime.Now;
                            iow.CreatedBy        = "SYSADMIN";
                            _unitOfWork.IOW.Create(iow);
                        }

                        foreach (PipeClusterPOFDTO pipeClusterPOFDTO in CorrosionStudyRequestDTO.PipeClusterPOFDTOList)
                        {
                            foreach (DMGuideDTO dmGuide in pipeClusterPOFDTO.DMGuideList)
                            {
                                // PipeClusterPOF pipeClusterPOF = _mapper.Map<PipeClusterPOF>(pipeClusterPOFDTO);
                                PipeClusterPOF pipeClusterPOF = new PipeClusterPOF();
                                pipeClusterPOF.ID = 0;
                                pipeClusterPOF.CorrosionStudyID = cr.ID;
                                pipeClusterPOF.CreatedDate      = DateTime.Now;
                                pipeClusterPOF.CreatedBy        = "SYSADMIN";
                                pipeClusterPOF.ClusterNo        = pipeClusterPOFDTO.ClusterNo;
                                pipeClusterPOF.MinPressure      = pipeClusterPOFDTO.MinPressure;
                                pipeClusterPOF.MaxPressure      = pipeClusterPOFDTO.MaxPressure;
                                pipeClusterPOF.MinTemperature   = pipeClusterPOFDTO.MinTemperature;
                                pipeClusterPOF.MaxTemperature   = pipeClusterPOFDTO.MaxTemperature;
                                pipeClusterPOF.MaterialCode     = pipeClusterPOFDTO.MaterialCode;
                                pipeClusterPOF.Fluid            = pipeClusterPOFDTO.Fluid;
                                pipeClusterPOF.DMCode           = dmGuide.DMCode;
                                pipeClusterPOF.DMDescription    = dmGuide.DMDescription;
                                pipeClusterPOF.DMRate           = dmGuide.DMRate;
                                pipeClusterPOF.DMSeverity       = dmGuide.DMSeverity;
                                pipeClusterPOF.DMSuceptability  = dmGuide.DMSuceptability;
                                pipeClusterPOF.DMType           = dmGuide.DMType;
                                pipeClusterPOF.DMGuideDocument  = dmGuide.DMGuideDocument;
                                _unitOfWork.PipeClusterPOF.Create(pipeClusterPOF);
                            }
                        }

                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new CorrosionStudyResponseDTO
                        {
                            LoopNo = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo,
                            Status = true,
                            StatusMessage = "Successfully created",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new CorrosionStudyResponseDTO
                        {
                            LoopNo = CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo,
                            Status = false,
                            StatusMessage = "Error - Duplicate Loop No - " + CorrosionStudyRequestDTO.CorrosionStudyDTO.LoopNo,
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new CorrosionStudyResponseDTO()
                    {
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }