public ActionResult Delete(int id) { var product = DocumentSession.Load <Product>(id); DocumentSession.Delete(product); return(RedirectToAction("Index")); }
public HttpResponseMessage Delete(int id) { var config = DocumentSession.Load <TaxRate>(id); DocumentSession.Delete(config); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public ActionResult Delete(int id) { var contato = DocumentSession.Load <Contato>(id); DocumentSession.Delete(contato); TempData["success"] = "Contato deletado com sucesso"; return(null); }
public Guid?Execute() { var @event = Mapper.Map <RecordedSpeedDeleted>(this); @event.DeletedByName = DocumentSession.Query <Person>().Single(a => a.Id == DeletedById).UserName; DocumentSession.Events.Append(Id, @event); DocumentSession.Delete <SpeedReadModel>(@event.Id); DocumentSession.SaveChanges(); return(null); }
public ActionResult ConfirmDelete(string id) { var productToDelete = DocumentSession.Load <Product>(id); if (productToDelete == null) { return(HttpNotFound()); } else { DocumentSession.Delete(id); DocumentSession.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult DeleteConfirmed(string id) { Roster roster = DocumentSession.Load <Roster>(id); if (roster == null) { throw new HttpException(404, "Roster not found"); } if (roster.MatchResultId != null) { throw new HttpException(400, "Can not delete registered rosters"); } DocumentSession.Delete(roster); return(RedirectToAction("Index")); }
/// <summary> /// Builder CarModule Class /// </summary> /// public CarModule() : base("/cars") { #region Method that returns the index View Car, with the registered Cars Get ["/"] = _ => { return(View ["index", DocumentSession.Query <Car> () .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region This method shows the data about a specified car Get ["/{Id}"] = x => { Guid carnumber = Guid.Parse(x.Id); var car = DocumentSession.Query <Car> ("CarsById") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Id == carnumber).FirstOrDefault(); if (car == null) { return(new NotFoundResponse()); } return(View ["show", car]); }; #endregion #region This method returns a New View to create a Default Car Get ["/new"] = x => { return(View ["new", Car.DefaultCar()]); }; #endregion #region This method creates a new Car Post ["/new"] = x => { var car = this.Bind <Car> (); var result = new CarValidator().Validate(car, ruleSet: "Update"); if (!result.IsValid) { return(View ["Shared/_errors", result]); } DocumentSession.Store(car); return(Response.AsRedirect(string.Format("/cars/{0}", car.Id))); }; #endregion #region Method that shows a view to edit a car Get ["/edit/{Id}"] = x => { Guid carnumber = Guid.Parse(x.Id); var car = DocumentSession.Query <Car> ("CarsById") .Where(n => n.Id == carnumber).FirstOrDefault(); if (car == null) { return(new NotFoundResponse()); } return(View ["edit", car]); }; #endregion #region Method that edits a Car by its ID Post ["/edit/{Id}"] = x => { var car = this.Bind <Car> (); var result = new CarValidator().Validate(car, ruleSet: "Update"); if (!result.IsValid) { return(View ["Shared/_errors", result]); } Guid carnumber = Guid.Parse(x.Id); var saved = DocumentSession.Query <Car> ("CarsById") .Where(n => n.Id == carnumber).FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(car); return(Response.AsRedirect(string.Format("/cars/{0}", car.Id))); }; #endregion #region This method deletes a car by its ID Delete ["/delete/{Id}"] = x => { Guid carnumber = Guid.Parse(x.Id); var car = DocumentSession.Query <Car> ("CarsById") .Where(n => n.Id == carnumber) .FirstOrDefault(); if (car == null) { return(new NotFoundResponse()); } DocumentSession.Delete(car); var resp = new JsonResponse <Car> ( car, new DefaultJsonSerializer() ); resp.StatusCode = HttpStatusCode.OK; return(resp); }; #endregion #region This method deletes a car by its ID Get ["/delete/{Id}"] = x => { Guid carnumber = Guid.Parse(x.Id); var car = DocumentSession.Query <Car> ("CarsById") .Where(n => n.Id == carnumber).FirstOrDefault(); if (car == null) { return(new NotFoundResponse()); } DocumentSession.Delete(car); return(Response.AsRedirect("/cars")); }; #endregion }
/// <summary> /// Builder DriveModule Class /// </summary> /// public DriverModule() : base("/drivers") { #region Method that returns the index View Course, with the registered Drivers Get["/"] = _ => { return(View["index", DocumentSession.Query <Driver>() .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Method that returns a View Show, displaying the driver in the form according to the ID. Get["/{Id}"] = x => { Guid driverId = Guid.Parse(x.Id); var driver = DocumentSession.Query <Driver>("DriverById") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Id == driverId).FirstOrDefault(); if (driver == null) { return(new NotFoundResponse()); } return(View["show", driver]); }; #endregion #region Method that returns the New View, creating a default driver Get["/new"] = x => { return(View["new", Driver.DefaultDriver()]); }; #endregion #region Method that creates and validates a new driver in accordance with the specifications of the class DriverValidator Post["/new"] = x => { var driver = this.Bind <Driver>(); var result = new DriverValidator().Validate(driver); if (!result.IsValid) { return(View["Shared/_errors", result]); } DocumentSession.Store(driver); return(Response.AsRedirect(string.Format("/drivers/{0}", driver.Id))); }; #endregion #region Displays data in the form of the Driver according to ID Get["/edit/{Id}"] = x => { Guid driverId = Guid.Parse(x.Id); var driver = DocumentSession.Query <Driver>("DriverById") .Where(n => n.Id == driverId).FirstOrDefault(); if (driver == null) { return(new NotFoundResponse()); } return(View["edit", driver]); }; #endregion #region Method editing the Driver according to ID Post["/edit/{Id}"] = x => { var driver = this.Bind <Driver>(); var result = new DriverValidator().Validate(driver, ruleSet: "Update"); if (!result.IsValid) { return(View["Shared/_errors", result]); } Guid driverId = Guid.Parse(x.Id); var saved = DocumentSession.Query <Driver>("DriverById") .Where(n => n.Id == driverId).FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(driver); return(Response.AsRedirect(string.Format("/drivers/{0}", driver.Id))); }; #endregion #region Method to delete a record according to ID Get["/delete/{Id}"] = x => { Guid driverId = Guid.Parse(x.Id); var driver = DocumentSession.Query <Driver>("DriverById") .Where(n => n.Id == driverId).FirstOrDefault(); if (driver == null) { return(new NotFoundResponse()); } DocumentSession.Delete(driver); return(Response.AsRedirect("/drivers")); }; #endregion }
private async Task <IHttpActionResult> Handle(GetRostersFromBitsMessage message) { WebsiteConfig websiteConfig = DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId); Log.Info($"Importing BITS season {websiteConfig.SeasonId} for {TenantConfiguration.FullTeamName} (ClubId={websiteConfig.ClubId})"); RosterSearchTerms.Result[] rosterSearchTerms = DocumentSession.Query <RosterSearchTerms.Result, RosterSearchTerms>() .Where(x => x.Season == websiteConfig.SeasonId) .Where(x => x.BitsMatchId != 0) .ProjectFromIndexFieldsInto <RosterSearchTerms.Result>() .ToArray(); Roster[] rosters = DocumentSession.Load <Roster>(rosterSearchTerms.Select(x => x.Id)); var foundMatchIds = new HashSet <int>(); // Team Log.Info($"Fetching teams"); TeamResult[] teams = await bitsClient.GetTeam(websiteConfig.ClubId, websiteConfig.SeasonId); foreach (TeamResult teamResult in teams) { // Division Log.Info($"Fetching divisions"); DivisionResult[] divisionResults = await bitsClient.GetDivisions(teamResult.TeamId, websiteConfig.SeasonId); // Match if (divisionResults.Length != 1) { throw new Exception($"Unexpected number of divisions: {divisionResults.Length}"); } DivisionResult divisionResult = divisionResults[0]; Log.Info($"Fetching match rounds"); MatchRound[] matchRounds = await bitsClient.GetMatchRounds(teamResult.TeamId, divisionResult.DivisionId, websiteConfig.SeasonId); var dict = matchRounds.ToDictionary(x => x.MatchId); foreach (int key in dict.Keys) { foundMatchIds.Add(key); } // update existing rosters foreach (Roster roster in rosters.Where(x => dict.ContainsKey(x.BitsMatchId))) { Log.Info($"Updating roster {roster.Id}"); MatchRound matchRound = dict[roster.BitsMatchId]; roster.OilPattern = OilPatternInformation.Create( matchRound.MatchOilPatternName, matchRound.MatchOilPatternId); roster.Date = matchRound.MatchDate.ToDateTime(matchRound.MatchTime); roster.Turn = matchRound.MatchRoundId; roster.MatchTimeChanged = matchRound.MatchStatus == 2; if (matchRound.HomeTeamClubId == websiteConfig.ClubId) { roster.Team = matchRound.MatchHomeTeamAlias; roster.TeamLevel = roster.Team.Substring(roster.Team.LastIndexOf(' ') + 1); roster.Opponent = matchRound.MatchAwayTeamAlias; } else if (matchRound.AwayTeamClubId == websiteConfig.ClubId) { roster.Team = matchRound.MatchAwayTeamAlias; roster.TeamLevel = roster.Team.Substring(roster.Team.LastIndexOf(' ') + 1); roster.Opponent = matchRound.MatchHomeTeamAlias; } else { throw new Exception($"Unknown clubs: {matchRound.HomeTeamClubId} {matchRound.AwayTeamClubId}"); } roster.Location = matchRound.MatchHallName; } // add missing rosters var existingMatchIds = new HashSet <int>(rosters.Select(x => x.BitsMatchId)); foreach (int matchId in dict.Keys.Where(x => existingMatchIds.Contains(x) == false)) { Log.Info($"Adding match {matchId}"); MatchRound matchRound = dict[matchId]; string team; string opponent; if (matchRound.HomeTeamClubId == websiteConfig.ClubId) { team = matchRound.MatchHomeTeamAlias; opponent = matchRound.MatchAwayTeamAlias; } else if (matchRound.AwayTeamClubId == websiteConfig.ClubId) { team = matchRound.MatchAwayTeamAlias; opponent = matchRound.MatchHomeTeamAlias; } else { throw new Exception($"Unknown clubs: {matchRound.HomeTeamClubId} {matchRound.AwayTeamClubId}"); } var roster = new Roster( matchRound.MatchSeason, matchRound.MatchRoundId, matchRound.MatchId, team, team.Substring(team.LastIndexOf(' ') + 1), matchRound.MatchHallName, opponent, matchRound.MatchDate.ToDateTime(matchRound.MatchTime), matchRound.MatchNbrOfPlayers == 4, OilPatternInformation.Create(matchRound.MatchOilPatternName, matchRound.MatchOilPatternId)) { MatchTimeChanged = matchRound.MatchStatus == 2 }; DocumentSession.Store(roster); } } // remove extraneous rosters Roster[] toRemove = rosters.Where(x => foundMatchIds.Contains(x.BitsMatchId) == false).ToArray(); if (toRemove.Any()) { string body = $"Rosters to remove: {string.Join(",", toRemove.Select(x => $"Id={x.Id} BitsMatchId={x.BitsMatchId}"))}"; Log.Info(body); foreach (Roster roster in toRemove) { DocumentSession.Delete(roster); } await Emails.SendAdminMail($"Removed rosters for {TenantConfiguration.FullTeamName}", body); } return(Ok()); }
/// <summary> /// Removes the first occurrence of a specific object from the collection. /// </summary> /// <returns> /// true if <paramref name="item"/> was successfully removed from the collection; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original Collection. /// </returns> /// <param name="item">The object to remove from the collection.</param> public bool Delete(T item) { DocumentSession.Delete(item); return(true); }
public DinnerModuleAuth() : base("/dinners") { this.RequiresAuthentication(); Get["/create"] = parameters => { Dinner dinner = new Dinner() { EventDate = DateTime.Now.AddDays(7) }; base.Page.Title = "Host a Nerd Dinner"; base.Model.Dinner = dinner; return(View["Create", base.Model]); }; Post["/create"] = parameters => { var dinner = this.Bind <Dinner>(); var result = this.Validate(dinner); if (result.IsValid) { UserIdentity nerd = (UserIdentity)this.Context.CurrentUser; dinner.HostedById = nerd.UserName; dinner.HostedBy = nerd.FriendlyName; RSVP rsvp = new RSVP(); rsvp.AttendeeNameId = nerd.UserName; rsvp.AttendeeName = nerd.FriendlyName; dinner.RSVPs = new List <RSVP>(); dinner.RSVPs.Add(rsvp); DocumentSession.Store(dinner); DocumentSession.SaveChanges(); return(this.Response.AsRedirect("/" + dinner.DinnerID)); } else { base.Page.Title = "Host a Nerd Dinner"; base.Model.Dinner = dinner; foreach (var item in result.Errors) { foreach (var member in item.MemberNames) { base.Page.Errors.Add(new ErrorModel() { Name = member, ErrorMessage = item.GetMessage(member) }); } } } return(View["Create", base.Model]); }; Get["/delete/" + Route.AnyIntAtLeastOnce("id")] = parameters => { Dinner dinner = DocumentSession.Load <Dinner>((int)parameters.id); if (dinner == null) { base.Page.Title = "Nerd Dinner Not Found"; return(View["NotFound", base.Model]); } if (!dinner.IsHostedBy(this.Context.CurrentUser.UserName)) { base.Page.Title = "You Don't Own This Dinner"; return(View["InvalidOwner", base.Model]); } base.Page.Title = "Delete Confirmation: " + dinner.Title; base.Model.Dinner = dinner; return(View["Delete", base.Model]); }; Post["/delete/" + Route.AnyIntAtLeastOnce("id")] = parameters => { Dinner dinner = DocumentSession.Load <Dinner>((int)parameters.id); if (dinner == null) { base.Page.Title = "Nerd Dinner Not Found"; return(View["NotFound", base.Model]); } if (!dinner.IsHostedBy(this.Context.CurrentUser.UserName)) { base.Page.Title = "You Don't Own This Dinner"; return(View["InvalidOwner", base.Model]); } DocumentSession.Delete(dinner); DocumentSession.SaveChanges(); base.Page.Title = "Deleted"; return(View["Deleted", base.Model]); }; Get["/edit" + Route.And() + Route.AnyIntAtLeastOnce("id")] = parameters => { Dinner dinner = DocumentSession.Load <Dinner>((int)parameters.id); if (dinner == null) { base.Page.Title = "Nerd Dinner Not Found"; return(View["NotFound", base.Model]); } if (!dinner.IsHostedBy(this.Context.CurrentUser.UserName)) { base.Page.Title = "You Don't Own This Dinner"; return(View["InvalidOwner", base.Model]); } base.Page.Title = "Edit: " + dinner.Title; base.Model.Dinner = dinner; return(View["Edit", base.Model]); }; Post["/edit" + Route.And() + Route.AnyIntAtLeastOnce("id")] = parameters => { Dinner dinner = DocumentSession.Load <Dinner>((int)parameters.id); if (!dinner.IsHostedBy(this.Context.CurrentUser.UserName)) { base.Page.Title = "You Don't Own This Dinner"; return(View["InvalidOwner", base.Model]); } this.BindTo(dinner); var result = this.Validate(dinner); if (!result.IsValid) { base.Page.Title = "Edit: " + dinner.Title; base.Model.Dinner = dinner; foreach (var item in result.Errors) { foreach (var member in item.MemberNames) { base.Page.Errors.Add(new ErrorModel() { Name = member, ErrorMessage = item.GetMessage(member) }); } } return(View["Edit", base.Model]); } DocumentSession.SaveChanges(); return(this.Response.AsRedirect("/" + dinner.DinnerID)); }; Get["/my"] = parameters => { string nerdName = this.Context.CurrentUser.UserName; var userDinners = DocumentSession.Query <Dinner, IndexMyDinners>() .Where(x => x.HostedById == nerdName || x.HostedBy == nerdName || x.RSVPs.Any(r => r.AttendeeNameId == nerdName || (r.AttendeeNameId == null && r.AttendeeName == nerdName))) .OrderBy(x => x.EventDate) .AsEnumerable(); base.Page.Title = "My Dinners"; base.Model.Dinners = userDinners; return(View["My", base.Model]); }; }
public UserModule() : base("/users") { #region Method that returns the index View User, with the registered Users Get ["/"] = _ => { return(View ["index", DocumentSession.Query <User> () .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Method that returns a View Show, displaying the User in the form according to the ID. Get ["/{Username}"] = x => { var username = (string)x.Username; var user = DocumentSession.Query <User> ("UsersByUsername") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Username == username).FirstOrDefault(); if (user == null) { return(new NotFoundResponse()); } return(View ["show", user]); }; #endregion #region Method that returns the New View, creating a default User Get ["/new"] = x => { return(View ["new", User.DefaultUser()]); }; #endregion #region Method that creates and validates a new User in accordance with the specifications of the class UserValidator Post ["/new"] = x => { var user = this.Bind <User> (); var result = new UserValidator().Validate(user); if (!result.IsValid) { return(View ["Shared/_errors", result]); } DocumentSession.Store(user); return(Response.AsRedirect(string.Format("/users/{0}", user.Username))); }; #endregion #region Displays data in the form of the User according to Username Get ["/edit/{Username}"] = x => { var username = (string)x.Username; var user = DocumentSession.Query <User> ("UsersByUsername") .Where(n => n.Username == username).FirstOrDefault(); if (user == null) { return(new NotFoundResponse()); } return(View ["edit", user]); }; #endregion #region Method editing the Memorandum according to Username Post ["/edit/{Username}"] = x => { var user = this.Bind <User> (); var result = new UserValidator().Validate(user, ruleSet: "Update"); if (!result.IsValid) { return(View ["Shared/_errors", result]); } var username = (string)x.Username; var saved = DocumentSession.Query <User> ("UsersByUsername") .Where(n => n.Username == username) .FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(user); return(Response.AsRedirect(string.Format("/users/{0}", user.Username))); }; #endregion #region Method to delete a record according to Username Delete ["/delete/{Username}"] = x => { var username = (string)x.Username; var user = DocumentSession.Query <User> ("UsersByUsername") .Where(n => n.Username == username) .FirstOrDefault(); if (user == null) { return(new NotFoundResponse()); } DocumentSession.Delete(user); var resp = new JsonResponse <User> ( user, new DefaultJsonSerializer() ); resp.StatusCode = HttpStatusCode.OK; return(resp); }; Get ["/delete/{Username}"] = x => { var username = (string)x.Username; var user = DocumentSession.Query <User> ("UsersByUsername") .Where(n => n.Username == username).FirstOrDefault(); if (user == null) { return(new NotFoundResponse()); } DocumentSession.Delete(user); return(Response.AsRedirect("/users")); }; #endregion }
public void DeleteEntity <T>(T entity) { DocumentSession.Delete(entity); }
/// <summary> /// Builder CourseModule Class. /// </summary> public CourseModule() : base("/courses") { #region Method that returns the index View Course, with the registered courses. Get ["/"] = _ => { return(View ["index", DocumentSession.Query <Course> () .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Method that returns a View Show, displaying the course in the form according to the ID. Get ["/{Id}"] = x => { Guid coursenumber = Guid.Parse(x.Id); var course = DocumentSession.Query <Course> ("CoursesById") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Id == coursenumber).FirstOrDefault(); if (course == null) { return(new NotFoundResponse()); } return(View ["show", course]); }; #endregion #region Method that returns the New View, creating a default course Get ["/new"] = x => { return(View ["new", Course.DefaultCourse()]); }; #endregion #region Method that creates and validates a new course in accordance with the specifications of the class CourseValidator Post ["/new"] = x => { var course = this.Bind <Course> (); var result = new CourseValidator().Validate(course); if (!result.IsValid) { return(View ["Shared/_errors", result]); } DocumentSession.Store(course); return(Response.AsRedirect(string.Format("/courses/{0}", course.Id))); }; #endregion #region Displays data in the form of the Course according to ID Get ["/edit/{Id}"] = x => { Guid coursenumber = Guid.Parse(x.Id); var course = DocumentSession.Query <Course> ("CoursesById") .Where(n => n.Id == coursenumber).FirstOrDefault(); if (course == null) { return(new NotFoundResponse()); } return(View ["edit", course]); }; #endregion #region Method editing the course according to ID Post ["/edit/{Id}"] = x => { var course = this.Bind <Course> (); var result = new CourseValidator().Validate(course, ruleSet: "Update"); if (!result.IsValid) { return(View ["Shared/_errors", result]); } Guid coursenumber = Guid.Parse(x.Id); var saved = DocumentSession.Query <Course> ("CoursesById") .Where(n => n.Id == coursenumber).FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(course); return(Response.AsRedirect(string.Format("/courses/{0}", course.Id))); }; #endregion #region Method to delete a record according to ID Delete ["/delete/{Id}"] = x => { Guid coursenumber = Guid.Parse(x.Id); var course = DocumentSession.Query <Course> ("CoursesById") .Where(n => n.Id == coursenumber) .FirstOrDefault(); if (course == null) { return(new NotFoundResponse()); } DocumentSession.Delete(course); var resp = new JsonResponse <Course> ( course, new DefaultJsonSerializer() ); resp.StatusCode = HttpStatusCode.OK; return(resp); }; Get ["/delete/{Id}"] = x => { Guid coursenumber = Guid.Parse(x.Id); var course = DocumentSession.Query <Course> ("CoursesById") .Where(n => n.Id == coursenumber).FirstOrDefault(); if (course == null) { return(new NotFoundResponse()); } DocumentSession.Delete(course); return(Response.AsRedirect("/courses")); }; #endregion Get["/select"] = _ => { return(View["select", DocumentSession.Query <Course>() .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; }
public MemorandumModule() : base("/memorandums") { #region Method that returns the index View Memorandum, with the registered Memorandum Get ["/"] = _ => { return(View ["index", DocumentSession.Query <Memorandum> () .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Method that returns a View Show, displaying the memorandum in the form according to the ID. Get ["/{Id}"] = x => { Guid memorandumnumber = Guid.Parse(x.Id); var memorandum = DocumentSession.Query <Memorandum> ("MemorandumById") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Id == memorandumnumber).FirstOrDefault(); if (memorandum == null) { return(new NotFoundResponse()); } return(View ["show", memorandum]); }; #endregion #region Method that returns the New View, creating a default Memorandum Get ["/new"] = x => { return(View ["new", Memorandum.DefaultMemorandum()]); }; #endregion #region Method that creates and validates a new memorandum in accordance with the specifications of the class MemorandumValidator Post ["/new"] = x => { var memorandum = this.Bind <Memorandum> (); var result = new MemorandumValidator().Validate(memorandum); if (!result.IsValid) { return(View ["Shared/_errors", result]); } DocumentSession.Store(memorandum); return(Response.AsRedirect(string.Format("/memorandums/{0}", memorandum.Id))); }; #endregion #region Displays data in the form of the Memorandum according to ID Get ["/edit/{Id}"] = x => { Guid memorandumsnumber = Guid.Parse(x.Id); var memorandum = DocumentSession.Query <Memorandum> ("MemorandumById") .Where(n => n.Id == memorandumsnumber).FirstOrDefault(); if (memorandum == null) { return(new NotFoundResponse()); } return(View ["edit", memorandum]); }; #endregion #region Method editing the Memorandum according to ID Post ["/edit/{Id}"] = x => { var memorandum = this.Bind <Memorandum>(); var result = new MemorandumValidator().Validate(memorandum, ruleSet: "Update"); if (!result.IsValid) { return(View ["Shared/_errors", result]); } Guid memorandumnumber = Guid.Parse(x.Id); var saved = DocumentSession.Query <Memorandum> ("MemorandumById") .Where(n => n.Id == memorandumnumber).FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(memorandum); return(Response.AsRedirect(string.Format("/memorandums/{0}", memorandum.Id))); }; #endregion #region Method to delete a record according to ID Get ["/delete/{Id}"] = x => { Guid memorandumnumber = Guid.Parse(x.Id); var memorandum = DocumentSession.Query <Memorandum> ("MemorandumById") .Where(n => n.Id == memorandumnumber).FirstOrDefault(); if (memorandum == null) { return(new NotFoundResponse()); } DocumentSession.Delete(memorandum); return(Response.AsRedirect("/memorandums")); }; #endregion }
public TravelModule() : base("/travels") { #region Method that returns the index View Travel, with the scheduled travels Get ["/"] = _ => { return(View ["index", DocumentSession.Query <Travel> () .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Method that returns a View Show, displaying the Travel. Get ["/{TravelTitle}"] = x => { var title = (string)x.TravelTitle; var travel = DocumentSession.Query <Travel> ("TravelByTitle") .Where(n => n.TravelTitle == title).FirstOrDefault(); if (travel == null) { return(new NotFoundResponse()); } return(View ["show", travel]); }; #endregion #region Method that returns the New View, creating a default Travel Get ["/new"] = x => { return(View ["new", Travel.DefaultTravel()]); }; #endregion #region Method that creates and validates a new Travel in accordance with the specifications of the class TravelValidator Post ["/new"] = x => { var travel = this.Bind <Travel> (); var result = new TravelValidator().Validate(travel); if (!result.IsValid) { return(View ["Shared/_errors", result]); } DocumentSession.Store(travel); return(Response.AsRedirect(string.Format("/travels/{0}", travel.TravelTitle))); }; #endregion #region Displays data in the form of the Travel according to TravelTitle Get ["/edit/{TravelTitle}"] = x => { var title = (string)x.TravelTitle; var travel = DocumentSession.Query <Travel> ("TravelByTitle") .Where(n => n.TravelTitle == title).FirstOrDefault(); if (travel == null) { return(new NotFoundResponse()); } return(View ["edit", travel]); }; #endregion #region Method editing the Memorandum according to TravelTitle Post ["/edit/{TravelTitle}"] = x => { var travel = this.Bind <Travel> (); var result = new TravelValidator().Validate(travel, ruleSet: "Update"); if (!result.IsValid) { return(View ["Shared/_errors", result]); } var title = (string)x.TravelTitle; var saved = DocumentSession.Query <Travel> ("TravelByTitle") .Where(n => n.TravelTitle == title) .FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(travel); return(Response.AsRedirect(string.Format("/travels/{0}", travel.TravelTitle))); }; #endregion #region Method to delete a record according to TravelTitle Delete ["/delete/{TravelTitle}"] = x => { var title = (string)x.TravelTitle; var travel = DocumentSession.Query <Travel> ("TravelByTitle") .Where(n => n.TravelTitle == title) .FirstOrDefault(); if (travel == null) { return(new NotFoundResponse()); } DocumentSession.Delete(travel); var resp = new JsonResponse <Travel> ( travel, new DefaultJsonSerializer() ); resp.StatusCode = HttpStatusCode.OK; return(resp); }; Get ["/delete/{TravelTitle}"] = x => { var title = (string)x.TravelTitle; var travel = DocumentSession.Query <Travel> ("TravelByTitle") .Where(n => n.TravelTitle == title).FirstOrDefault(); if (travel == null) { return(new NotFoundResponse()); } DocumentSession.Delete(travel); return(Response.AsRedirect("/travels")); }; #endregion }
public void RobTheBank(string storeFilename) { var swFull = new Stopwatch(); swFull.Start(); using (DocumentSession session = DocumentSessionFactory.Create(storeFilename)) { var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < EventCount; i++) { session.Store(i.ToString(), new NumericDocument { Number = i }); } sw.Stop(); Console.WriteLine("10k inserts: {0}ms", sw.ElapsedMilliseconds); } swFull.Stop(); Console.WriteLine("Spin up, insert, and shutdown: {0}ms", swFull.ElapsedMilliseconds); swFull.Reset(); swFull.Start(); using (DocumentSession session = DocumentSessionFactory.Create(storeFilename)) { var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < EventCount; i++) { var document = session.Retrieve <NumericDocument>(i.ToString()); Assert.That(document, Is.Not.Null, "Document not found for record {0}".FormatWith(i)); int result = document.Number; Assert.That(result, Is.EqualTo(i)); } sw.Stop(); Console.WriteLine("10k reads: {0}ms", sw.ElapsedMilliseconds); } swFull.Stop(); Console.WriteLine("Spin up, assert each, and shutdown: {0}ms", swFull.ElapsedMilliseconds); swFull.Reset(); swFull.Start(); using (DocumentSession session = DocumentSessionFactory.Create(storeFilename)) { var rand = new Random(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < EventCount / 100; i++) { string key = rand.Next(EventCount - 1).ToString(); session.Delete <NumericDocument>(key); } sw.Stop(); int count = session.List <NumericDocument>().Count(); Console.WriteLine("{1} (of {2} attempted) deletes: {0}ms", sw.ElapsedMilliseconds, EventCount - count, EventCount / 100); // at least one delete should have happened count.ShouldBeLessThan(EventCount - 1); } swFull.Stop(); Console.WriteLine("Spin up, delete, count, and shutdown: {0}ms", swFull.ElapsedMilliseconds); }
public virtual ActionResult Generate(string language, string version, string key, bool all) { if (DebugHelper.IsDebug() == false) { return(RedirectToAction(MVC.Docs.ActionNames.Index, MVC.Docs.Name)); } var versionsToParse = new List <string>(); if (all == false) { versionsToParse.Add(CurrentVersion); } var parser = new DocumentationParser( new ParserOptions { PathToDocumentationDirectory = GetDocumentationDirectory(), VersionsToParse = versionsToParse, RootUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")), ImagesUrl = GetImagesUrl(HttpContext, DocumentStore, ArticleType.Documentation) }, new NoOpGitFileInformationProvider()); DocumentSession.Delete(AttachmentsController.AttachmentsForDocumentationPrefix); var query = DocumentSession .Advanced .DocumentQuery <DocumentationPage>() .GetIndexQuery(); DocumentStore .Operations .Send(new DeleteByQueryOperation(query)) .WaitForCompletion(); query = DocumentSession .Advanced .DocumentQuery <TableOfContents>() .GetIndexQuery(); DocumentStore .Operations .Send(new DeleteByQueryOperation(query)) .WaitForCompletion(); DocumentSession.SaveChanges(); var toDispose = new List <IDisposable>(); var attachments = new HashSet <string>(StringComparer.OrdinalIgnoreCase); try { DocumentSession.Store(new Attachment(), AttachmentsController.AttachmentsForDocumentationPrefix); foreach (var page in parser.Parse()) { DocumentSession.Store(page); foreach (var image in page.Images) { var fileInfo = new FileInfo(image.ImagePath); if (fileInfo.Exists == false) { continue; } var file = fileInfo.OpenRead(); toDispose.Add(file); if (attachments.Add(image.ImageKey)) { DocumentSession.Advanced.Attachments.Store(AttachmentsController.AttachmentsForDocumentationPrefix, image.ImageKey, file, AttachmentsController.FileExtensionToContentTypeMapping[fileInfo.Extension]); } } } foreach (var toc in parser.GenerateTableOfContents()) { DocumentSession.Store(toc); } DocumentSession.SaveChanges(); } finally { foreach (var disposable in toDispose) { disposable?.Dispose(); } } if (string.IsNullOrEmpty(key)) { return(RedirectToAction(MVC.Docs.ActionNames.ArticlePage, MVC.Docs.Name, new { language = language, version = version })); } while (true) { var stats = DocumentStore.Maintenance.Send(new GetStatisticsOperation()); if (stats.StaleIndexes.Any() == false) { break; } Thread.Sleep(500); } return(RedirectToAction( MVC.Docs.ActionNames.ArticlePage, MVC.Docs.Name, new { language = CurrentLanguage, version = CurrentVersion, key = key })); }
public RenunciationModule() : base("/renunciations") { #region Get["/"] = _ => { return(View["index", DocumentSession.Query <Renunciation>() .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .ToList()]); }; #endregion #region Get["/{Id}"] = x => { Guid renunciationId = Guid.Parse(x.Id); var renunciation = DocumentSession.Query <Renunciation>("RenunciationById") .Customize(q => q.WaitForNonStaleResultsAsOfLastWrite()) .Where(n => n.Id == renunciationId).FirstOrDefault(); if (renunciation == null) { return(new NotFoundResponse()); } return(View["show", renunciation]); }; #endregion #region Get["/new"] = x => { return(View["new", Renunciation.DefaultRenunciation()]); }; #endregion #region Post["/new"] = x => { var renunciation = this.Bind <Renunciation>(); var result = new RenunciationValidator().Validate(renunciation); if (!result.IsValid) { return(View["Shared/_errors", result]); } DocumentSession.Store(renunciation); return(Response.AsRedirect(string.Format("/renunciations/{0}", renunciation.Id))); }; #endregion #region Get["/edit/{Id}"] = x => { Guid renunciationId = Guid.Parse(x.Id); var renunciation = DocumentSession.Query <Renunciation>("RenunciationById") .Where(n => n.Id == renunciationId).FirstOrDefault(); if (renunciation == null) { return(new NotFoundResponse()); } return(View["edit", renunciation]); }; #endregion #region Post["/edit/{Id}"] = x => { var renunciation = this.Bind <Renunciation>(); var result = new RenunciationValidator().Validate(renunciation, ruleSet: "Update"); if (!result.IsValid) { return(View["Shared/_errors", result]); } Guid renunciationId = Guid.Parse(x.Id); var saved = DocumentSession.Query <Renunciation>("RenunciationById") .Where(n => n.Id == renunciationId).FirstOrDefault(); if (saved == null) { return(new NotFoundResponse()); } saved.Fill(renunciation); return(Response.AsRedirect(string.Format("/renunciations/{0}", renunciation.Id))); }; #endregion #region Get["/delete/{Id}"] = x => { Guid renunciationId = Guid.Parse(x.Id); var renunciation = DocumentSession.Query <Renunciation>("RenunciationById") .Where(n => n.Id == renunciationId).FirstOrDefault(); if (renunciation == null) { return(new NotFoundResponse()); } DocumentSession.Delete(renunciation); return(Response.AsRedirect("/renunciations")); }; #endregion }