public void DeleteWarehouse(DeleteWarehouseInput input) { var warehouse = _WarehouseRepository.Get(input.Id); warehouse.IsDeleted = true; _WarehouseRepository.Delete(warehouse); }
public long Add(Warehouse obj) { //var customer = _customerService.GetByDomain(obj.); if (IsDuplicate(obj.WarehouseCode, obj.Id, obj.CustomerId) == false) { return(_warehouseRepository.Add(obj)); } else { Expression <Func <Warehouse, bool> > res = x => x.WarehouseCode == obj.WarehouseCode && x.CustomerId == obj.CustomerId && x.IsActive == false; var model = _warehouseRepository.Get(res); if (model != null) { obj.Id = model.Id; obj.IsActive = true; _warehouseRepository.Detach(model); _warehouseRepository.Update(obj); return(obj.Id); } else { return(0); } } }
protected void SetDefaultInventory(string code, decimal inStockQuantity, string warehouseCode = "default") { _log.Debug("Setting stock for {0} to {1}", code, inStockQuantity); var warehouse = _warehouseRepository.Get(warehouseCode); if (warehouse == null) { throw new ArgumentNullException("warehouse"); } if (inStockQuantity == 0) { throw new ArgumentNullException("inStockQuantity", "InStockQuantity is required"); } var existingInventory = _inventoryService.Get(code, warehouse.Code); InventoryRecord inv; if (existingInventory != null) { inv = new InventoryRecord(existingInventory); } else { inv = new InventoryRecord(); inv.WarehouseCode = warehouse.Code; inv.CatalogEntryCode = code; } inv.PurchaseAvailableQuantity = inStockQuantity; _inventoryService.Save(new[] { inv }); }
public IEnumerable <Location> GetByWarehouseCode(string warehouseCode, bool isActive, long customerId) { Expression <Func <Warehouse, bool> > resWarehouse = x => x.WarehouseCode.ToLower() == warehouseCode && x.IsActive == isActive && x.CustomerId == customerId; var wareHouse = _warehouseRepository.Get(resWarehouse); Expression <Func <Location, bool> > res = x => x.WarehouseId == wareHouse.Id; return(_locationRepository.GetList(res)); }
public ActionResult <WarehouseDTO> GetWarehouse(int id) { WarehouseDTO item = repository.Get(id); if (item == null) { return(NotFound()); } return(item); }
public IActionResult Get(int id) { try { return(Ok(warehouseRepository.Get(id))); } catch (Exception e) { throw e; } }
public IActionResult Get(Nullable <Int64> id) { if (id == null) { return(BadRequest(null)); } else { var model = _repository.Get(id.Value); return(Ok(model)); } }
/// <summary> /// 新增门店 /// </summary> /// <returns></returns> public ActionResult AddStore(int?id) { ViewBag.categorys = AutofacDependencyResolver.Current.GetService <IProductCategoryRepository>(). GetRootCategorys().Select(o => new SelectListItem() { Text = o.Title, Value = o.CategorySN.ToString() }).ToList(); Warehouse model = null; if (id != null) { model = _warehouseRepository.Get(id); } return(View(model ?? new Warehouse())); }
protected virtual ShipmentLeg CreateShipmentLeg(IShipment shipment, ShippingMethodDto shippingMethod, IEstimateSettings settings) { var postalCodeFrom = settings.PostalCodeFrom; var countryCodeFrom = settings.CountryCodeFrom; if (string.IsNullOrEmpty(shipment.WarehouseCode) == false) { var warehouse = _warehouseRepository.Get(shipment.WarehouseCode); var warehousePostalCode = warehouse.ContactInformation?.PostalCode; var warehouseCountryCode = warehouse.ContactInformation?.CountryCode; if (string.IsNullOrEmpty(warehousePostalCode) == false && warehouse.IsPickupLocation) { postalCodeFrom = warehousePostalCode; countryCodeFrom = warehouseCountryCode.ToIso2CountryCode(); } } var countryCodeTo = shipment.ShippingAddress.CountryCode.ToIso2CountryCode(); return(new ShipmentLeg(postalCodeFrom, shipment.ShippingAddress.PostalCode, countryCodeFrom, countryCodeTo)); }
/// <summary> /// Gets all item in stock. /// </summary> /// <param name="inventories"> The WarehouseInventory.</param> /// <returns></returns> public static IWarehouseInventory SumInventories(IEnumerable <IWarehouseInventory> inventories) { WarehouseInventory result = new WarehouseInventory() { InStockQuantity = 0, ReservedQuantity = 0, ReorderMinQuantity = 0, PreorderQuantity = 0, BackorderQuantity = 0, AllowBackorder = false, AllowPreorder = false, PreorderAvailabilityDate = DateTime.MaxValue, BackorderAvailabilityDate = DateTime.MaxValue }; IWarehouseRepository warehouseRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <IWarehouseRepository>(); foreach (IWarehouseInventory inventory in inventories) { if (warehouseRepository.Get(inventory.WarehouseCode).IsActive) { // Sum up quantity fields result.BackorderQuantity += inventory.BackorderQuantity; result.InStockQuantity += inventory.InStockQuantity; result.PreorderQuantity += inventory.PreorderQuantity; result.ReorderMinQuantity += inventory.ReorderMinQuantity; result.ReservedQuantity += inventory.ReservedQuantity; // Check flags that should be global when aggregating warehouse inventories result.AllowBackorder = inventory.AllowBackorder ? inventory.AllowBackorder : result.AllowBackorder; result.AllowPreorder = inventory.AllowPreorder ? inventory.AllowPreorder : result.AllowPreorder; result.BackorderAvailabilityDate = GetAvailabilityDate(result.BackorderAvailabilityDate, inventory.BackorderAvailabilityDate); result.PreorderAvailabilityDate = GetAvailabilityDate(result.PreorderAvailabilityDate, inventory.PreorderAvailabilityDate); } } return(result); }
public Product Map(ProductViewModel productViewModel) { if (productViewModel == null) { return(null); } List <Inventory> inventory = new List <Inventory>(); Product product = new Product(productViewModel.Sku, productViewModel.Name, inventory); foreach (var warehouseViewModel in productViewModel.Inventory.Warehouses) { var warehouse = warehouseRepository.Get(warehouseViewModel.Locality, warehouseViewModel.Type.ToString()); if (warehouse == null) { warehouse = new Warehouse(warehouseViewModel.Locality, warehouseViewModel.Type); warehouseRepository.Add(warehouse); } inventory.Add(new Inventory(product.Id, warehouse.Id, warehouseViewModel.Quantity)); } return(product); }
protected void SetDefaultInventory(string code, decimal inStockQuantity, string warehouseCode = "default") { _log.Debug("Setting stock for {0} to {1}", code, inStockQuantity); var warehouse = _warehouseRepository.Get(warehouseCode); if (warehouse == null) { throw new ArgumentNullException("warehouse"); } if (inStockQuantity == 0) { throw new ArgumentNullException("inStockQuantity", "InStockQuantity is required"); } CatalogKey key = new CatalogKey(Mediachase.Commerce.Core.AppContext.Current.ApplicationId, code); var existingInventory = _inventoryService.Get(key, warehouse); WarehouseInventory inv; if (existingInventory != null) { inv = new WarehouseInventory(existingInventory); } else { inv = new WarehouseInventory(); inv.WarehouseCode = warehouse.Code; inv.CatalogKey = key; } inv.InStockQuantity = inStockQuantity; _inventoryService.Save(inv); }
public Warehouse GetWarehouseByName(string warehouseName) { return(warehouseRepository.Get(c => c.Name == warehouseName)); }
public IWarehouse GetWarehouse(string warehouseCode) { return(_warehouseRepository.Get(warehouseCode)); }
public AddToCartResult AddToCart(ICart cart, EntryContentBase entryContent, decimal quantity, string deliveryMethod, string warehouseCode) { var result = new AddToCartResult(); var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); if (contact?.OwnerId != null) { var org = cart.GetString("OwnerOrg"); if (string.IsNullOrEmpty(org)) { cart.Properties["OwnerOrg"] = contact.OwnerId.Value.ToString().ToLower(); } } IWarehouse warehouse = null; if (deliveryMethod.Equals("instore") && !string.IsNullOrEmpty(warehouseCode)) { warehouse = _warehouseRepository.Get(warehouseCode); } if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(entryContent.ContentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry, relation.Quantity ?? 1, deliveryMethod, warehouseCode); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } var form = cart.GetFirstForm(); if (form == null) { form = _orderGroupFactory.CreateOrderForm(cart); form.Name = cart.Name; cart.Forms.Add(form); } var shipment = cart.GetFirstShipment(); if (warehouse != null) { if (shipment != null && !shipment.LineItems.Any()) { shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); } else { shipment = form.Shipments.FirstOrDefault(x => !string.IsNullOrEmpty(x.WarehouseCode) && x.WarehouseCode.Equals(warehouse.Code)); if (shipment == null) { shipment = _orderGroupFactory.CreateShipment(cart); shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; cart.GetFirstForm().Shipments.Add(shipment); shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); } } } if (shipment == null) { shipment = _orderGroupFactory.CreateShipment(cart); cart.GetFirstForm().Shipments.Add(shipment); } var lineItem = cart.GetAllLineItems().FirstOrDefault(x => x.Code == entryContent.Code); if (lineItem == null) { lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory); lineItem.DisplayName = entryContent.DisplayName; lineItem.Quantity = quantity; cart.AddLineItem(shipment, lineItem); } else { cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } var validationIssues = ValidateCart(cart); AddValidationMessagesToResult(result, lineItem, validationIssues); return(result); }
public AddToCartResult AddToCart(ICart cart, EntryContentBase entryContent, decimal quantity, string deliveryMethod, string warehouseCode, List <string> dynamicVariantOptionCodes) { var result = new AddToCartResult(); var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); if (contact?.OwnerId != null) { var org = cart.GetString("OwnerOrg"); if (string.IsNullOrEmpty(org)) { cart.Properties["OwnerOrg"] = contact.OwnerId.Value.ToString().ToLower(); } } IWarehouse warehouse = null; if (deliveryMethod.Equals("instore") && !string.IsNullOrEmpty(warehouseCode)) { warehouse = _warehouseRepository.Get(warehouseCode); } if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(entryContent.ContentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry, (relation.Quantity ?? 1) * quantity, deliveryMethod, warehouseCode, dynamicVariantOptionCodes); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } var form = cart.GetFirstForm(); if (form == null) { form = _orderGroupFactory.CreateOrderForm(cart); form.Name = cart.Name; cart.Forms.Add(form); } var shipment = cart.GetFirstForm().Shipments.FirstOrDefault(x => string.IsNullOrEmpty(warehouseCode) || (x.WarehouseCode == warehouseCode && x.ShippingMethodId == InStorePickupInfoModel.MethodId)); if (warehouse != null) { if (shipment != null && !shipment.LineItems.Any()) { shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); } else { shipment = form.Shipments.FirstOrDefault(x => !string.IsNullOrEmpty(x.WarehouseCode) && x.WarehouseCode.Equals(warehouse.Code)); if (shipment == null) { if (cart.GetFirstShipment().LineItems.Count > 0) { shipment = _orderGroupFactory.CreateShipment(cart); } else { shipment = cart.GetFirstShipment(); } shipment.WarehouseCode = warehouseCode; shipment.ShippingMethodId = InStorePickupInfoModel.MethodId; shipment.ShippingAddress = GetOrderAddressFromWarehosue(cart, warehouse); if (cart.GetFirstShipment().LineItems.Count > 0) { cart.GetFirstForm().Shipments.Add(shipment); } } } } if (shipment == null) { var cartFirstShipment = cart.GetFirstShipment(); if (cartFirstShipment == null) { shipment = _orderGroupFactory.CreateShipment(cart); cart.GetFirstForm().Shipments.Add(shipment); } else { if (cartFirstShipment.LineItems.Count > 0) { shipment = _orderGroupFactory.CreateShipment(cart); cart.GetFirstForm().Shipments.Add(shipment); } else { shipment = cartFirstShipment; } } } var lineItem = shipment.LineItems.FirstOrDefault(x => x.Code == entryContent.Code); decimal originalLineItemQuantity = 0; if (lineItem == null) { lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory); var lineDisplayName = entryContent.DisplayName; if (dynamicVariantOptionCodes?.Count > 0) { lineItem.Properties[VariantOptionCodesProperty] = string.Join(",", dynamicVariantOptionCodes.OrderBy(x => x)); lineDisplayName += " - " + lineItem.Properties[VariantOptionCodesProperty]; } lineItem.DisplayName = lineDisplayName; lineItem.Quantity = quantity; cart.AddLineItem(shipment, lineItem); } else { if (lineItem.Properties[VariantOptionCodesProperty] != null) { var variantOptionCodesLineItem = lineItem.Properties[VariantOptionCodesProperty].ToString().Split(','); var intersectCodes = variantOptionCodesLineItem.Intersect(dynamicVariantOptionCodes); if (intersectCodes != null && intersectCodes.Any() && intersectCodes.Count() == variantOptionCodesLineItem.Length && intersectCodes.Count() == dynamicVariantOptionCodes.Count) { originalLineItemQuantity = lineItem.Quantity; cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } else { lineItem = cart.CreateLineItem(entryContent.Code, _orderGroupFactory); lineItem.Properties[VariantOptionCodesProperty] = string.Join(",", dynamicVariantOptionCodes.OrderBy(x => x)); lineItem.DisplayName = entryContent.DisplayName + " - " + lineItem.Properties[VariantOptionCodesProperty]; lineItem.Quantity = quantity; cart.AddLineItem(shipment, lineItem); } } else { originalLineItemQuantity = lineItem.Quantity; cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } } var validationIssues = ValidateCart(cart); var newLineItem = shipment.LineItems.FirstOrDefault(x => x.Code == entryContent.Code); var isAdded = (newLineItem != null ? newLineItem.Quantity : 0) - originalLineItemQuantity > 0; AddValidationMessagesToResult(result, lineItem, validationIssues, isAdded); return(result); }
public ApiResponse <ApiWarehouse> Get() { return(new ApiResponse <ApiWarehouse>(_repo.Get())); }
public JsonResult GetRepository(int id) { return(Json(_warehouseRepository.Get(id))); }
public object Post(JObject inventory) { // Need the catalog code string code = inventory["CatalogEntryCode"].Value <string>(); if (string.IsNullOrWhiteSpace(code)) { throw new ArgumentNullException("CatalogEntryCode", "CatalogEntryCode is required"); } string warehouseCode = "default"; if (string.IsNullOrEmpty(inventory["WarehouseCode"].Value <string>()) == false) { warehouseCode = inventory["WarehouseCode"].Value <string>(); } IWarehouseRepository warehouseRepository = ServiceLocator.Current.GetInstance <IWarehouseRepository>(); var warehouse = warehouseRepository.Get(warehouseCode); if (warehouse == null) { throw new ArgumentNullException("warehouse"); } decimal inStockQuantity = inventory["InStockQuantity"].Value <decimal>(); if (inStockQuantity == 0) { throw new ArgumentNullException("InStockQuantity", "InStockQuantity is required"); } CatalogKey key = new CatalogKey(AppContext.Current.ApplicationId, code); var inventoryService = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>(); var existingInventory = inventoryService.Get(key, warehouse); WarehouseInventory inv; if (existingInventory != null) { inv = new WarehouseInventory(existingInventory); } else { inv = new WarehouseInventory(); inv.WarehouseCode = warehouse.Code; inv.CatalogKey = key; } inv.InStockQuantity = inStockQuantity; // Set tracking status, if passed in, if not, ignore it string status = inventory["InventoryStatus"].Value <string>(); if (string.IsNullOrEmpty(status) == false) { InventoryTrackingStatus inventoryTrackingStatus; if (Enum.TryParse(status, true, out inventoryTrackingStatus)) { inv.InventoryStatus = inventoryTrackingStatus; } } inventoryService.Save(inv); return(Get(key.CatalogEntryCode)); }