/// <summary> /// Converts a List<Items> (shopping basket) to List of orderLines /// Ensures each item only listed once and allocates appropriate quantity. /// </summary> private List <OrderLines> ConvertToOrderLines(List <Items> basketObj) { List <OrderLines> orderLines = new List <OrderLines>(); foreach (var item in basketObj) { OrderLines tempOrderLine = new OrderLines(item); bool itemAlreadyInList = false; if (orderLines.Count == 0) { orderLines.Add(tempOrderLine); } else { foreach (var ol in orderLines) { if (ol.ItemId == item.ItemId) { ol.Quantity++; itemAlreadyInList = true; } } if (!itemAlreadyInList) { orderLines.Add(new OrderLines(item)); } } } return(orderLines); }
public bool CanPlaceOrder(decimal expectedTotalCost, decimal expectedShippingCost) { //An order must have at least one line if (!OrderLines.Any()) { return(false); } //All products must be available to order foreach (var line in OrderLines) { if (!_productAvailabilityService.CheckProductAvailability(line.Product.Stockcode, line.Quantity)) { return(false); } } //The calculated costs must match the expected ones CalculateShippingCost(); CalculateTotalCost(); if (TotalCost != expectedTotalCost || ShippingCost != expectedShippingCost) { return(false); } //if all checks succeeded, return true return(true); }
/// <summary> /// Removes orderline from the current order /// </summary> /// <param name="orderLine"></param> public void RemoveOrderLine(OrderLine orderLine) { if (CanOrderBeChanged()) { OrderLines.Remove(orderLine); } }
public int checkout(ShoppingCart cart) { var db = new DatabaseContext(); var newOrder = new Orders() { OrderDate = DateTime.Now, CustomersId = cart.userID }; db.Orders.Add(newOrder); db.SaveChanges(); foreach (var item in cart.shoppingCartItems) { var newItem = new OrderLines() { ProductsId = item.product.itemnumber, OrdersId = newOrder.Id, Quantity = item.quantity }; db.OrderLines.Add(newItem); } db.SaveChanges(); return(newOrder.Id); }
public void Validate() { if (string.IsNullOrWhiteSpace(OrderNumber)) { throw new ValidationErrorException(nameof(OrderNumber)); } if (TotalValue < 0) { throw new ValidationErrorException(nameof(TotalValue)); } if (Customer == null) { throw new ValidationErrorException(nameof(Customer)); } Customer.Validate(); if (ShippingAddress == null) { throw new ValidationErrorException(nameof(ShippingAddress)); } ShippingAddress.Validate(); if (OrderLines == null || !OrderLines.Any()) { throw new ValidationErrorException(nameof(OrderLines)); } OrderLines.ForEach(o => o.Validate()); }
public static void Load(OrderLines instance) { var db = new DefaultConnection(); foreach (var u in db.OrderLines) { BaseOrderLine l = null; if (u.LineType == "OrderLine") { l = addOrderLine(u); } else if (u.LineType == "TaxOnLine") { l = addTaxLine(u); } else if (u.LineType == "ChargeLine") { l = addChargeLine(u); } if (l == null) { continue; } instance.Add(l); } }
public OrderLines Update(OrderLines orderlinesParam) { var orderline = _db.OrderLines.Find(orderlinesParam.Id); if (orderline == null) { throw new Exception("Product not found"); } if (orderlinesParam.Order != orderline.Order) { // type has changed so check if the new type is already taken if (_db.OrderLines.Any(x => x.Order == orderlinesParam.Order)) { throw new Exception(orderlinesParam.Order + " is already taken"); } } //productTypes.UpdatedBy = User.Identity.Name; orderline.UpdatedBy = "Admin"; orderline.UpdatedDate = DateTime.Now; orderline.Price = orderlinesParam.Price; orderline.OrderIdFk = orderlinesParam.OrderIdFk; orderline.Quantity = orderlinesParam.Quantity; orderline.ProductIdFk = orderlinesParam.ProductIdFk; orderline.TotalPrice = orderlinesParam.TotalPrice; orderline.IsActive = orderlinesParam.IsActive; _db.OrderLines.Update(orderline); _db.SaveChanges(); return(orderline); }
/// <summary> /// Get orderlines by order iD /// </summary> /// <param name="orderId"></param> /// <returns></returns> public List <OrderLines> GetLinesByOrderId(int orderId) { List <OrderLines> aLine = new List <OrderLines>(); try { OracleCommand commn = dataConnection.ConnectToDatabase(); commn.CommandText = "select o.orderlineid, p.productId, p.productname, o.quantity, o.UNITPRICE from product p inner join orderline o " + "on p.productid = o.productid where o.orderid=" + orderId; OracleDataReader odr = commn.ExecuteReader(); while (odr.Read()) { OrderLines odrLine = new OrderLines(); odrLine.OrderLineId = odr.GetInt32(0); odrLine.OrderId = orderId; odrLine.ProductId = odr.GetInt32(1); Product aProduct = new Product(); aProduct.ProductId = odr.GetInt32(1); aProduct.ProductName = odr.GetString(2); odrLine.Quantity = odr.GetInt32(3); odrLine.UnitPrice = odr.GetFloat(4); odrLine.ProductInfo = aProduct; aLine.Add(odrLine); } dataConnection.CloseDatabase(); } catch (Exception e) { } finally { dataConnection.CloseDatabase(); } return(aLine); }
// /OrderLines/Change [POST] public ActionResult Change([FromBody] OrderLines orderLines) { OrderLines orderLines2 = db.OrderLines.Find(orderLines.Id); if (orderLines2 == null) { return(Json(new JsonMessage("Failure", "Record that needs to be changed has been deleted"), JsonRequestBehavior.AllowGet)); } orderLines2.OrderId = orderLines.OrderId; orderLines2.LineNbr = orderLines.LineNbr; orderLines2.Product = orderLines.Product; orderLines2.Price = orderLines.Price; orderLines2.Quantity = orderLines.Quantity; orderLines2.LineTotal = orderLines.LineTotal; try { db.SaveChanges(); } catch (Exception ex) { return(Json(new JsonMessage("Failure", ex.Message), JsonRequestBehavior.AllowGet)); } return(Json(new JsonMessage("Success", "Order Lines was updated"))); }
public OrderLines UpdateOrderLines(OrderLines orderLines) { if (orderLines != null) { OrderLines orderLinesUpd = _DbModelEntities.OrderLines.FirstOrDefault(p => p.OrderLineID.Equals(orderLines.OrderLineID)); if (orderLinesUpd != null) { orderLinesUpd.Description = orderLines.Description; orderLinesUpd.PackageTypeID = orderLines.PackageTypeID; orderLinesUpd.Quantity = orderLines.Quantity; orderLinesUpd.UnitPrice = orderLines.UnitPrice; orderLinesUpd.TaxRate = orderLines.TaxRate; orderLinesUpd.PickedQuantity = orderLines.PickedQuantity; } else { return(null); } _DbModelEntities.SaveChanges(); return(orderLinesUpd); } return(null); }
public virtual void AddLine(string productName, int quantity, Money price, string productUrlName, int productId, string sizeName) { if (productName == null) { throw new ArgumentNullException("productName"); } if (quantity == 0) { throw new ArgumentException("quantity can not be zero"); } if (productUrlName == null) { throw new ArgumentNullException("productUrlName"); } if (sizeName == null) { throw new ArgumentNullException("sizeName"); } var orderLine = new OrderLine { ProductName = productName, Quantity = quantity, Price = price, Order = this, ProductUrlName = productUrlName, ProductId = productId, SizeName = sizeName }; OrderLines.Add(orderLine); }
public void AddOrderLine(Product p) { OrderLines.Add(new OrderLineViewModel(p)); UpdateTotal(); //refresh the commands RaisePropertyChanged(nameof(OnCancelCommand)); RaisePropertyChanged(nameof(OnOrderCommand)); }
/// <summary> /// Adds the product. /// </summary> /// <param name="product">The product.</param> /// <param name="quantity">The quantity.</param> /// <param name="discount">The discount.</param> public void AddProduct(Product product, int quantity, decimal discount = 0) { if (OrderLines == null) { OrderLines = new List <OrderLine>(); } OrderLines.Add(new OrderLine(this, product, quantity, discount)); }
/// <summary> /// Obtenemos un registro por su ID de la tabla OrderLines /// </summary> /// <param name="OrderLineID"></param> /// <returns></returns> public OrderLines GetOrderLinesById(int orderLineID) { OrderLines orderLines = new OrderLines(); orderLines = _DbModelEntities.OrderLines.FirstOrDefault(p => p.OrderLineID.Equals(orderLineID)); return(orderLines); }
public void AddProduct(Products product, int quantity) { if (OrderLines == null) { OrderLines = new List <OrderLine>(); } OrderLines.Add(new OrderLine(this, product, quantity)); }
private void CalculateSubtotalPrice() { OrderLines.ForEach(line => line.CalculatePrice()); var subtotal = OrderLines .Aggregate(0.0, (i, line) => i + line.Price); SubtotalPrice = Math.Round(subtotal, 2); }
public void CleanUpOrderLines() { List <DisplayOrderLine> LinesToRemove = OrderLines.Where(ol => ol.Amount <= 0).ToList(); foreach (DisplayOrderLine orderLine in LinesToRemove) { OrderLines.Remove(orderLine); } }
public void When_DeliverOrderCancelled_ThrowOrderCancelledException() { Given( new OrderCreated(id, basketId, shippingAddress), new OrderLineAdded(id, OrderLines.First()), new OrderReadyForShipping(id), new OrderCancelled(id)); WhenThrows <DeliverOrder, InvalidOrderStateException>(new DeliverOrder(id)); }
public void Add(Event newevent) { OrderLines = OrderLines ?? new List <OrderLine>(); OrderLines.Add(new EventOrderLine(newevent) { ID = Guid.NewGuid() }); Total += newevent.Price; }
public void addNewOrderLine(OrderLines orderLine) { using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); connection.Execute(@"insert into OrderLines(OrderId, ProductId) values (@OrderId,@ProductId)", orderLine); } }
public OrderLines Create(OrderLines orderlines) { orderlines.CreatedBy = "Admin"; orderlines.CreatedDate = DateTime.Now; orderlines.IsActive = true; _db.OrderLines.Add(orderlines); _db.SaveChanges(); return(orderlines); }
public void AddOrderLine(OrderLine orderLine) { OrderLines.Add(orderLine); Status = OrderStatus.SelectingProducts; DefaultPrice += orderLine.TotalDefaultCost; ActualPrice += orderLine.TotalActualCost; }
public void RemoveOrderLine(OrderLine orderLine) { var itemToRemove = OrderLines.Single(o => o.Id == orderLine.Id); DefaultPrice -= orderLine.TotalDefaultCost; ActualPrice -= orderLine.TotalActualCost; OrderLines.Remove(itemToRemove); }
public void CartToOrder(ICollection <CartLine> cartLines) { foreach (var item in cartLines) { OrderLines.Add(new OrderLine { Product = item.Product, Quantity = item.Quantity }); } }
public void MakeOrder(IEnumerable <CartItem> items, OrderDetails ord) { var orderDto = new Orders(); PropertyCopier <OrderDetails, Orders> .Copy(ord, orderDto); using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) { try { var orderId = InsertOrder(orderDto, connection, transaction); foreach (var cartItem in items) { var orderLineFoodItemDto = new OrderLines(); PropertyCopier <CartItem, OrderLines> .Copy(cartItem, orderLineFoodItemDto); orderLineFoodItemDto.OrderId = orderId; for (int i = 0; i < cartItem.Quantity; i++) { var parentId = InsertOrder(orderLineFoodItemDto, connection, transaction); foreach (var cartItemIngredient in cartItem.Ingredients) { var orderLineIngredientDto = new OrderLines(); PropertyCopier <CartItemIngredient, OrderLines> .Copy(cartItemIngredient, orderLineIngredientDto); orderLineIngredientDto.OrderId = orderId; orderLineIngredientDto.ParentId = parentId; InsertOrder(orderLineIngredientDto, connection, transaction); } } } transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } finally { connection.Close(); } } } }
/// <summary> /// Creates a new order line for the provided item in the order header. /// </summary> /// <param name="itemToAdd"></param> public void CreateOrderLineForItem(Item itemToAdd) { OrderLine orderLine = new OrderLine() { Item = itemToAdd, Qty = 1 }; OrderLines.Add(orderLine); }
public async Task <OrderLines> AddAsyncOrderLine(OrderLines entity) { if (entity != null) { _dbContext.OrderLines.Add(entity); await _dbContext.SaveChangesAsync(); } return(entity); }
public Order AddOrderLine(Guid itemId, int quantity, Money price) { if (OrderLines == null) { OrderLines = new List <OrderLine>(); } OrderLines.Add(new OrderLine(itemId, quantity, price)); return(this); }
public override Model.Order ToModel() { return(new Model.BreadOrder() { Id = Id, CustomerName = CustomerName, CustomerAddress = CustomerAddress, OrderLines = OrderLines.Select(o => o.ToModel()).ToList() }); }
public OrderViewModel(IFormatProvider currencyFormat, PurchaseOrderModel order) : this(currencyFormat) { OrderNumber = order.TrackingNumber; OrderDate = order.Created; Status = order.Status; TotalLineItemsAmount = order.OrderForms.First().LineItems.Sum(i => i.ExtendedPrice); TotalAmount = order.Total; Shipping = order.ShippingTotal; // TODO: Make taxes work as it should, instead of flat hard codet 25% tax if (order.TaxTotal == 0 && order.Total > 0) { order.TaxTotal = ((decimal)0.25) * order.Total; } Tax = order.TaxTotal; Discount = order.OrderForms.First().LineItems.Sum(i => i.LineItemDiscountAmount + i.OrderLevelDiscountAmount) + order.OrderForms.First().Shipments.First().ShippingDiscountAmount; if (order.OrderForms.Any() && order.OrderForms.First().Payments.Any()) { PaymentMethod = order.OrderForms.First().Payments.First().PaymentMethodName; } Email = order.BillingEmail; Phone = order.BillingPhone; BillingAddress = new Address(order.OrderAddresses.FirstOrDefault(a => a.Name == Constants.Order.BillingAddressName)); var shippingAddress = order.OrderAddresses.FirstOrDefault(a => a.Name == Constants.Order.ShippingAddressName); ShippingAddress = new Address(shippingAddress); DeliveryLocation = ""; if (shippingAddress != null && !string.IsNullOrWhiteSpace(shippingAddress.DeliveryServicePoint)) { DeliveryLocation = shippingAddress.DeliveryServicePoint; } foreach (var item in order.OrderForms.First().LineItems) { OrderLines.Add(new OrderLineViewModel(item)); } // discounts var discounts = CartService.GetAllDiscounts(order); DiscountCodes = discounts.Where(x => !string.IsNullOrEmpty(x.DiscountCode)).Select(x => x.DiscountCode).ToList(); ShippingTrackingNumber = ""; if (order.OrderForms.Any() && order.OrderForms.First().Shipments != null && order.OrderForms.First().Shipments.Any()) { ShippingTrackingNumber = order.OrderForms.First().Shipments.First().ShipmentTrackingNumber; } ErpOrderNumber = order.BackendOrderNumber; }
public Order() { orderLines = new OrderLines(); }