public IActionResult Get(int page = 1, int size = 25, string order = "{}", string keyword = null, string filter = "{}") { try { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; var Data = facade.Read(page, size, order, keyword, filter); var viewModel = mapper.Map <List <GarmentInternNoteViewModel> >(Data.Item1); HashSet <long> garmentInvoiceIds = new HashSet <long>(viewModel.SelectMany(vm => vm.items.Select(i => i.garmentInvoice.Id))); List <GarmentInvoice> garmentInvoices = invoiceFacade.ReadForInternNote(garmentInvoiceIds.ToList()); HashSet <long> deliveryOrderIds = new HashSet <long>(viewModel.SelectMany(vm => vm.items.SelectMany(i => i.details.Select(d => d.deliveryOrder.Id)))); List <GarmentDeliveryOrder> garmentDeliveryOrders = deliveryOrderFacade.ReadForInternNote(deliveryOrderIds.ToList()); foreach (var d in viewModel) { foreach (var item in d.items) { GarmentInvoice garmentInvoice = garmentInvoices.SingleOrDefault(gi => gi.Id == item.garmentInvoice.Id); if (garmentInvoice != null) { GarmentInvoiceViewModel invoiceViewModel = mapper.Map <GarmentInvoiceViewModel>(garmentInvoice); item.garmentInvoice.items = invoiceViewModel.items; } foreach (var detail in item.details) { var deliveryOrder = garmentDeliveryOrders.SingleOrDefault(gdo => gdo.Id == detail.deliveryOrder.Id); if (deliveryOrder != null) { var deliveryOrderViewModel = mapper.Map <GarmentDeliveryOrderViewModel>(deliveryOrder); detail.deliveryOrder.items = deliveryOrderViewModel.items; } } } } List <object> listData = new List <object>(); listData.AddRange( viewModel.AsQueryable().Select(s => new { s.Id, s.inNo, s.inDate, supplier = new { s.supplier.Name }, items = s.items.Select(i => new { //i.garmentInvoice, garmentInvoice = new { i.garmentInvoice.invoiceNo, items = i.garmentInvoice.items == null ? null : i.garmentInvoice.items.Select(gii => new { details = gii.details == null ? null : gii.details.Select(gid => new { gid.dODetailId }) }) }, details = i.details.Select(d => new { //d.deliveryOrder deliveryOrder = new { items = d.deliveryOrder.items == null ? null : d.deliveryOrder.items.Select(doi => new { fulfillments = doi.fulfillments == null ? null : doi.fulfillments.Select(dof => new { dof.Id, dof.receiptQuantity }) }) } }).ToList(), }).ToList(), s.CreatedBy, s.LastModifiedUtc }).ToList() ); var info = new Dictionary <string, object> { { "count", listData.Count }, { "total", Data.Item2 }, { "order", Data.Item3 }, { "page", page }, { "size", size } }; Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE) .Ok(listData, info); 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)); } }
public IActionResult Get(int page = 1, int size = 25, string order = "{}", string keyword = null, string filter = "{}") { try { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; var Data = facade.Read(page, size, order, keyword, filter); var viewModel = mapper.Map <List <GarmentInternNoteViewModel> >(Data.Item1); foreach (var d in viewModel) { foreach (var item in d.items) { GarmentInvoice garmentInvoice = invoiceFacade.ReadById((int)item.garmentInvoice.Id); if (garmentInvoice != null) { GarmentInvoiceViewModel invoiceViewModel = mapper.Map <GarmentInvoiceViewModel>(garmentInvoice); item.garmentInvoice.items = invoiceViewModel.items; } foreach (var detail in item.details) { var deliveryOrder = deliveryOrderFacade.ReadById((int)detail.deliveryOrder.Id); if (deliveryOrder != null) { var deliveryOrderViewModel = mapper.Map <GarmentDeliveryOrderViewModel>(deliveryOrder); detail.deliveryOrder.items = deliveryOrderViewModel.items; } } } } List <object> listData = new List <object>(); listData.AddRange( viewModel.AsQueryable().Select(s => new { s.Id, s.inNo, s.inDate, supplier = new { s.supplier.Name }, items = s.items.Select(i => new { i.garmentInvoice, details = i.details.Select(d => new { d.deliveryOrder }).ToList(), }).ToList(), s.CreatedBy, s.LastModifiedUtc }).ToList() ); var info = new Dictionary <string, object> { { "count", listData.Count }, { "total", Data.Item2 }, { "order", Data.Item3 }, { "page", page }, { "size", size } }; Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE) .Ok(listData, info); 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)); } }