public async Task <ActionResult <Order> > PostOrder(Order order) { OrderRules.ProcessRules(order); _context.Order.Add(order); await _context.SaveChangesAsync(); return(CreatedAtAction("GetOrder", new { id = order.OrderId }, order)); }
public override void Handle(OrderRules rule, ref ICollection<TeamInTableViewModel> teamsStats) { if (rule == OrderRules.DirectMatch) { // TODO } else if(Successor != null) { Successor.Handle(rule, ref teamsStats); } }
public override void Handle(OrderRules rule, ref ICollection <TeamInTableViewModel> teamsStats) { if (rule == OrderRules.DirectMatch) { // TODO } else if (Successor != null) { Successor.Handle(rule, ref teamsStats); } }
public override void Handle(OrderRules rule, ref ICollection <TeamInTableViewModel> teamsStats) { if (rule == OrderRules.SmallPointsRatio) { var teamInTableViewModels = teamsStats.OrderByDescending(t => t.PointsRatio); teamsStats = teamInTableViewModels.ToList(); } else if (Successor != null) { Successor.Handle(rule, ref teamsStats); } }
private string GetPriceForWhiteMatrix(OrderRules rules) { if (rules.BuyingMatrix != null && rules.BuyingMatrixType == MatrixType.WhiteList) { return(string.Format("{0} - ({1})", rules.BuyingMatrixPrice.Supplier.Name, rules.BuyingMatrixPrice.PriceName)); } if (rules.OfferMatrix != null && rules.OfferMatrixType == MatrixType.WhiteList) { return(string.Format("{0} - ({1})", rules.OfferMatrixPrice.Supplier.Name, rules.OfferMatrixPrice.PriceName)); } return(null); }
public override void Handle(OrderRules rule, ref ICollection<TeamInTableViewModel> teamsStats) { if (rule == OrderRules.SmallPointsRatio) { var teamInTableViewModels = teamsStats.OrderByDescending(t => t.PointsRatio); teamsStats = teamInTableViewModels.ToList(); } else if (Successor != null) { Successor.Handle(rule, ref teamsStats); } }
public void TestFailureOrderContentBadMorningOrderMultipleInvalidDessert() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "Morning,1,2,3,4,4" }; OrderRules.ProcessRules(order); Assert.AreEqual("eggs, Toast, coffee, error", order.OrderContents); }
public void TestSuccessMorningCaseMultipleDrinks() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "morning,1,2,3,3" }; OrderRules.ProcessRules(order); Assert.AreEqual("eggs, Toast, coffee(x2)", order.OrderContents); }
public void TestFailureOrderContentBadNightOrderMultipleInvalidEntrée() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "Night,1,1,2" }; OrderRules.ProcessRules(order); Assert.AreEqual("steak, error", order.OrderContents); }
public void TestFailureOrderContentNoCommaCase2() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "Night.1;2/3'4" }; OrderRules.ProcessRules(order); Assert.AreEqual("error", order.OrderContents); }
public void TestFailureOrderContentCommaInvalid() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "bleh,nhjaks" }; OrderRules.ProcessRules(order); Assert.AreEqual("error", order.OrderContents); }
public void TestFailureOrderContentBadMorningOrderMultipleInvalidDrink() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "Night,1,2,3,3" }; OrderRules.ProcessRules(order); Assert.AreEqual("steak, potato, wine, error", order.OrderContents); }
public void TestSuccessNightCaseMultipleSides() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "night,1,2,2,3,4" }; OrderRules.ProcessRules(order); Assert.AreEqual("steak, potato(x2), wine, cake", order.OrderContents); }
public void TestFailureOrderContentNull() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = null }; OrderRules.ProcessRules(order); Assert.AreEqual("error", order.OrderContents); }
public void TestSuccessMorningCaseBasic() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "Morning,1,2,3" }; OrderRules.ProcessRules(order); Assert.AreEqual("eggs, Toast, coffee", order.OrderContents); }
public void StartLevel(GameObject levelPrefab) { Debug.Log("Starting level"); CountCoins(); if (waveRules != null && waveRules.IsRunning()) { Debug.LogError("Level is already running, ignoring"); return; } waveRules = levelPrefab.GetComponent <WaveRules>(); orderRules = levelPrefab.GetComponent <OrderRules>(); burgerScorer = levelPrefab.GetComponent <BurgerScorer>(); StartLevel(); }
private void PrepareCollumns(DataTable table, OrderRules rules) { table.Columns.Remove("BuyingMatrixType"); if ((rules.BuyingMatrixType == MatrixType.WhiteList && rules.BuyingMatrix != null && (rules.OfferMatrix == null || rules.OfferMatrixType == MatrixType.WhiteList)) || (rules.OfferMatrixType == MatrixType.WhiteList && rules.OfferMatrix != null && (rules.BuyingMatrix == null || rules.BuyingMatrixType == MatrixType.WhiteList))) { table.Columns.Remove("ProductId"); table.Columns.Remove("ProducerId"); table.Columns.Remove("ProductSynonym"); table.Columns.Remove("ProducerSynonym"); CollumnNames = CollumnNames.Skip(4).ToArray(); } }
private SqlParts GetPartsData(OrderRules rules) { var offerJoinPart = string.Empty; var offerSelectPart = string.Empty; var buyingJoinPart = string.Empty; var buyingSelectPart = string.Empty; if (rules.OfferMatrix.HasValue) { offerJoinPart = "left join usersettings.PricesData pd1 on pd1.PriceCode = mol.PriceId\r\n" + "left join customers.Suppliers s1 on s1.Id = pd1.FirmCode"; offerSelectPart = "Concat(s1.Name, ' - (', pd1.PriceName, ')')"; } if (rules.BuyingMatrix.HasValue) { buyingJoinPart = "left join usersettings.PricesData pd3 on pd3.PriceCode = bol.PriceId\r\n" + "left join customers.Suppliers s3 on s3.Id = pd3.FirmCode"; buyingSelectPart = "Concat(s3.Name, ' - (', pd3.PriceName, ')')"; } var part = new SqlParts(); if (!string.IsNullOrEmpty(offerJoinPart)) { part.Join += offerJoinPart + Environment.NewLine; } if (!string.IsNullOrEmpty(buyingJoinPart)) { part.Join += buyingJoinPart + Environment.NewLine; } if (rules.OfferMatrix.HasValue && rules.BuyingMatrix.HasValue) { part.Select = string.Format(@"if(({0}) is not null, {0}, {1})", offerSelectPart, buyingSelectPart); } else { if (rules.OfferMatrix.HasValue) { part.Select = offerSelectPart; } if (rules.BuyingMatrix.HasValue) { part.Select = buyingSelectPart; } } part.Select += " as MatrixPriceName"; return(part); }
public void TestSuccessNightCases() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "night,1,2,3,4" }; OrderRules.ProcessRules(order); Assert.AreEqual("steak, potato, wine, cake", order.OrderContents); Order order2 = new Order { OrderId = 0, IsMorning = false, OrderContents = "Night,1,2,2,4" }; OrderRules.ProcessRules(order2); Assert.AreEqual("steak, potato(x2), cake", order2.OrderContents); Order order3 = new Order { OrderId = 0, IsMorning = false, OrderContents = "NiGhT,1,2,3,5" }; OrderRules.ProcessRules(order3); Assert.AreEqual("steak, potato, wine, error", order3.OrderContents); Order order4 = new Order { OrderId = 0, IsMorning = false, OrderContents = "Night, 1, 1, 2, 3, 5" }; OrderRules.ProcessRules(order4); Assert.AreEqual("steak, error", order4.OrderContents); }
public void TestSuccessMorningCases() { Order order = new Order { OrderId = 0, IsMorning = false, OrderContents = "MORNING,1,2,3" }; OrderRules.ProcessRules(order); Assert.AreEqual("eggs, Toast, coffee", order.OrderContents); Order order2 = new Order { OrderId = 0, IsMorning = false, OrderContents = "MoRnInG, 2, 1, 3" }; OrderRules.ProcessRules(order2); Assert.AreEqual("eggs, Toast, coffee", order2.OrderContents); Order order3 = new Order { OrderId = 0, IsMorning = false, OrderContents = "morning,1,2,3,4" }; OrderRules.ProcessRules(order3); Assert.AreEqual("eggs, Toast, coffee, error", order3.OrderContents); Order order4 = new Order { OrderId = 0, IsMorning = false, OrderContents = "morning,1,2,3,3,3" }; OrderRules.ProcessRules(order4); Assert.AreEqual("eggs, Toast, coffee(x3)", order4.OrderContents); }
private void ProcessElement(XmlReader xmlReader, StringBuilder output) { string currentIndentString = GetIndentString(xmlReader.Depth); string elementName = xmlReader.Name; if ("Run".Equals(elementName)) { if (output.IsNewLine()) { // Shall not add extra whitespaces (including linefeeds) before <Run/>, // because it will affect the rendering of <TextBlock><Run/><Run/></TextBlock> output .Append(currentIndentString) .Append('<') .Append(xmlReader.Name); } else { output.Append('<'); output.Append(xmlReader.Name); } } else if (output.Length == 0 || output.IsNewLine()) { output .Append(currentIndentString) .Append('<') .Append(xmlReader.Name); } else { output .Append(Environment.NewLine) .Append(currentIndentString) .Append('<') .Append(xmlReader.Name); } bool isEmptyElement = xmlReader.IsEmptyElement; bool hasPutEndingBracketOnNewLine = false; var list = new List <AttributeInfo>(xmlReader.AttributeCount); if (xmlReader.HasAttributes) { while (xmlReader.MoveToNextAttribute()) { string attributeName = xmlReader.Name; string attributeValue = xmlReader.Value; AttributeOrderRule orderRule = OrderRules.GetRuleFor(attributeName); list.Add(new AttributeInfo(attributeName, attributeValue, orderRule)); } if (Options.OrderAttributesByName) { list.Sort(); } currentIndentString = GetIndentString(xmlReader.Depth); var noLineBreakInAttributes = (list.Count <= Options.AttributesTolerance) || IsNoLineBreakElement(elementName); // Root element? if (_elementProcessStatusStack.Count == 2) { switch (Options.RootElementLineBreakRule) { case LineBreakRule.Default: break; case LineBreakRule.Always: noLineBreakInAttributes = false; break; case LineBreakRule.Never: noLineBreakInAttributes = true; break; default: throw new ArgumentOutOfRangeException(); } } // No need to break attributes if (noLineBreakInAttributes) { foreach (var attrInfo in list) { output .Append(' ') .Append(attrInfo.ToSingleLineString()); } _elementProcessStatusStack.Peek().IsMultlineStartTag = false; } // Need to break attributes else { IList <String> attributeLines = new List <String>(); var currentLineBuffer = new StringBuilder(); int attributeCountInCurrentLineBuffer = 0; AttributeInfo lastAttributeInfo = null; foreach (AttributeInfo attrInfo in list) { // Attributes with markup extension, always put on new line if (attrInfo.IsMarkupExtension && Options.FormatMarkupExtension) { string baseIndetationString; if (!Options.KeepFirstAttributeOnSameLine) { baseIndetationString = GetIndentString(xmlReader.Depth); } else { baseIndetationString = GetIndentString(xmlReader.Depth - 1) + string.Empty.PadLeft(elementName.Length + 2, ' '); } string pendingAppend; //Keep binding and / or x:bind on same line? if ((attrInfo.Value.ToLower().Contains("x:bind ") && Options.KeepxBindOnSameLine) || Options.KeepBindingsOnSameLine) { pendingAppend = " " + attrInfo.ToSingleLineString(); } else { pendingAppend = attrInfo.ToMultiLineString(baseIndetationString); } if (currentLineBuffer.Length > 0) { attributeLines.Add(currentLineBuffer.ToString()); currentLineBuffer.Length = 0; attributeCountInCurrentLineBuffer = 0; } attributeLines.Add(pendingAppend); } else { string pendingAppend = attrInfo.ToSingleLineString(); bool isAttributeCharLengthExceeded = (attributeCountInCurrentLineBuffer > 0 && Options.MaxAttributeCharatersPerLine > 0 && currentLineBuffer.Length + pendingAppend.Length > Options.MaxAttributeCharatersPerLine); bool isAttributeCountExceeded = (Options.MaxAttributesPerLine > 0 && attributeCountInCurrentLineBuffer + 1 > Options.MaxAttributesPerLine); bool isAttributeRuleGroupChanged = Options.PutAttributeOrderRuleGroupsOnSeparateLines && lastAttributeInfo != null && lastAttributeInfo.OrderRule.AttributeTokenType != attrInfo.OrderRule.AttributeTokenType; if (isAttributeCharLengthExceeded || isAttributeCountExceeded || isAttributeRuleGroupChanged) { attributeLines.Add(currentLineBuffer.ToString()); currentLineBuffer.Length = 0; attributeCountInCurrentLineBuffer = 0; } currentLineBuffer.AppendFormat("{0} ", pendingAppend); attributeCountInCurrentLineBuffer++; } lastAttributeInfo = attrInfo; } if (currentLineBuffer.Length > 0) { attributeLines.Add(currentLineBuffer.ToString()); } for (int i = 0; i < attributeLines.Count; i++) { if (0 == i && Options.KeepFirstAttributeOnSameLine) { output .Append(' ') .Append(attributeLines[i].Trim()); // Align subsequent attributes with first attribute currentIndentString = GetIndentString(xmlReader.Depth - 1) + String.Empty.PadLeft(elementName.Length + 2, ' '); continue; } output .Append(Environment.NewLine) .Append(currentIndentString) .Append(attributeLines[i].Trim()); } _elementProcessStatusStack.Peek().IsMultlineStartTag = true; } // Determine if to put ending bracket on new line if (Options.PutEndingBracketOnNewLine && _elementProcessStatusStack.Peek().IsMultlineStartTag) { output .Append(Environment.NewLine) .Append(currentIndentString); hasPutEndingBracketOnNewLine = true; } } if (isEmptyElement) { if (hasPutEndingBracketOnNewLine == false && Options.SpaceBeforeClosingSlash) { output.Append(' '); } output.Append("/>"); _elementProcessStatusStack.Peek().IsSelfClosingElement = true; } else { output.Append(">"); } }
private void ProcessElement(XmlReader xmlReader, StringBuilder output) { string currentIndentString = GetIndentString(xmlReader.Depth); string elementName = xmlReader.Name; // Calculate how element should be indented if (!_elementProcessStatusStack.Peek().IsPreservingSpace) { // "Run" get special treatment to try to preserve spacing. Use xml:space='preserve' to make sure! if (elementName.Equals("Run")) { _elementProcessStatusStack.Peek().Parent.IsSignificantWhiteSpace = true; if (output.Length == 0 || output.IsNewLine()) { output.Append(currentIndentString); } } else { _elementProcessStatusStack.Peek().Parent.IsSignificantWhiteSpace = false; if (output.Length == 0 || output.IsNewLine()) { output.Append(currentIndentString); } else { output .Append(Environment.NewLine) .Append(currentIndentString); } } } // Output the element itself output .Append('<') .Append(xmlReader.Name); bool isEmptyElement = xmlReader.IsEmptyElement; bool hasPutEndingBracketOnNewLine = false; var list = new List <AttributeInfo>(xmlReader.AttributeCount); if (xmlReader.HasAttributes) { while (xmlReader.MoveToNextAttribute()) { string attributeName = xmlReader.Name; string attributeValue = xmlReader.Value; AttributeOrderRule orderRule = OrderRules.GetRuleFor(attributeName); list.Add(new AttributeInfo(attributeName, attributeValue, orderRule)); // Check for xml:space as defined in http://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space if (xmlReader.IsXmlSpaceAttribute()) { _elementProcessStatusStack.Peek().IsPreservingSpace = (xmlReader.Value == "preserve"); } } if (Options.EnableAttributeReordering) { list.Sort(AttributeInfoComparison); } currentIndentString = GetIndentString(xmlReader.Depth); var noLineBreakInAttributes = (list.Count <= Options.AttributesTolerance) || IsNoLineBreakElement(elementName); var forceLineBreakInAttributes = false; // Root element? if (_elementProcessStatusStack.Count == 2) { switch (Options.RootElementLineBreakRule) { case LineBreakRule.Default: break; case LineBreakRule.Always: noLineBreakInAttributes = false; forceLineBreakInAttributes = true; break; case LineBreakRule.Never: noLineBreakInAttributes = true; break; default: throw new ArgumentOutOfRangeException(); } } // No need to break attributes if (noLineBreakInAttributes) { foreach (var attrInfo in list) { output .Append(' ') .Append(attrInfo.ToSingleLineString()); } _elementProcessStatusStack.Peek().IsMultlineStartTag = false; } // Need to break attributes else { IList <String> attributeLines = new List <String>(); var currentLineBuffer = new StringBuilder(); int attributeCountInCurrentLineBuffer = 0; AttributeInfo lastAttributeInfo = null; foreach (AttributeInfo attrInfo in list) { // Attributes with markup extension, always put on new line if (attrInfo.IsMarkupExtension && Options.FormatMarkupExtension) { string baseIndetationString; if (!Options.KeepFirstAttributeOnSameLine) { baseIndetationString = GetIndentString(xmlReader.Depth); } else { baseIndetationString = GetIndentString(xmlReader.Depth - 1) + string.Empty.PadLeft(elementName.Length + 2, ' '); } string pendingAppend; if (NoNewLineMarkupExtensionsList.Contains(attrInfo.MarkupExtension)) { pendingAppend = " " + attrInfo.ToSingleLineString(); } else { pendingAppend = attrInfo.ToMultiLineString(baseIndetationString); } if (currentLineBuffer.Length > 0) { attributeLines.Add(currentLineBuffer.ToString()); currentLineBuffer.Length = 0; attributeCountInCurrentLineBuffer = 0; } attributeLines.Add(pendingAppend); } else { string pendingAppend = attrInfo.ToSingleLineString(); bool isAttributeCharLengthExceeded = (attributeCountInCurrentLineBuffer > 0 && Options.MaxAttributeCharatersPerLine > 0 && currentLineBuffer.Length + pendingAppend.Length > Options.MaxAttributeCharatersPerLine); bool isAttributeCountExceeded = (Options.MaxAttributesPerLine > 0 && attributeCountInCurrentLineBuffer + 1 > Options.MaxAttributesPerLine); bool isAttributeRuleGroupChanged = Options.PutAttributeOrderRuleGroupsOnSeparateLines && lastAttributeInfo != null && lastAttributeInfo.OrderRule.Group != attrInfo.OrderRule.Group; if (currentLineBuffer.Length > 0 && (forceLineBreakInAttributes || isAttributeCharLengthExceeded || isAttributeCountExceeded || isAttributeRuleGroupChanged)) { attributeLines.Add(currentLineBuffer.ToString()); currentLineBuffer.Length = 0; attributeCountInCurrentLineBuffer = 0; } currentLineBuffer.AppendFormat("{0} ", pendingAppend); attributeCountInCurrentLineBuffer++; } lastAttributeInfo = attrInfo; } if (currentLineBuffer.Length > 0) { attributeLines.Add(currentLineBuffer.ToString()); } for (int i = 0; i < attributeLines.Count; i++) { if (0 == i && Options.KeepFirstAttributeOnSameLine) { output .Append(' ') .Append(attributeLines[i].Trim()); // Align subsequent attributes with first attribute currentIndentString = GetIndentString(xmlReader.Depth - 1) + String.Empty.PadLeft(elementName.Length + 2, ' '); continue; } output .Append(Environment.NewLine) .Append(currentIndentString) .Append(attributeLines[i].Trim()); } _elementProcessStatusStack.Peek().IsMultlineStartTag = true; } // Determine if to put ending bracket on new line if (Options.PutEndingBracketOnNewLine && _elementProcessStatusStack.Peek().IsMultlineStartTag) { output .Append(Environment.NewLine) .Append(currentIndentString); hasPutEndingBracketOnNewLine = true; } } if (isEmptyElement) { if (hasPutEndingBracketOnNewLine == false && Options.SpaceBeforeClosingSlash) { output.Append(' '); } output.Append("/>"); _elementProcessStatusStack.Peek().IsSelfClosingElement = true; } else { output.Append(">"); } }
public abstract void Handle(OrderRules rule, ref ICollection <TeamInTableViewModel> teamsStats);
public abstract void Handle(OrderRules rule, ref ICollection<TeamInTableViewModel> teamsStats);