Exemple #1
0
 private void GetMaterialRegisterHeaderVM(MaterialRegisterHeaderVM materialRegisterHeaderVM)
 {
     materialRegisterHeaderVM.Suppliers             = SupplierList;
     materialRegisterHeaderVM.ThirdPartyInspections = ThirdPartyInspectionList;
     materialRegisterHeaderVM.RawMaterialForms      = RawMaterialFormList;
     materialRegisterHeaderVM.Specifications        = SpecificationList;
     materialRegisterHeaderVM.Dimensions            = DimensionList;
 }
Exemple #2
0
        public HttpResponseMessage Update(HttpRequestMessage request, MaterialRegisterHeaderVM materialRegisterHeaderVM)
        {
            MemoryCache _cache = MemoryCache.Default;

            _cache.Remove("MaterialRegisterHeaders");
            _cache.Remove("MaterialRegisterSubSeries");

            _requiredRepositories = new List <Type>()
            {
                typeof(MaterialRegisterHeader),
                typeof(MillDetail),
                typeof(LabReport),
                typeof(Error),
                typeof(MaterialRegisterSubSeries),
                typeof(MaterialRegisterSubseriesTestRelationship),
                typeof(MaterialRegisterFileDetail),
            };

            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
                {
                    MaterialRegisterHeader _materialRegisterHeader = _materialRegisterHeadersRepository.GetSingleByMaterialRegisterHeaderID(materialRegisterHeaderVM.ID);

                    if (_materialRegisterHeader == null)
                    {
                        ModelState.AddModelError("Invalid material register", "CT Number does not exists");
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                          ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                    }
                    else
                    {
                        _materialRegisterHeader.UpdateMaterialRegisterHeader(materialRegisterHeaderVM);

                        UpdateSubSeriesListRemoveSubSeries(_materialRegisterHeader, materialRegisterHeaderVM);

                        UpdateSubSeriesListAddUpdate(_materialRegisterHeader, materialRegisterHeaderVM);

                        _materialRegisterHeadersRepository.Update(_materialRegisterHeader);

                        _materialRegisterHeadersRepository.Commit();
                    }

                    response = request.CreateResponse <MaterialRegisterHeaderVM>(HttpStatusCode.Created, materialRegisterHeaderVM);
                }
                return response;
            }));
        }
Exemple #3
0
        public HttpResponseMessage Create(HttpRequestMessage request, MaterialRegisterHeaderVM materialRegisterHeaderVM)
        {
            MemoryCache _cache = MemoryCache.Default;

            _cache.Remove("MaterialRegisterHeaders");
            _cache.Remove("MaterialRegisterSubSeries");

            _requiredRepositories = new List <Type>()
            {
                typeof(MaterialRegisterHeader), 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 (_materialRegisterHeadersRepository.MaterialRegisterHeaderExists(materialRegisterHeaderVM.CTNumber))
                    {
                        ModelState.AddModelError("Invalid material register", "CT Number exists");
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                          ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                    }
                    else
                    {
                        MaterialRegisterHeader newMaterialRegisterHeader = new MaterialRegisterHeader();
                        newMaterialRegisterHeader = AutoMapper.Map <MaterialRegisterHeaderVM, MaterialRegisterHeader>(materialRegisterHeaderVM);

                        _materialRegisterHeadersRepository.Insert(newMaterialRegisterHeader);
                        _materialRegisterHeadersRepository.Commit();

                        // Update view model
                        materialRegisterHeaderVM = AutoMapper.Map <MaterialRegisterHeader, MaterialRegisterHeaderVM>(newMaterialRegisterHeader);
                        response = request.CreateResponse <MaterialRegisterHeaderVM>(HttpStatusCode.Created, materialRegisterHeaderVM);
                    }
                }
                return response;
            }));
        }
Exemple #4
0
        public HttpResponseMessage Create(HttpRequestMessage request)
        {
            currentRequestMessage = request;

            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                MaterialRegisterHeaderVM materialRegisterHeaderVM = new MaterialRegisterHeaderVM();

                GetMaterialRegisterHeaderVM(materialRegisterHeaderVM);

                if (ConfigurationReader.IsCheckTestNumberAutoCalculate)
                {
                    materialRegisterHeaderVM.CTNumber = AutoCalculateCTNumber();
                    materialRegisterHeaderVM.IsCheckTestNumberAutoCalculate = true;
                }

                response = request.CreateResponse(HttpStatusCode.OK, materialRegisterHeaderVM);

                return response;
            }));
        }
Exemple #5
0
 private HeatChartMaterialHeaderRelationshipVM GetHeatChartMaterialHeaderRelationship(MaterialRegisterHeaderVM materialRegisterHeaderVM, MaterialRegisterSubSeriesVM materialRegisterSubSeriesVM)
 {
     return(new HeatChartMaterialHeaderRelationshipVM()
     {
         MaterialRegisterHeaderID = materialRegisterHeaderVM.ID,
         MaterialRegisterSubSeriesID = materialRegisterSubSeriesVM.ID
     });
 }
