Пример #1
0
        public override async Task <IActionResult> GetById([FromRoute] int id)
        {
            try
            {
                FinishingPrintingCostCalculationModel model = await Facade.ReadByIdAsync(id);

                if (model == null)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, Common.NOT_FOUND_STATUS_CODE, Common.NOT_FOUND_MESSAGE)
                        .Fail();
                    return(NotFound(Result));
                }
                else
                {
                    FinishingPrintingCostCalculationViewModel viewModel = Mapper.Map <FinishingPrintingCostCalculationViewModel>(model);
                    var preSalesContractModel = await fpPreSalesContractFacade.ReadByIdAsync((int)viewModel.PreSalesContract.Id);

                    viewModel.Instruction.Steps = viewModel.Machines.Select(x => x.Step).ToList();
                    viewModel.PreSalesContract  = Mapper.Map <FinishingPrintingPreSalesContractViewModel>(preSalesContractModel);
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, Common.OK_STATUS_CODE, Common.OK_MESSAGE)
                        .Ok <FinishingPrintingCostCalculationViewModel>(viewModel);
                    return(Ok(Result));
                }
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, Common.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(Common.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        //[HttpGet("filterBySalesContract/{salesContractNo}")]
        //public virtual async Task<IActionResult> ReadBySalesContractNo([FromRoute] string salesContractNo)
        //{
        //    if (!ModelState.IsValid)
        //    {
        //        return BadRequest(ModelState);
        //    }

        //    try
        //    {
        //        List<ProductionOrderModel> model = Facade.ReadBySalesContractNo(salesContractNo);
        //        List<ShinProductionOrderViewModel> viewModel = Mapper.Map<List<ShinProductionOrderViewModel>>(model);
        //        Dictionary<string, object> Result =
        //            new ResultFormatter(ApiVersion, Common.OK_STATUS_CODE, Common.OK_MESSAGE)
        //            .Ok(Mapper, viewModel, 1, viewModel.Count, viewModel.Count, viewModel.Count, new Dictionary<string, string>(), new List<string>());
        //        return Ok(Result);
        //    }
        //    catch (Exception e)
        //    {
        //        Dictionary<string, object> Result =
        //            new ResultFormatter(ApiVersion, Common.INTERNAL_ERROR_STATUS_CODE, e.Message)
        //            .Fail();
        //        return StatusCode(Common.INTERNAL_ERROR_STATUS_CODE, Result);
        //    }
        //}

        public override async Task <IActionResult> GetById([FromRoute] int id)
        {
            try
            {
                ProductionOrderModel model = await Facade.ReadByIdAsync(id);

                if (model == null)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, Common.NOT_FOUND_STATUS_CODE, Common.NOT_FOUND_MESSAGE)
                        .Fail();
                    return(NotFound(Result));
                }
                else
                {
                    ShinProductionOrderViewModel viewModel = Mapper.Map <ShinProductionOrderViewModel>(model);
                    var fpSCModel = await finishingPrintingSalesContractFacade.ReadParent(viewModel.FinishingPrintingSalesContract.Id);

                    if (fpSCModel != null)
                    {
                        var fpSCVM = Mapper.Map <ShinFinishingPrintingSalesContractViewModel>(fpSCModel);
                        //var fpCCModel = await finishingPrintingCostCalculationService.ReadParent(fpSCVM.CostCalculation.Id);

                        var preSalesContractModel = await fpPreSalesContractFacade.ReadByIdAsync((int)fpSCVM.PreSalesContract.Id);

                        if (preSalesContractModel != null)
                        {
                            fpSCVM.PreSalesContract = Mapper.Map <FinishingPrintingPreSalesContractViewModel>(preSalesContractModel);

                            viewModel.FinishingPrintingSalesContract = fpSCVM;
                        }
                        //if (fpCCModel != null)
                        //{
                        //    var fpCCVM = Mapper.Map<FinishingPrintingCostCalculationViewModel>(fpCCModel);
                        //    var preSalesContractModel = await fpPreSalesContractFacade.ReadByIdAsync((int)fpCCVM.PreSalesContract.Id);
                        //    fpCCVM.PreSalesContract = Mapper.Map<FinishingPrintingPreSalesContractViewModel>(preSalesContractModel);
                        //    fpSCVM.CostCalculation = fpCCVM;

                        //    viewModel.FinishingPrintingSalesContract = fpSCVM;
                        //}
                    }
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, Common.OK_STATUS_CODE, Common.OK_MESSAGE)
                        .Ok <ShinProductionOrderViewModel>(viewModel);
                    return(Ok(Result));
                }
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, Common.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(Common.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
Пример #3
0
        public override IActionResult Get(int page = 1, int size = 25, string order = "{}", [Bind(Prefix = "Select[]")] List <string> select = null, string keyword = null, string filter = "{}")
        {
            try
            {
                ValidateUser();

                ReadResponse <FinishingPrintingSalesContractModel> read = Facade.Read(page, size, order, select, keyword, filter);

                //Tuple<List<TModel>, int, Dictionary<string, string>, List<string>> Data = Facade.Read(page, size, order, select, keyword, filter);
                List <ShinFinishingPrintingSalesContractViewModel> DataVM = Mapper.Map <List <ShinFinishingPrintingSalesContractViewModel> >(read.Data);

                foreach (var data in DataVM)
                {
                    var preSalesContractModel = fpPreSalesContractFacade.ReadByIdAsync((int)data.PreSalesContract.Id).Result;
                    if (preSalesContractModel != null)
                    {
                        data.PreSalesContract = Mapper.Map <FinishingPrintingPreSalesContractViewModel>(preSalesContractModel);
                    }
                    //var fpCCModel = finishingPrintingCostCalculationService.ReadParent(data.CostCalculation.Id).Result;
                    //if(fpCCModel != null)
                    //{

                    //    var fpCCVM = Mapper.Map<FinishingPrintingCostCalculationViewModel>(fpCCModel);
                    //    var preSalesContractModel = fpPreSalesContractFacade.ReadByIdAsync((int)fpCCVM.PreSalesContract.Id).Result;
                    //    fpCCVM.PreSalesContract = Mapper.Map<FinishingPrintingPreSalesContractViewModel>(preSalesContractModel);
                    //    data.CostCalculation = fpCCVM;
                    //}
                }

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, Common.OK_STATUS_CODE, Common.OK_MESSAGE)
                    .Ok <ShinFinishingPrintingSalesContractViewModel>(Mapper, DataVM, page, size, read.Count, DataVM.Count, read.Order, read.Selected);
                return(Ok(Result));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, Common.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(Common.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }