public async Task <ActionResult> Index() { SetDropDownList(); ShipmentBookingDtos model = new ShipmentBookingDtos(); model.OrderDetails = new List <ShipmentResultDtos>(); model.OrderDetails = await _bookingService.ConvertToResultAsync(await _bookingService.ListShipmentFilterAsync(null, "Hong Kong", "Aberdeen", null, null, null, null, null, null, null)); return(View(model)); }
public async Task <List <ShipmentBookingDtos> > CreateOrUpdateBookingAsync(ShipmentBookingDtos booking) { List <Booking> result = new List <Booking>(); List <ShipmentBookingDtos> bookings = ConvertToBookingList(booking); PagedListResult <Booking> bookingDb = await _bookingDataProvider.ListAsync(); foreach (var item in bookings) { Booking entity = new Booking(); if (item.Status == OrderStatus.BookingMade) { foreach (var detail in bookingDb.Items) { if (detail.ItemNumber == item.ItemNumber) { entity = detail; break; } } item.Id = entity.Id; var temp = entity.RowVersion; entity = Mapper.Map(item, entity); entity.RowVersion = temp; _bookingRepository.Update(entity); result.Add(entity); } else { item.Status = OrderStatus.BookingMade; entity = Mapper.Map <Booking>(item); result.Add(entity); _bookingRepository.Insert(entity); } } //await UnitOfWork.SaveChangesAsync(); var rs = Mapper.Map <List <ShipmentBookingDtos> >(result); return(rs); }
public async Task <ActionResult> Filter(int?page, string origin = null, string originPort = null, string mode = null, string warehouse = null, string status = null, string vendor = null, string poNumber = null, string itemNumber = null, string shipmentId = null) { SetDropDownList(); ShipmentBookingDtos model = new ShipmentBookingDtos(); model.OrderDetails = new List <ShipmentResultDtos>(); model.OrderDetails = await _bookingService.ConvertToResultAsync(await _bookingService.ListShipmentFilterAsync(page, origin, originPort, mode, warehouse, status, vendor, poNumber, itemNumber, shipmentId)); if (model.OrderDetails.Count > 0) { model.OrderDetails = await _bookingService.UpdatePackType(model.OrderDetails); } return(PartialView("_Result", model)); }
public List <ShipmentBookingDtos> ConvertToBookingList(ShipmentBookingDtos input) { List <ShipmentBookingDtos> result = new List <ShipmentBookingDtos>(); Guid shipmentId = Guid.NewGuid(); foreach (var item in input.OrderDetails) { if (item.Selected) { { ShipmentBookingDtos output = new ShipmentBookingDtos(); output.OrderId = item.OrderId; output.ItemNumber = item.ItemNumber; output.Quantity = item.Quantity; output.Cartons = item.Cartons; output.Cube = item.Cube; output.PackType = item.PackType; output.Status = item.Status; output.PONumber = item.PONumber; output.PortOfLoading = input.PortOfLoading; output.PortOfDelivery = input.PortOfDelivery; output.Carrier = input.Carrier; output.Mode = input.Mode; output.ETD = input.ETD; output.ETA = input.ETA; output.ShipmentID = shipmentId; result.Add(output); } } } return(result); }
public async Task <ActionResult> Booking(ShipmentBookingDtos model, string method = null) { SetDropDownList(); switch (method) { case "Book": if (ModelState.IsValid) { if (model.OrderDetails != null) { if (SelectAtLeastOne(model.OrderDetails)) { await _bookingService.CreateOrUpdateBookingAsync(model); ModelState.Clear(); model = await _bookingService.ChangeItemStatus(model); ViewBag.ShowModal = "Updated"; } else { ViewBag.ShowModal = "NoItem"; } } } break; default: ModelState.Clear(); int number = int.Parse(new string(method.Where(char.IsDigit).ToArray())); ViewBag.Page = number; break; } return(PartialView("_Result", model)); }
public async Task <List <OrderDetailDTO> > ListShipmentFilterAsync(int?page, string origin = null, string originPort = null, string mode = null, string warehouse = null, string status = null, string vendor = null, string poNumber = null, string itemNumber = null, string shipmentId = null) { if (page == null) { page = 1; } ShipmentBookingDtos shipmentFilter = new ShipmentBookingDtos(); Expression <Func <OrderDetail, bool> > All = x => x.Id > 0; if (origin != null) { Expression <Func <OrderDetail, bool> > filter = x => x.Order.Origin == origin; All = All.And(filter); } if (vendor != null) { Expression <Func <OrderDetail, bool> > filter = x => x.Order.Vendor.Contains(vendor); All = All.And(filter); } if (poNumber != null) { Expression <Func <OrderDetail, bool> > filter = x => x.Order.PONumber.Contains(poNumber); All = All.And(filter); } if (warehouse != null) { Expression <Func <OrderDetail, bool> > filter = x => x.Warehouse.Contains(warehouse); All = All.And(filter); } if (itemNumber != null) { Expression <Func <OrderDetail, bool> > filter = x => x.ItemNumber.Contains(itemNumber); All = All.And(filter); } Expression <Func <OrderDetail, bool> > All1 = x => x.Status == OrderStatus.AwaitingBooking; Expression <Func <OrderDetail, bool> > All2 = x => x.Status == OrderStatus.BookingMade; if (originPort != null) { Expression <Func <OrderDetail, bool> > filter1 = x => x.Order.PortOfLoading == originPort; All1 = All1.And(filter1); Expression <Func <OrderDetail, bool> > filter2 = x => x.Order.Bookings.Where(p => p.PortOfLoading == originPort).Count() > 0; All2 = All2.And(filter2); } if (mode != null) { Expression <Func <OrderDetail, bool> > filter = x => x.Order.Mode == mode; All1 = All1.And(filter); Expression <Func <OrderDetail, bool> > filter2 = x => x.Order.Bookings.Where(p => p.Mode == mode).Count() > 0; All2 = All2.And(filter2); } if (status == OrderStatus.AwaitingBooking.GetDescription <OrderStatus>()) { All = All.And(All1); } else if (status == OrderStatus.BookingMade.GetDescription <OrderStatus>()) { All = All.And(All2); } else { All = All.And(All1.Or(All2)); } PagedListResult <OrderDetail> result = await _orderDetailDataProvider.ListAsync(All, null, true); if (shipmentId != null) { Expression <Func <Booking, bool> > booking = x => x.ShipmentID.ToString().Contains(shipmentId); PagedListResult <Booking> resultBooking = await _bookingDataProvider.ListAsync(booking, null, true); PagedListResult <OrderDetail> finalResult = new PagedListResult <OrderDetail>(); finalResult.Items = new List <OrderDetail>(); foreach (var orderDetail in result.Items) { bool add = false; foreach (var item in resultBooking.Items) { if (item.ItemNumber == orderDetail.ItemNumber) { add = true; break; } } if (add) { finalResult.Items.Add(orderDetail); } } result.Items = finalResult.Items; } return(Mapper.Map <List <OrderDetailDTO> >(result.Items)); }
public async Task <ShipmentBookingDtos> ChangeItemStatus(ShipmentBookingDtos input) { foreach (var item in input.OrderDetails) { if (item.Selected) { { List <Booking> booking = await _bookingRepository.Query(x => x.ItemNumber == item.ItemNumber, false).SelectAsync(); if (booking.Count > 0) { item.ShipmentID = booking[0].ShipmentID; } item.Status = OrderStatus.BookingMade; item.StatusDescription = OrderStatus.BookingMade.GetDescription <OrderStatus>(); List <OrderDetail> orderDetails = await _orderDetailRepository.Query(x => x.ItemNumber == item.ItemNumber, false).SelectAsync(); orderDetails[0].Status = OrderStatus.BookingMade; _orderDetailRepository.Update(orderDetails[0]); //update Order info List <Order> order = await _orderRepository.Query(x => x.Id == item.OrderId, false).SelectAsync(); if (order == null) { throw new AppException("Order not found."); } //if ((order[0].PortOfLoading != input.PortOfLoading) || (order[0].PortOfDelivery != input.PortOfDelivery) || (order[0].Mode != input.Mode)) //{ // order[0].PortOfLoading = input.PortOfLoading; // order[0].PortOfDelivery = input.PortOfDelivery; // order[0].Mode = input.Mode; // _orderRepository.Update(order[0]); //} } } } await UnitOfWork.SaveChangesAsync(); foreach (var item in input.OrderDetails) { if (item.Selected) { { List <Booking> booking = await _bookingRepository.Query(x => x.ItemNumber == item.ItemNumber, false).SelectAsync(); if (booking.Count > 0) { item.ShipmentID = booking[0].ShipmentID; } } } } return(input); }