Exemple #6
0
        public static void UpdateMaterialRegisterHeader(this MaterialRegisterHeader materialRegisterHeader, MaterialRegisterHeaderVM materialRegisterHeaderVM)
        {
            var materialRegisterHeaderNew = AutoMapper.Map <MaterialRegisterHeaderVM, MaterialRegisterHeader>(materialRegisterHeaderVM);

            materialRegisterHeader.SupplierID             = materialRegisterHeaderNew.SupplierID;
            materialRegisterHeader.ThirdPartyInspectionID = materialRegisterHeaderNew.ThirdPartyInspectionID;
            materialRegisterHeader.SpecificationsID       = materialRegisterHeaderNew.SpecificationsID;
            materialRegisterHeader.Dimension         = materialRegisterHeaderNew.Dimension;
            materialRegisterHeader.RawMaterialFormID = materialRegisterHeaderNew.RawMaterialFormID;

            //materialRegisterHeader.MaterialRegisterSubSeriess = materialRegisterHeaderNew.MaterialRegisterSubSeriess;

            materialRegisterHeader.ModifiedBy = materialRegisterHeaderNew.ModifiedBy;
            materialRegisterHeader.ModifiedOn = materialRegisterHeaderNew.ModifiedOn;

            materialRegisterHeader.SupplierPONumber = materialRegisterHeaderNew.SupplierPONumber;
            materialRegisterHeader.SupplierPODate   = materialRegisterHeaderNew.SupplierPODate;

            materialRegisterHeader.StatusID = materialRegisterHeaderNew.StatusID;

            materialRegisterHeader.PartiallyAcceptedRemarks = materialRegisterHeaderNew.PartiallyAcceptedRemarks;
            materialRegisterHeader.OtherInfo = materialRegisterHeaderVM.OtherInfo;
            materialRegisterHeader.Quantity  = materialRegisterHeaderVM.Quantity;

            materialRegisterHeader.IsDeleted = materialRegisterHeaderNew.IsDeleted;
        }
Exemple #7
0
        private void UpdateSubSeriesListAddUpdate(MaterialRegisterHeader materialRegisterHeader, MaterialRegisterHeaderVM materialRegisterHeaderVM)
        {
            if (materialRegisterHeaderVM.MaterialRegisterSubSeriess == null || !materialRegisterHeaderVM.MaterialRegisterSubSeriess.Any())
            {
                return;
            }

            foreach (var materialSub in materialRegisterHeaderVM.MaterialRegisterSubSeriess)
            {
                var existingSubSeries = materialRegisterHeader.MaterialRegisterSubSeriess.Where(x => x.ID == materialSub.ID).SingleOrDefault();

                if (existingSubSeries != null)
                {
                    existingSubSeries.UpdateMaterialRegisterSubSeries(materialSub);

                    UpdateSubSeriesTestRemoveTestRelationship(existingSubSeries, materialSub);
                    UpdateSubSeriesTestAddUpdate(existingSubSeries, materialSub);

                    UpdateMillDetailsAddUpdate(existingSubSeries, materialSub);
                    UpdateLabReportsAddUpdate(existingSubSeries, materialSub);

                    UpdateSubSeriesRemoveFileDetails(existingSubSeries, materialSub);
                    UpdateSubSeriesFileDetailsAddUpdate(existingSubSeries, materialSub);

                    _materialRegisterSubseriessRepository.Update(existingSubSeries);
                }
                else
                {
                    var updatedMaterialSubSeries = AutoMapper.Map <MaterialRegisterSubSeriesVM, MaterialRegisterSubSeries>(materialSub);
                    materialRegisterHeader.MaterialRegisterSubSeriess.Add(updatedMaterialSubSeries);
                }
            }
        }
Exemple #8
0
        private void UpdateSubSeriesListRemoveSubSeries(MaterialRegisterHeader materialRegisterHeader, MaterialRegisterHeaderVM materialRegisterHeaderVM)
        {
            if (materialRegisterHeader.MaterialRegisterSubSeriess == null || !materialRegisterHeader.MaterialRegisterSubSeriess.Any())
            {
                return;
            }

            var deletableMaterialRegisterHeaders = materialRegisterHeader.MaterialRegisterSubSeriess.Where(sub => !materialRegisterHeaderVM.MaterialRegisterSubSeriess.Any(x => x.ID == sub.ID)).ToList();

            foreach (var materialSub in deletableMaterialRegisterHeaders)
            {
                if (materialSub.MillDetail != null)
                {
                    _millDetailsRepository.Delete(materialSub.MillDetail);
                }

                if (materialSub.LabReport != null)
                {
                    _labReportssRepository.Delete(materialSub.LabReport);
                }
                _materialRegisterSubseriessRepository.Delete(materialSub);
            }
        }