public MacDeliveryModel LocateMacIds(string macId) { var result = new MacDeliveryModel(); if (!string.IsNullOrEmpty(macId)) { var modifiedMac = macId.Length >= 29 ? macId.Remove(macId.Length - 17, 17) : macId; if (modifiedMac.Length == 12 || modifiedMac.Length == 16) { var delivery = _repo.GetDeliveryByMacId(modifiedMac); if (delivery != null) { result = new MacDeliveryModel { DeliveryNumber = delivery.DeliveryNumber, IsInternal = delivery.IsIrDelivery }; } else { result.Error = "Delivery not found for this Smart Mac."; } } else { result.Error = " Incorrect Mac Id Length, or Mac Id is not a serialized number."; } } return(result); }
public void OrderLookUp_HappyPath() { var lookup = new MacDeliveryModel { DeliveryNumber = 1234, IsInternal = false }; var expectedDelivery = new Delivery { Address = "ADDRESS" }; var expectedChartData = new Dictionary <string, int>(); expectedChartData.Add("REALITEM1", 1); expectedChartData.Add("REALITEM2", 1); var expectedItems = new List <SerialNumberItem> { new SerialNumberItem { DocEntry = 1, RealItemCode = "REALITEM1" }, new SerialNumberItem { MacId = "SERIAL", RealItemCode = "REALITEM2" } }; _identity.Stub(i => i.Name).Return("USERNAME"); _settings.Stub(s => s.GetServerLocation).Return("SERVER"); _repo.Expect(r => r.GetDelivery(Arg <DeliveryOrderQuery> .Matches(a => a.IsInternal.Equals(false) && a.DocNum.Equals(lookup.DeliveryNumber) && a.ServerLocation.Equals("SERVER")))).Return(expectedDelivery); _repo.Expect(r => r.GetDeliveryItems(Arg <DeliveryOrderItemsQuery> .Matches(a => a.DocNum.Equals(lookup.DeliveryNumber) && a.ServerLocation.Equals("SERVER") && a.Username.Equals("USERNAME") && a.IsInternal.Equals(false)))).Return(expectedItems); var actual = new OrderDeliveryService(_repo, _settings, _identity).OrderLookUp(lookup); Assert.AreEqual("ADDRESS", actual.Address); Assert.AreEqual(lookup.DeliveryNumber, actual.DeliveryNumber); Assert.AreEqual(actual.ScannedItems.Count, 1); Assert.AreEqual(actual.NotScannedItems.Count, 1); Assert.AreEqual(actual.ChartData, expectedChartData); }
public OrderDeliveryModel OrderLookUp(MacDeliveryModel lookup) { var delivery = _repo.GetDelivery(new DeliveryOrderQuery { DocNum = lookup.DeliveryNumber, ServerLocation = _settings.GetServerLocation, IsInternal = lookup.IsInternal }); OrderDeliveryModel deliveryModel = null; if (delivery != null) { delivery.IsIrDelivery = lookup.IsInternal; var items = _repo.GetDeliveryItems(new DeliveryOrderItemsQuery { DocNum = lookup.DeliveryNumber, ServerLocation = _settings.GetServerLocation, Username = _identity.Name, IsInternal = delivery.IsIrDelivery }).ToList(); deliveryModel = delivery.Map <Delivery, OrderDeliveryModel>(); deliveryModel.DeliveryNumber = lookup.DeliveryNumber; deliveryModel.IsInternal = lookup.IsInternal; FindActiveKits(items, deliveryModel); items.ForEach(i => { var model = i.Map <SerialNumberItem, DeliveryOrderItemModel>(); if (string.IsNullOrEmpty(i.MacId)) { deliveryModel.NotScannedItems.Add(model); } else { deliveryModel.ScannedItems.Add(model); } }); var dictionary = new Dictionary <string, int>(); var grouped = items.Where(i => i.RealItemCode != null).GroupBy(i => i.RealItemCode).ToList(); grouped.OrderBy(g => g.Count()).ToList().ForEach(g => dictionary.Add(g.Key, g.Count())); deliveryModel.ChartData = dictionary; } return(deliveryModel); }