public IActionResult Get(int id)
        {
            try
            {
                var model = facade.ReadById(id);
                var viewModel = mapper.Map<GarmentInternNoteViewModel>(model);
                if (viewModel == null)
                {
                    throw new Exception("Invalid Id");
                }
                else
                {
                    viewModel.isEdit = model.Position <= PurchasingGarmentExpeditionPosition.Purchasing;
                    foreach (GarmentInternNoteItemViewModel item in viewModel.items)
                    {
                        GarmentInvoice garmentInvoice = invoiceFacade.ReadById((int)item.garmentInvoice.Id);
                        if (garmentInvoice != null)
                        {
                            GarmentInvoiceViewModel invoiceViewModel = mapper.Map<GarmentInvoiceViewModel>(garmentInvoice);

                            item.garmentInvoice.items = invoiceViewModel.items;

                        }
                        foreach (GarmentInternNoteDetailViewModel detail in item.details)
                        {
                            GarmentDeliveryOrder deliveryOrder = deliveryOrderFacade.ReadById((int)detail.deliveryOrder.Id);
                            if (deliveryOrder != null)
                            {
                                GarmentDeliveryOrderViewModel deliveryOrderViewModel = mapper.Map<GarmentDeliveryOrderViewModel>(deliveryOrder);
                                detail.deliveryOrder.items = deliveryOrderViewModel.items;
                                if (detail.invoiceDetailId != 0)
                                {
                                    var invoiceItem = garmentInvoice.Items.First(s => s.Details.Any(d => d.Id == detail.invoiceDetailId));

                                    var invoiceDetail = invoiceItem.Details.First(i => i.Id == detail.invoiceDetailId);

                                    if (invoiceDetail != null)
                                    {
                                        detail.dODetailId = invoiceDetail.DODetailId;
                                    }
                                }

                            }
                        }
                    }
                }

                Dictionary<string, object> Result =
                    new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                    .Ok(viewModel);
                return Ok(Result);
            }
            catch (Exception e)
            {
                Dictionary<string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result);
            }
        }
コード例 #2
0
        public IActionResult Get(int id)
        {
            try
            {
                var model     = facade.ReadById(id);
                var viewModel = mapper.Map <GarmentInternNoteViewModel>(model);
                if (viewModel == null)
                {
                    throw new Exception("Invalid Id");
                }
                else
                {
                    foreach (GarmentInternNoteItemViewModel item in viewModel.items)
                    {
                        foreach (GarmentInternNoteDetailViewModel detail in item.details)
                        {
                            GarmentDeliveryOrder deliveryOrder = deliveryOrderFacade.ReadById((int)detail.deliveryOrder.Id);
                            if (deliveryOrder != null)
                            {
                                GarmentDeliveryOrderViewModel deliveryOrderViewModel = mapper.Map <GarmentDeliveryOrderViewModel>(deliveryOrder);
                                detail.deliveryOrder.items = deliveryOrderViewModel.items;
                            }
                        }
                    }
                }

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE)
                    .Ok(viewModel);
                return(Ok(Result));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }