private void UpdateHeatChartDetailListAddUpdate(HeatChartHeader heatChartHeader, HeatChartHeaderVM heatChartHeaderVM)
        {
            if (heatChartHeaderVM.HeatChartDetails == null || !heatChartHeaderVM.HeatChartDetails.Any())
            {
                return;
            }

            foreach (var heatChartDetail in heatChartHeaderVM.HeatChartDetails)
            {
                var existingHeatChartDetail = heatChartHeader.HeatChartDetails.Where(x => x.ID == heatChartDetail.ID && x.ID > 0).SingleOrDefault();

                if (existingHeatChartDetail != null)
                {
                    existingHeatChartDetail.UpdateHeatChartDetails(heatChartDetail);

                    UpdateHeatChartDetailMaterialRegisterRelationshipAddUpdate(existingHeatChartDetail, heatChartDetail);

                    _heatChartDetailsRepository.Update(existingHeatChartDetail);
                }
                else
                {
                    var updatedHeatChartDetail = AutoMapper.Map <HeatChartDetailsVM, HeatChartDetails>(heatChartDetail);

                    heatChartHeader.HeatChartDetails.Add(updatedHeatChartDetail);
                }
            }
        }
        public static HeatChartHeaderVM MapHeatChartHeader(HeatChartHeader heatChartHeader)
        {
            var heatChartHeaderVM = AutoMapper.Map <HeatChartHeader, HeatChartHeaderVM>(heatChartHeader);

            heatChartHeaderVM.HeatChartDetails = MapHeatChartDetailsList(heatChartHeader.HeatChartDetails.ToList());

            heatChartHeaderVM.CustomerSelected             = AutoMapper.Map <Customer, CustomerVM>(heatChartHeader.Customers);
            heatChartHeaderVM.ThirdPartyInspectionSelected = AutoMapper.Map <ThirdPartyInspection, ThirdPartyInspectionVM>(heatChartHeader.ThirdPartyInspections);

            heatChartHeaderVM.IsShowDownLoad = heatChartHeaderVM.HeatChartDetails != null &&
                                               heatChartHeaderVM.HeatChartDetails.Any(x => x.MaterialRegisterSubSeriesSelected != null &&
                                                                                      x.MaterialRegisterSubSeriesSelected.MaterialRegisterFileDetails.Any()) ? true : false;

            return(heatChartHeaderVM);
        }
        public HttpResponseMessage Update(HttpRequestMessage request, HeatChartHeaderVM heatChartHeaderVM)
        {
            _requiredRepositories = new List <Type>()
            {
                typeof(HeatChartHeader),
                typeof(HeatChartDetails),
                typeof(HeatChartMaterialHeaderRelationship),
                typeof(Error)
            };

            return(CreateHttpResponse(request, _requiredRepositories, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    HeatChartHeader _heatChartHeader = _heatChartHeadersRepository.GetSingleByHeatChartHeaderID(heatChartHeaderVM.ID);

                    if (_heatChartHeader == null)
                    {
                        ModelState.AddModelError("Invalid Heat Chart", "Heat Chart Number does not exists");
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                          ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                    }
                    else
                    {
                        _heatChartHeader.UpdateHeatChartHeader(heatChartHeaderVM);

                        UpdateHeatChartDetailListRemoveHeatChartDetail(_heatChartHeader, heatChartHeaderVM);

                        UpdateHeatChartDetailListAddUpdate(_heatChartHeader, heatChartHeaderVM);

                        _heatChartHeadersRepository.Update(_heatChartHeader);

                        _heatChartHeadersRepository.Commit();
                    }

                    response = request.CreateResponse <HeatChartHeaderVM>(HttpStatusCode.Created, heatChartHeaderVM);
                }
                return response;
            }));
        }
        private void UpdateHeatChartDetailListRemoveHeatChartDetail(HeatChartHeader heatChartHeader, HeatChartHeaderVM heatChartHeaderVM)
        {
            if (heatChartHeader.HeatChartDetails == null || !heatChartHeader.HeatChartDetails.Any())
            {
                return;
            }

            var deletableHeatChartDetails = heatChartHeader.HeatChartDetails.
                                            Where(sub => !heatChartHeaderVM.HeatChartDetails.Any(x => x.ID.Equals(sub.ID))).ToList();

            foreach (var heatChartDetail in deletableHeatChartDetails)
            {
                if (heatChartDetail.HeathChartMaterialHeaderRelationships != null)
                {
                    _heatChartMaterialHeaderRelationshipRepository.Delete(heatChartDetail.HeathChartMaterialHeaderRelationships);
                }

                _heatChartDetailsRepository.Delete(heatChartDetail);
            }
        }
        public HttpResponseMessage Create(HttpRequestMessage request, HeatChartHeaderVM heatChartHeaderVM)
        {
            _requiredRepositories = new List <Type>()
            {
                typeof(HeatChartHeader), typeof(Error)
            };

            return(CreateHttpResponse(request, _requiredRepositories, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    if (_heatChartHeadersRepository.HeatChartHeaderExists(heatChartHeaderVM.HeatChartNumber))
                    {
                        ModelState.AddModelError("Invalid Heat Chart", "Heat Chart Number exists");
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                          ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                    }
                    else
                    {
                        HeatChartHeader newHeatChartHeader = new HeatChartHeader();
                        newHeatChartHeader = AutoMapper.Map <HeatChartHeaderVM, HeatChartHeader>(heatChartHeaderVM);

                        _heatChartHeadersRepository.Insert(newHeatChartHeader);
                        _heatChartHeadersRepository.Commit();

                        // Update view model
                        heatChartHeaderVM = AutoMapper.Map <HeatChartHeader, HeatChartHeaderVM>(newHeatChartHeader);
                        response = request.CreateResponse <HeatChartHeaderVM>(HttpStatusCode.Created, heatChartHeaderVM);
                    }
                }
                return response;
            }));
        }
예제 #6
0
        public static void UpdateHeatChartHeader(this HeatChartHeader heatChartHeader, HeatChartHeaderVM heatChartHeaderVM)
        {
            heatChartHeader.CreatedBy  = heatChartHeaderVM.CreatedBy;
            heatChartHeader.CreatedOn  = heatChartHeaderVM.CreatedOn;
            heatChartHeader.ModifiedBy = heatChartHeaderVM.ModifiedBy;
            heatChartHeader.ModifiedOn = heatChartHeaderVM.ModifiedOn;

            heatChartHeader.CustomerID          = heatChartHeaderVM.CustomerSelected.ID;
            heatChartHeader.CustomerPOEquipment = heatChartHeaderVM.CustomerPOEquipment;
            heatChartHeader.CustomerPONumber    = heatChartHeaderVM.CustomerPONumber;
            heatChartHeader.CustomerPODate      = heatChartHeaderVM.CustomerPODate;

            heatChartHeader.DrawingNumber   = heatChartHeaderVM.DrawingNumber;
            heatChartHeader.DrawingRevision = heatChartHeaderVM.DrawingRevision;

            heatChartHeader.JobNumber     = heatChartHeaderVM.JobNumber;
            heatChartHeader.TagNumber     = heatChartHeaderVM.TagNumber;
            heatChartHeader.OtherInfo     = heatChartHeaderVM.OtherInfo;
            heatChartHeader.Plant         = heatChartHeaderVM.Plant;
            heatChartHeader.NoOfEquipment = heatChartHeaderVM.NoOfEquipment;

            heatChartHeader.ThirdPartyInspectionID = heatChartHeaderVM.ThirdPartyInspectionSelected.ID;
        }