public ActionResult Create([Bind(Include = "Id,Name,Limit,StartTime,EndTime,Visible")] TestMatch testMatch) { if (ModelState.IsValid) { testMatch.Id = Guid.NewGuid(); db.TestMatches.Add(testMatch); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(testMatch)); }
public ActionResult DeleteConfirmed(Guid id) { TestMatch testMatch = db.TestMatches.Find(id); foreach (var item in testMatch.RecordsCollection) { db.TestRecords.Remove(item); } db.SaveChanges(); db.TestMatches.Remove(testMatch); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Administrator/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TestMatch testMatch = db.TestMatches.Find(id); if (testMatch == null) { return(HttpNotFound()); } return(View(testMatch)); }
public ActionResult Edit([Bind(Include = "Id,Name,Limit,StartTime,EndTime,Visible,RowVersion")] TestMatch testMatch) { if (ModelState.IsValid) { db.Entry(testMatch).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); return(RedirectToAction("Index", new { message = MessageType.DbUpdateFailed })); } return(RedirectToAction("Index")); } return(View(testMatch)); }
String TryRule(String input, IEnumerable <Alias> choices, TestMatch rule) { Alias match = null; foreach (var choice in choices) { bool matched = rule(input, choice); if (matched) { if ((match != null) && (match.MapsTo != choice.MapsTo)) { // two matches return("Error"); } match = choice; } } if (match != null) { return(match.MapsTo); } return(null); }
private IEnumerable <TestMatch> GetRules(string input) { // check for exact match. TestMatch ruleExact = (userInput, choice) => { bool ok = String.Compare(userInput, choice.Original, StringComparison.InvariantCultureIgnoreCase) == 0; return(ok); }; //initials TestMatch ruleInitials = (userInput, choice) => { if (!choice.Original[0].ToString().ToLowerInvariant(). Equals(userInput[0].ToString().ToLowerInvariant())) { return(false); } int ixMatch = -1; foreach (char ch in userInput) { int ix = choice.Original.IndexOf(ch.ToString(), ixMatch + 1, StringComparison.InvariantCultureIgnoreCase); ixMatch = ix; if (ix == -1) { return(false); } } return(true); }; // check for input inside the string TestMatch ruleConsecutive = (userInput, choice) => { String ui = userInput.ToLowerInvariant(); String ci = choice.Original.ToLowerInvariant(); return(ci.Contains(ui)); }; // check for input inside the string TestMatch ruleStart = (userInput, choice) => { String ui = userInput.ToLowerInvariant(); String ci = choice.Original.ToLowerInvariant(); return(ci.StartsWith(ui)); }; List <TestMatch> rules = new List <TestMatch>(); rules.Add(ruleExact); if (input.Length > 2) { rules.Add(ruleStart); rules.Add(ruleInitials); rules.Add(ruleConsecutive); } else { if (input.Length == 2) { rules.Add(ruleInitials); } } return(rules); }