public GolfClub GetNewGolfClubInfo() { ///example of isolation GolfClub gcv = new GolfClub(); int id, year; string name; float rating; Console.WriteLine("Enter Golf Club Id: "); id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Golf Club Name: "); name = Console.ReadLine(); Console.WriteLine("Enter Golf Club Year: "); year = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Golf Club Rating (1-5 stars): "); rating = float.Parse(Console.ReadLine()); gcv.Id = id; gcv.Name = name; gcv.Year = year; gcv.Rating = rating; return(gcv); }
public void DisplayGolfClub(GolfClub gcv) { Console.WriteLine(gcv.Id); Console.WriteLine(gcv.Name); Console.WriteLine(gcv.Year); Console.WriteLine(gcv.Rating); Console.WriteLine(" "); }
public async Task <IHttpActionResult> Put(string id, [FromBody] GolfClub entity) { await _repo.UpdateDocumentAsync(entity); var model = _repo.GetById(id); return(Ok(model)); }
public ActionResult DeleteConfirmed(int id) { GolfClub golfClub = db.GolfClubs.Find(id); db.GolfClubs.Remove(golfClub); db.SaveChanges(); return(RedirectToAction("Index")); }
public int ConfirmRemoveGolfClub(GolfClub gc) { int id; Console.WriteLine("Enter Golf Club ID you want to remove."); id = Convert.ToInt32(Console.ReadLine()); return(id); }
public async Task <IHttpActionResult> Post([FromBody] GolfClub entity) { var result = await _repo.CreateDocumentAsync(entity); var id = result.Resource.Id; var model = _repo.GetById(id); return(Ok(model)); }
private void FindByIDGolfClub() { // ask for id int id = gv.GetGolfClubId(); // display for matching id GolfClub club = gr.ReadById(id); gv.DisplayGolfClub(club); }
public ActionResult Edit([Bind(Include = "GolfClubId,Name,Country,Area,County,Postcode,WebSite,Email,ContactNo")] GolfClub golfClub) { if (ModelState.IsValid) { db.Entry(golfClub).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(golfClub)); }
public ActionResult Create([Bind(Include = "GolfClubId,Name,Country,Area,County,Postcode,WebSite,Email,ContactNo")] GolfClub golfClub) { if (ModelState.IsValid) { db.GolfClubs.Add(golfClub); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(golfClub)); }
private void EditGolfClub() { //ask for aid and store it in line 73 int id = gv.GetGolfClubId(); //take club and send to line 75 GolfClub club = gr.ReadById(id); //hold updated golfclubinfo club = gv.GetUpdatedGolfClubInfo(club); //then store the golfclubinfo gr.Update(id, club); }
public void Update(int id, GolfClub gc) { foreach (var club in golfClubs) { if (club.Id == id) { club.Id = gc.Id; club.Name = gc.Name; club.Year = gc.Year; club.Rating = gc.Rating; break; } } }
public GolfClub ReadById(int id) { GolfClub retval = new GolfClub(); foreach (var club in golfClubs) { if (club.Id == id) { retval = club; break; } } return(retval); }
// GET: GolfClubs/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GolfClub golfClub = db.GolfClubs.Find(id); if (golfClub == null) { return(HttpNotFound()); } return(View(golfClub)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } GolfClub = await _context.GolfClubs.FirstOrDefaultAsync(m => m.ID == id); if (GolfClub == null) { return(NotFound()); } return(Page()); }
public void ThenTheDetailsForAreShown(String golfClubName) { MockDatabaseDbContext context = this.MockDatabase; GolfClub golfClub = context.GolfClubs.Single(c => c.Name == golfClubName); AppResult golfClubNameLabel = this.App.WaitForElement(c => c.Marked("GolfClubName")).Single(); AppResult townLabel = this.App.WaitForElement(c => c.Marked("Town")).Single(); AppResult regionLabel = this.App.WaitForElement(c => c.Marked("Region")).Single(); AppResult postCodeLabel = this.App.WaitForElement(c => c.Marked("PostCode")).Single(); golfClubNameLabel.Text.ShouldBe(golfClub.Name); townLabel.Text.ShouldBe(golfClub.Town); regionLabel.Text.ShouldBe(golfClub.Region); postCodeLabel.Text.ShouldBe(golfClub.PostalCode); }
public async Task <IActionResult> RequestClubMembership([FromRoute] Guid playerId, [FromRoute] Guid golfClubId, CancellationToken cancellationToken) { List <KeyValuePair <String, StringValues> > headers = this.Request.Headers.ToList(); String authHeader = headers.Where(x => x.Key == "Authorization").Select(x => x.Value).SingleOrDefault().SingleOrDefault(); if (authHeader == null) { return(this.Unauthorized()); } using (MockDatabaseDbContext context = this.MockDatabaseDbContextResolver()) { Player player = context.Players.SingleOrDefault(p => p.PlayerId == playerId); if (player == null) { return(this.BadRequest()); } GolfClub golfClub = context.GolfClubs.SingleOrDefault(c => c.GolfClubId == golfClubId); if (golfClub == null) { return(this.BadRequest()); } GolfClubMembership membership = new GolfClubMembership { PlayerId = playerId, AcceptedDateTime = DateTime.Now, GolfClubId = golfClubId, GolfClubName = golfClub.Name, MembershipId = Guid.NewGuid(), PlayerDateOfBirth = player.DateOfBirth, PlayerFullName = $"{player.FirstName} {player.LastName}", PlayerGender = player.Gender, }; await context.GolfClubMemberships.AddAsync(membership, cancellationToken); await context.SaveChangesAsync(cancellationToken); } return(this.NoContent()); }
private void LoadSeedData(DocumentStore documentStore) { var urls = string.Join(", ", documentStore.Urls); using (var session = documentStore.OpenSession()){ if (!session.Advanced.LoadStartingWith <GolfClub>("GolfClubs").Any()) { var callawayRogue = new GolfClub { Type = ClubType.Driver, Make = "Callaway", Model = "Rogue", Loft = 10.5m, Shaft = new Shaft { Type = ShaftType.Graphite, Make = "Project X", Model = "HZRDUS Yellow", Flex = Flex.Stiff, Weight = 65 } }; var taylormadeM1 = new GolfClub { Type = ClubType.Driver, Make = "Taylormade", Model = "M1", Loft = 10.5m, Shaft = new Shaft { Type = ShaftType.Graphite, Make = "Aldila", Model = "Rogue Silver", Flex = Flex.Stiff, Weight = 65 } }; var clubs = new[] { callawayRogue, taylormadeM1 }; using (var bulkOperation = documentStore.BulkInsert()){ foreach (var club in clubs) { bulkOperation.Store(club); } } } } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } GolfClub = await _context.GolfClubs.FindAsync(id); if (GolfClub != null) { _context.GolfClubs.Remove(GolfClub); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public GolfClub GetUpdatedGolfClubInfo(GolfClub gcv) { int year; string name; float rating; Console.WriteLine("Enter Golf Club Name: "); name = Console.ReadLine(); Console.WriteLine("Enter Golf Club Year: "); year = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Golf Club Rating (1-5 stars): "); rating = float.Parse(Console.ReadLine()); gcv.Name = name; gcv.Year = year; gcv.Rating = rating; return(gcv); }
public GolfClubInformation SaveGolfClub([FromBody] GolfClubInformation golfClubToSave) { const string message = "Could not save golf club."; try { using (var context = new GolfTrackerContext()) { if (golfClubToSave.Id == Guid.Empty) { golfClubToSave.Id = Guid.NewGuid(); } var golfClub = context.GolfClub .Include("GolfCourses.Tees") .FirstOrDefault(c => c.Id == golfClubToSave.Id); if (golfClub == null) { golfClub = new GolfClub { Id = golfClubToSave.Id }; context.GolfClub.Add(golfClub); } mapInformationToEntity(golfClubToSave, golfClub, context); context.SaveChanges(); return(mapEntityToInformation(golfClub)); } } catch (Exception ex) { var exMessage = ExceptionHelper.ExceptionToString(ex, message); _logger.LogCritical(exMessage); return(null); } }
public void GivenTheFollowingGolfClubsAreRegistered(Table table) { MockDatabaseDbContext context = this.MockDatabase; List <GolfClub> golfClubsToRemove = context.GolfClubs.ToList(); context.RemoveRange(golfClubsToRemove); foreach (TableRow tableRow in table.Rows) { GolfClub golfClub = new GolfClub { GolfClubId = Guid.NewGuid(), Name = tableRow["GolfClubName"], Town = tableRow["Town"], Region = tableRow["Region"], PostalCode = tableRow["PostalCode"] }; context.GolfClubs.Add(golfClub); } context.SaveChanges(); }
private static GolfClubInformation mapEntityToInformation(GolfClub club) { var newClub = new GolfClubInformation { Id = club.Id, Name = club.Name, Location = club.Location, }; foreach (var course in club.GolfCourses) { var newCourse = new GolfCourseInformation { Id = course.Id, Name = course.Name, }; newClub.GolfCourses.Add(newCourse); foreach (var tee in course.Tees) { var newTee = new TeeInformation { Id = tee.Id, TeeName = tee.TeeName, Gender = tee.Gender, Length = tee.Length, Slope = tee.Slope, Rating = tee.Rating, Par = tee.Par, }; newCourse.Tees.Add(newTee); } } return(newClub); }
private void CreateGolfClub() { GolfClub gcc = gv.GetNewGolfClubInfo(); gr.Create(gcc); }
private static void mapInformationToEntity(GolfClubInformation golfClubToSave, GolfClub golfClub, GolfTrackerContext context) { golfClub.Name = golfClubToSave.Name; golfClub.Location = golfClubToSave.Location; foreach (var courseToSave in golfClubToSave.GolfCourses) { if (courseToSave.Id == Guid.Empty) { courseToSave.Id = Guid.NewGuid(); } var course = golfClub.GolfCourses .FirstOrDefault(c => c.Id == courseToSave.Id); if (course == null) { course = new GolfCourse { Id = courseToSave.Id }; golfClub.GolfCourses.Add(course); } course.GolfClubId = golfClub.Id; course.Name = courseToSave.Name; foreach (var teeToSave in courseToSave.Tees) { if (teeToSave.Id == Guid.Empty) { teeToSave.Id = Guid.NewGuid(); } var tee = course.Tees .FirstOrDefault(t => t.Id == teeToSave.Id); if (tee == null) { tee = new Tee { Id = teeToSave.Id }; course.Tees.Add(tee); } tee.GolfCourseId = course.Id; tee.TeeName = teeToSave.TeeName; tee.Gender = teeToSave.Gender; tee.Length = teeToSave.Length; tee.Par = teeToSave.Par; tee.Rating = teeToSave.Rating; tee.Slope = teeToSave.Slope; } //remove deleted tees; foreach (var tee in course.Tees) { if (!courseToSave.Tees.Any(t => t.Id == tee.Id)) { context.Entry(tee).State = EntityState.Deleted; } } } //remove deleted courses foreach (var course in golfClub.GolfCourses) { if (!golfClubToSave.GolfCourses.Any(c => c.Id == course.Id)) { context.Entry(course).State = EntityState.Deleted; } } }
public void Create(GolfClub gcr) { golfClubs.Add(gcr); }