public void Create(RestRegex regex) { using (var trans = Session.BeginTransaction()) { Session.Save(regex); trans.Commit(); } }
public ActionResult Edit(long id, RestRegex regex, string regexType) { GetRegexType(regex, regexType); ValidateRestRegex(regex); if (!ModelState.IsValid) { return View(regex); } Regexes.Edit(id, regex); return RedirectToAction("Index"); }
public void Edit(long id, RestRegex regex) { using (var trans = Session.BeginTransaction()) { var dbRegex = Session.Get<RestRegex>(id); dbRegex.IsCode = regex.IsCode; dbRegex.IsDiff = regex.IsDiff; dbRegex.IsEdit = regex.IsEdit; dbRegex.IsHistory = regex.IsHistory; dbRegex.MatchRegex = regex.MatchRegex; dbRegex.Name = regex.Name; dbRegex.ReplaceRegex = regex.ReplaceRegex; Session.Update(dbRegex); trans.Commit(); } }
public ActionResult SetupForScrewTurn() { var code = new RestRegex { Name = "ScrewTurn Wiki View Code", IsCode = true, MatchRegex = @"^(http|https)://((.)+)/((.)+).ashx", ReplaceRegex = @"$1://$2/$4.ashx?Code=1" }; var edit = new RestRegex { Name = "ScrewTurn Wiki Edit", IsEdit = true, MatchRegex = @"^(http|https)://((.)+)/((.)+).ashx", ReplaceRegex = @"$1://$2/Edit.aspx?Page=$4" }; var hist = new RestRegex { Name = "ScrewTurn Wiki History", IsHistory = true, MatchRegex = @"^(http|https)://((.)+)/((.)+).ashx", ReplaceRegex = @"$1://$2/History.aspx?Page=$4" }; var diff = new RestRegex { Name = "ScrewTurn Wiki Diff", IsDiff = true, MatchRegex = @"^(http|https)://((.)+)/((.)+).ashx", ReplaceRegex = "$1://$2/Diff.aspx?Page=$4&Rev1=VERSION&Rev2=Current" }; Regexes.Create(diff); Regexes.Create(hist); Regexes.Create(edit); Regexes.Create(code); return RedirectToAction("Index"); }
private void ValidateRestRegex(RestRegex regex) { if (string.IsNullOrEmpty(regex.Name)) { ModelState.AddModelError("Name", "Name is required.", ""); } if (string.IsNullOrEmpty(regex.MatchRegex)) { ModelState.AddModelError("MatchRegex", "Match Regex is required.", ""); } if (string.IsNullOrEmpty(regex.ReplaceRegex)) { ModelState.AddModelError("ReplaceRegex", "Replace Regex is required.", ""); } if(!(regex.IsDiff || regex.IsCode || regex.IsEdit || regex.IsHistory)) { ModelState.AddModelError("IsDiff", "At least one version must be checked.", ""); } }
void GetRegexType(RestRegex target, string radioButtonValue) { // HACK: sub-optimal way of handling radios, // but a change in the Entity, or a new one altogether, would be required otherwise target.IsDiff = false; target.IsEdit = false; target.IsHistory = false; switch(radioButtonValue) { case "code": target.IsCode = true; break; case "edit": target.IsEdit = true; break; case "history": target.IsHistory = true; break; case "diff": target.IsDiff = true; break; } }