private static IShippingAdapter GetShippingAdapter(ShippingAssignment assignment) { return((assignment.Shipper.ToUpperInvariant()) switch { "POSTNL" => new ShippingPostNlAdapter(), "DHL" => new ShippingDhlAdapter(), "BELGIOPOSTO" => new ShippingBelgioPostoAdapter(), _ => null });
int IShippingAdapter.GetDuration(ShippingAssignment assignment) { if (assignment.Order.Weight < 10) { return(4); } else { return(8); } }
public static ShippingAssignment ToShippingAssignment(this CustomerOrder order) { ICountryAdapter countryAdapter = new CountryAdapter(); var shipping = new ShippingAssignment() { Order = order }; shipping.Shipper = countryAdapter.GetShippingPartner(order); return(shipping); }
public async Task <ActionResult> Assignment(ShippingAssignmentViewModel model) { model.Containers = await this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <Container>().ToListAsync(); ShippingOrder shippingOrder = await this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <ShippingOrder>().FirstOrDefaultAsync(x => x.TrackingId == model.OrderTrackingId.ToString()); model.Items = shippingOrder.Items.ToList(); if (!ModelState.IsValid) { return(View(model)); } try { ShippingAssignment shippingAssignment = await this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <ShippingAssignment>().FirstOrDefaultAsync(x => x.ShippingOrderId == model.ShippingOrderId); if (shippingAssignment == null) { shippingAssignment = new ShippingAssignment(); this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <ShippingAssignment>().Add(new ShippingAssignment { ContainerId = model.ContainerId, ShippingOrderId = model.ShippingOrderId, }); if (shippingOrder != null) { shippingOrder.ActualTonnage = model.ActualWeight; } } else { shippingAssignment.ContainerId = model.ContainerId; shippingAssignment.ShippingOrder.ActualTonnage = model.ActualWeight; } shippingAssignment.AssignorId = this.User.Identity.GetUserId(); shippingAssignment.AssignedDateTime = DateTime.Now; await this.HttpContext.GetOwinContext().Get <CMSDbContext>().SaveChangesAsync(); model.Message = "Shipping assignment has been saved."; } catch (Exception ex) { model.Message = "Error occured. Failed to save shipping assignment."; } return(View(model)); }
public static ShippingNote ToShippingConfirmation(this ShippingAssignment shipping) { if (shipping == null) { throw new ArgumentNullException(nameof(shipping)); } IShippingAdapter shippinAdapter = new ShippingAdapter(); return(new ShippingNote() { Order = shipping.Order, Shipper = shipping.Shipper, Duration = shippinAdapter.GetDuration(shipping), ShippingCost = shippinAdapter.GetQuote(shipping) }); }
public void ShippingAssignmentToConfirmation_Success() { // ARRANGE var line = new CsvOrderLine() { CustomerId = 1, Weight = 1.1, Country = "Netherlands" }; var order = new CustomerOrder() { CustomerId = 1, Weight = 1.1, Country = "Netherlands" }; order.OrderLines.Add(line); var assignment = new ShippingAssignment() { Order = order, Shipper = "PostNL" }; // ACT var sc = assignment.ToShippingConfirmation(); // ASSESS Assert.Equal(1, sc.Order.CustomerId); }
public async Task <ActionResult> Assignment(string shippingTrackingNo) { ShippingOrder shippingOrder = await this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <ShippingOrder>().FirstOrDefaultAsync(x => x.TrackingId == shippingTrackingNo); if (shippingOrder == null) { return(new HttpStatusCodeResult(400)); } ShippingAssignment shippingAssignment = await this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <ShippingAssignment>().FirstOrDefaultAsync(x => x.ShippingOrderId == shippingOrder.Id); IList <Container> containers = await this.HttpContext.GetOwinContext().Get <CMSDbContext>().Set <Container>().ToListAsync(); if (shippingAssignment == null) { return(View(new ShippingAssignmentViewModel { OrderTrackingId = shippingOrder.TrackingId, ShippingOrderId = shippingOrder.Id, CustomerName = shippingOrder.ShipmentOwner.UserName, Containers = containers, Items = shippingOrder.Items.ToList() })); } return(View(new ShippingAssignmentViewModel { OrderTrackingId = shippingAssignment.ShippingOrder.TrackingId, ShippingOrderId = shippingAssignment.ShippingOrderId, ContainerId = shippingAssignment.ContainerId, ActualWeight = shippingAssignment.ShippingOrder.ActualTonnage, Id = shippingAssignment.Id, CustomerName = shippingAssignment.ShippingOrder.ShipmentOwner.UserName, Containers = containers, Items = shippingAssignment.ShippingOrder.Items.ToList() })); }
int IShippingAdapter.GetDuration(ShippingAssignment assignment) { var adapter = GetShippingAdapter(assignment); return(adapter.GetDuration(assignment)); }
double IShippingAdapter.GetQuote(ShippingAssignment assignment) { var adapter = GetShippingAdapter(assignment); return(adapter.GetQuote(assignment)); }
int IShippingAdapter.GetDuration(ShippingAssignment assignment) { return(2); }
double IShippingAdapter.GetQuote(ShippingAssignment assignment) { return(1.95 + 1 * assignment.Order.Weight); }
double IShippingAdapter.GetQuote(ShippingAssignment assignment) { return(6.95); }