예제 #1
0
        public PipeReportResponseDTO Update(PipeReportRequestDTO PipeReportRequestDTO)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    PipeReport tempObj = (from s in _unitOfWork.PipeReport.GenerateEntityAsIQueryable()
                                          where s.ReportNo == PipeReportRequestDTO.PipeReport.ReportNo
                                          select s).FirstOrDefault();

                    if (tempObj != null)
                    {
                        //  PipeReport pipeReport = _mapper.Map<PipeReport>(PipeReportRequestDTO.PipeReport);
                        tempObj.ModifiedBy   = "SYSADMIN";
                        tempObj.ModifiedDate = DateTime.Now;
                        _unitOfWork.PipeReport.Update(tempObj);

                        foreach (InspectionConfidenceDTO confidence in PipeReportRequestDTO.InspectionConfidenceList)
                        {
                            InspectionConfidence inspectionConfidence = _mapper.Map <InspectionConfidence>(confidence);
                            if (inspectionConfidence.ID > 0)
                            {
                                inspectionConfidence.ModifiedBy   = "SYSADMIN";
                                inspectionConfidence.ModifiedDate = DateTime.Now;
                                _unitOfWork.InspectionConfidence.Update(inspectionConfidence);
                            }
                        }

                        foreach (InspectionObservationDTO inspectionObservationDTO in PipeReportRequestDTO.InspectionObservationList)
                        {
                            InspectionObservation inspectionObservation = _mapper.Map <InspectionObservation>(inspectionObservationDTO);

                            if (inspectionObservation.ID > 0)
                            {
                                inspectionObservation.ModifiedBy   = "SYSADMIN";
                                inspectionObservation.ModifiedDate = DateTime.Now;
                                _unitOfWork.InspectionObservation.Update(inspectionObservation);
                            }
                            else
                            {
                                inspectionObservation.ID           = 0;
                                inspectionObservation.PipeReportID = tempObj.ID;
                                inspectionObservation.CreatedDate  = DateTime.Now;
                                inspectionObservation.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionObservation.Create(inspectionObservation);
                            }
                        }



                        foreach (InspectionRecommendationDTO inspectionRecommendationDTO in PipeReportRequestDTO.InspectionRecommendationList)
                        {
                            InspectionRecommendation inspectionRecommendation = _mapper.Map <InspectionRecommendation>(inspectionRecommendationDTO);
                            if (inspectionRecommendation.ID > 0)
                            {
                                inspectionRecommendation.ModifiedBy   = "SYSADMIN";
                                inspectionRecommendation.ModifiedDate = DateTime.Now;
                                _unitOfWork.InspectionRecommendation.Update(inspectionRecommendation);
                            }
                            else
                            {
                                inspectionRecommendation.ID           = 0;
                                inspectionRecommendation.PipeReportID = tempObj.ID;
                                inspectionRecommendation.CreatedDate  = DateTime.Now;
                                inspectionRecommendation.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionRecommendation.Create(inspectionRecommendation);
                            }
                        }

                        //foreach (InspectionDistributionDTO inspectionDistributionDTO in PipeReportRequestDTO.InspectionDistributionList)
                        //{
                        //    InspectionDistribution inspectionDistribution = _mapper.Map<InspectionDistribution>(inspectionDistributionDTO);
                        //    if (inspectionDistribution.ID > 0)
                        //    {
                        //        inspectionDistribution.ModifiedDate = DateTime.Now;
                        //        _unitOfWork.InspectionDistribution.Create(inspectionDistribution);
                        //    }
                        //    else
                        //    {
                        //        inspectionDistribution.PipeReportID = pipeReport.ID;
                        //        inspectionDistribution.CreatedDate = DateTime.Now;
                        //        _unitOfWork.InspectionDistribution.Create(inspectionDistribution);
                        //    }
                        //}

                        //foreach (InspectionProgramDTO inspectionProgramDTO in PipeReportRequestDTO.InspectionProgramList)
                        //{
                        //    InspectionProgram inspectionProgram = _mapper.Map<InspectionProgram>(inspectionProgramDTO);
                        //    if (inspectionProgram.ID > 0)
                        //    {
                        //        inspectionProgram.ModifiedBy = "SYSADMIN";
                        //        inspectionProgram.ModifiedDate = DateTime.Now;
                        //        _unitOfWork.InspectionProgram.Create(inspectionProgram);
                        //    }
                        //    else
                        //    {
                        //        inspectionProgram.PipeReportID = pipeReport.ID;
                        //        inspectionProgram.CreatedDate = DateTime.Now;
                        //        _unitOfWork.InspectionProgram.Create(inspectionProgram);
                        //    }
                        //}

                        foreach (TMLDTO tmlDTO in PipeReportRequestDTO.TMLList)
                        {
                            TML tml = _mapper.Map <TML>(tmlDTO);
                            if (tml.ID > 0)
                            {
                                tml.ModifiedBy   = "SYSADMIN";
                                tml.ModifiedDate = DateTime.Now;
                                _unitOfWork.TML.Update(tml);
                            }
                            else
                            {
                                tml.ID           = 0;
                                tml.PipeReportID = tempObj.ID;
                                tml.CreatedDate  = DateTime.Now;
                                tml.CreatedBy    = "SYSADMIN";
                                _unitOfWork.TML.Create(tml);
                            }
                        }

                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new PipeReportResponseDTO
                        {
                            Status = true,
                            StatusMessage = "Successfully created",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new PipeReportResponseDTO
                        {
                            Status = false,
                            StatusMessage = "Error - Duplicate Report - " + tempObj.ReportNo,
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new PipeReportResponseDTO()
                    {
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }
예제 #2
0
        public PipeReportResponseDTO Create(PipeReportRequestDTO PipeReportRequestDTO)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    PipeReport tempObj = (from s in _unitOfWork.PipeReport.GenerateEntityAsIQueryable()
                                          where s.ReportNo == PipeReportRequestDTO.PipeReport.ReportNo
                                          select s).FirstOrDefault();

                    if (tempObj == null)
                    {
                        PipeReport pipeReport = _mapper.Map <PipeReport>(PipeReportRequestDTO.PipeReport);
                        pipeReport.ID          = 0;
                        pipeReport.CreatedDate = DateTime.Now;
                        pipeReport.ReportNo    = GenerateReportNo(DateTime.Now.Year.ToString());
                        pipeReport.CreatedBy   = "SYSADMIN";
                        PipeReport report = _unitOfWork.PipeReport.CreateWithReturnEntity(pipeReport);
                        if (PipeReportRequestDTO.InspectionConfidenceList != null && PipeReportRequestDTO.InspectionConfidenceList.Count > 0)
                        {
                            foreach (InspectionConfidenceDTO confidence in PipeReportRequestDTO.InspectionConfidenceList)
                            {
                                InspectionConfidence inspectionConfidence = _mapper.Map <InspectionConfidence>(confidence);
                                inspectionConfidence.ID           = 0;
                                inspectionConfidence.PipeReportID = report.ID;
                                inspectionConfidence.PipeMasterID = report.PipeMasterID;
                                inspectionConfidence.ReportNo     = report.ReportNo;
                                inspectionConfidence.EquipmentNo  = report.EquipmentNo;
                                inspectionConfidence.CreatedDate  = DateTime.Now;
                                inspectionConfidence.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionConfidence.Create(inspectionConfidence);
                            }
                        }
                        if (PipeReportRequestDTO.InspectionObservationList != null && PipeReportRequestDTO.InspectionObservationList.Count > 0)
                        {
                            foreach (InspectionObservationDTO inspectionObservationDTO in PipeReportRequestDTO.InspectionObservationList)
                            {
                                InspectionObservation inspectionObservation = _mapper.Map <InspectionObservation>(inspectionObservationDTO);
                                inspectionObservation.ID           = 0;
                                inspectionObservation.PipeReportID = report.ID;
                                inspectionObservation.PipeMasterID = report.PipeMasterID;
                                inspectionObservation.ReportNo     = report.ReportNo;
                                inspectionObservation.EquipmentNo  = report.EquipmentNo;
                                inspectionObservation.CreatedDate  = DateTime.Now;
                                inspectionObservation.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionObservation.Create(inspectionObservation);
                            }
                        }

                        if (PipeReportRequestDTO.InspectionRecommendationList != null && PipeReportRequestDTO.InspectionRecommendationList.Count > 0)
                        {
                            foreach (InspectionRecommendationDTO inspectionRecommendationDTO in PipeReportRequestDTO.InspectionRecommendationList)
                            {
                                InspectionRecommendation inspectionRecommendation = _mapper.Map <InspectionRecommendation>(inspectionRecommendationDTO);
                                inspectionRecommendation.ID           = 0;
                                inspectionRecommendation.PipeReportID = report.ID;
                                inspectionRecommendation.PipeMasterID = report.PipeMasterID;
                                inspectionRecommendation.ReportNo     = report.ReportNo;
                                inspectionRecommendation.EquipmentNo  = report.EquipmentNo;
                                inspectionRecommendation.CreatedDate  = DateTime.Now;
                                inspectionRecommendation.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionRecommendation.Create(inspectionRecommendation);
                            }
                        }
                        if (PipeReportRequestDTO.InspectionDistributionList != null && PipeReportRequestDTO.InspectionDistributionList.Count > 0)
                        {
                            foreach (InspectionDistributionDTO inspectionDistributionDTO in PipeReportRequestDTO.InspectionDistributionList)
                            {
                                InspectionDistribution inspectionDistribution = _mapper.Map <InspectionDistribution>(inspectionDistributionDTO);
                                inspectionDistribution.ID           = 0;
                                inspectionDistribution.PipeReportID = report.ID;
                                inspectionDistribution.CreatedDate  = DateTime.Now;
                                inspectionDistribution.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionDistribution.Create(inspectionDistribution);
                            }
                        }
                        if (PipeReportRequestDTO.InspectionProgramList != null && PipeReportRequestDTO.InspectionProgramList.Count > 0)
                        {
                            foreach (InspectionProgramDTO inspectionProgramDTO in PipeReportRequestDTO.InspectionProgramList)
                            {
                                InspectionProgram inspectionProgram = _mapper.Map <InspectionProgram>(inspectionProgramDTO);
                                inspectionProgram.ID           = 0;
                                inspectionProgram.PipeReportID = report.ID;
                                inspectionProgram.PipeMasterID = report.PipeMasterID;
                                inspectionProgram.ReportNo     = report.ReportNo;
                                inspectionProgram.EquipmentNo  = report.EquipmentNo;
                                inspectionProgram.CreatedDate  = DateTime.Now;
                                inspectionProgram.CreatedBy    = "SYSADMIN";
                                _unitOfWork.InspectionProgram.Create(inspectionProgram);
                            }
                        }
                        if (PipeReportRequestDTO.TMLList != null && PipeReportRequestDTO.TMLList.Count > 0)
                        {
                            foreach (TMLDTO tmlDTO in PipeReportRequestDTO.TMLList)
                            {
                                TML tml = _mapper.Map <TML>(tmlDTO);
                                tml.ID           = 0;
                                tml.PipeReportID = report.ID;
                                tml.PipeMasterID = report.PipeMasterID;
                                tml.ReportNo     = report.ReportNo;
                                tml.EquipmentNo  = report.EquipmentNo;
                                tml.CreatedDate  = DateTime.Now;
                                tml.CreatedBy    = "SYSADMIN";
                                _unitOfWork.TML.Create(tml);
                            }
                        }

                        _unitOfWork.SaveChanges();
                        transaction.Commit();
                        return(new PipeReportResponseDTO
                        {
                            ReportNo = PipeReportRequestDTO.PipeReport.ReportNo,
                            Status = true,
                            StatusMessage = "Successfully created",
                            StatusCode = 200
                        });
                    }
                    else
                    {
                        return(new PipeReportResponseDTO
                        {
                            ReportNo = PipeReportRequestDTO.PipeReport.ReportNo,
                            Status = false,
                            StatusMessage = "Error - Duplicate Report - " + PipeReportRequestDTO.PipeReport.ReportNo,
                            StatusCode = 200
                        });
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(new PipeReportResponseDTO()
                    {
                        Status = false,
                        StatusMessage = ex.Message,
                        StatusCode = 200
                    });
                }
            }
        }