public IActionResult Initialize() { var boxesModel = new List <Box>(); using (var db = new ShippingContext()) { db.Boxes.RemoveRange(db.Boxes); db.Boxes.Add(new Box { BoxId = 123450, Weight = 3 }); db.Boxes.Add(new Box { BoxId = 123461, Weight = 8 }); db.Boxes.Add(new Box { BoxId = 123472, Weight = 11 }); db.Boxes.Add(new Box { BoxId = 123483, Weight = 3 }); db.Boxes.Add(new Box { BoxId = 123494, Weight = 13 }); db.SaveChanges(); boxesModel = db.Boxes.ToList(); } return(View(boxesModel)); }
public IActionResult CalculatePartDetails() { PartsModel partsModel; using (var db = new ShippingContext()) { db.Parts.RemoveRange(db.Parts); foreach (var box in db.Boxes) { var W = box.Weight; var PC = box.PartCount; var floor = (int)(W / PC); var mod = W % PC; for (var p = 0; p < PC; p++) { var part = new Part { BoxId = box.BoxId, PartWeight = p == 0 ? floor + mod : floor }; part.PartCost = CalculateCost(part.PartWeight); db.Parts.Add(part); } } db.SaveChanges(); partsModel = new PartsModel { Parts = db.Parts.OrderBy(p => p.BoxId).ToList() }; } return(View(partsModel)); }
public IActionResult CalculatePartCounts() { var boxesModel = new List <Box>(); using (var db = new ShippingContext()) { var orderedBoxes = db.Boxes.OrderBy(b => b.Weight); var partCount = 1; foreach (var box in orderedBoxes) { box.PartCount = ++partCount; } db.SaveChanges(); boxesModel = db.Boxes.ToList(); } return(View(boxesModel)); }
public void Handle(PurchaseOrderReceived @event) { // Invoke the shipping domain to check stock for every book using this service's own db // calculate shipping cost based on destination // if all is OK, store the shipping manifest and publish an event var totalCostWithoutShipping = @event.BooksOrdered.Sum(x => x.BookPrice); var shippingCost = totalCostWithoutShipping * 0.2m; var shippingManifest = new ShippingManifest { BookIds = String.Join(", ", @event.BooksOrdered.Select(x => x.Id).ToList()), ShippingCost = shippingCost, ShippingReference = $"SP{@event.Id}" }; _context.ShippingManifests.Add(shippingManifest); _context.SaveChanges(); _bus.Publish(new OrderShipped(Guid.NewGuid(), @event.CorrelationId, shippingManifest.ShippingReference, @event.BooksOrdered.Select(x => x.Id).ToList(), shippingCost, totalCostWithoutShipping + shippingCost)); }
public void Create(Order order) { _context.Orders.Add(order); _context.SaveChanges(); }
public void Create(User user) { _context.Users.Add(user); _context.SaveChanges(); }
public void Commit() { _context.SaveChanges(); }