public virtual string GetMatchName(Boxer boxer) { //if names match then prefix their first inital if (NamesMatch()) { return string.Format("{0}. {1}", boxer.FirstName.Substring(0, 1), boxer.LastName); } return boxer.LastName; }
public ActionResult CreateAndSelectBoxer(Boxer NewBoxer) { //set boxers rankings NewBoxer.RankingPts = 0; //need to get weight id from page!!! NewBoxer.Weight = GetRepository<Weight>().Get(120); DataSession.Save(NewBoxer); return new JsonResult { Data = new { BoxerId = NewBoxer.Id, BoxerName = NewBoxer.FullName() } }; }
public BoxerSummary(Boxer boxer, string boxerUrl) { BoxerNameLink = boxer.NameLink; BoxerName = boxer.FullName(); BoxerNameReverse = boxer.FullNameReverse; Nationality = boxer.Nationality != null ? boxer.Nationality.Name : "N/A"; Weight = boxer.Weight.Name; Boxrec = boxer.Boxrec; Age = boxer.DateOfBirth != null ? boxer.GetAge().ToString() : "N/A"; BoxerUrl = boxerUrl.ToLowerInvariant(); Credentials = boxer.Credentials; BoxerId = boxer.Id; Rankingpts = boxer.RankingPts; InternalLink = boxer.FirstName.Replace(" ", "_") + "/" + boxer.LastName.Replace(" ", "_"); Match NextMatch = boxer.NextMatch(); if (NextMatch != null) { NextMatchDate = NextMatch.MatchDate.Value; NextMatchString = NextMatch.MatchString(boxer.Id); } Match LastMatch = boxer.LastMatch(); if (LastMatch != null) { LastMatchDate = LastMatch.MatchDate.Value; LastMatchString = LastMatch.MatchResultString(boxer.Id); if(LastMatch.Result.Winner == boxer){ LastMatchResult = "Won"; }else if(LastMatch.Result.Winner != null){ LastMatchResult = "Lost"; }else{ LastMatchResult = "Draw"; } } if (boxer.Record != null) { Record = boxer.Record.Won + "-" + boxer.Record.Lost; if (boxer.Record.Drawn > 0) { Record += "-" + boxer.Record.Drawn; } Record += " (" + boxer.Record.KO + ")"; } //Only here as getting only prospects fails remove after its works IsProspect = boxer.IsProspect.ToString(); }
public CreateBoxerViewModel(Boxer boxer, IEnumerable<Nationality> nationalityddl, IEnumerable<Weight> weightddl) { Weightddl = weightddl; Nationalityddl = nationalityddl; Boxer = boxer; //Make sure the page won't error when trying to view random boxers if (Boxer.Nationality == null) { try { Boxer.Nationality = nationalityddl.Where(x => x.Name == "Other").First(); } catch { Boxer.Nationality = nationalityddl.First(); } } if (Boxer.Record == null) Boxer.Record = new Record(); }
public virtual bool UpdateBoxer(Boxer NewBoxer, Record NewRecord) { try { FirstName = NewBoxer.FirstName; LastName = NewBoxer.LastName; DateOfBirth = NewBoxer.DateOfBirth; Weight = NewBoxer.Weight; Boxrec = NewBoxer.Boxrec; Credentials = NewBoxer.Credentials; Nationality = NewBoxer.Nationality; RankingPts = NewBoxer.RankingPts; if (Record == null) { Record = new Record(); Record.Boxer = this; } Record.UpdateBoxer(NewRecord); return true; } catch { return false; } }
public ActionResult CreateBoxer() { var Weightrepository = GetRepository<Weight>(); var allWeights = Weightrepository.All().ToArray(); var Nationalityrepository = GetRepository<Nationality>(); var allNationalities = Nationalityrepository.All().OrderBy(x => x.Name).ToArray(); var Boxer = new Boxer(); Boxer.Record = new Record(); Boxer.Weight = new Weight(); Boxer.Nationality = new Nationality(); return View(new CreateBoxerViewModel(Boxer,allNationalities,allWeights)); }
public ActionResult EditMatch(int id, int? GetBoxer_Dialog_Prospect_Id, int? GetBoxer_Dialog_Opponent_Id, int matchlength, DateTime matchdate, string Location, string Details, string Winner, string Type, string Round) { var Matchreppository = GetRepository<Match>(); var Boxerrepository = GetRepository<Boxer>(); var Opponent = new Boxer(); var Prospect = new Boxer(); //set prospect if have if (GetBoxer_Dialog_Prospect_Id != null) Prospect = Boxerrepository.Get((int)GetBoxer_Dialog_Prospect_Id); //set oppoent if have if (GetBoxer_Dialog_Opponent_Id != null) Opponent = Boxerrepository.Get((int)GetBoxer_Dialog_Opponent_Id); //get match Match dbmatch = Matchreppository.Get(id); //remove boxers dbmatch.Boxers.Clear(); //add boxers to match if we have them if (Prospect.Id > 0) dbmatch.Boxers.Add(Prospect); if (Opponent.Id > 0) dbmatch.Boxers.Add(Opponent); //Update db Match dbmatch.MatchDate = matchdate; dbmatch.Location = Location; dbmatch.Details = Details; dbmatch.Rounds = matchlength; //Now Detail with the result section of the Match var ResultTypeRep = GetRepository<ResultType>(); var MatchResultRep = GetRepository<MatchResult>(); bool IsValid = true; var matchResult = new MatchResult(); if (dbmatch.Boxers.Count() == 2) { if (Winner == "0") { //if draw set Result Type ONLY!!! matchResult.ResultType = ResultTypeRep.All().Where(x => x.Type == "Draw").Single(); } else if (Winner != string.Empty) { //if there is a result (not a draw) set the winner! if (Winner == "prospect" & Type != "") { matchResult.Winner = Prospect; } else if (Winner == "opponent" & Type != "") { matchResult.Winner = Opponent; } else { IsValid = false; } //Set the Type if (Type != "") matchResult.ResultType = ResultTypeRep.All().Where(x => x.Type == Type).Single(); //set the round if (Round != "") matchResult.Round = int.Parse(Round); } else { var MatchResult = MatchResultRep.Get(id); if (MatchResult != null) { MatchResultRep.Delete(MatchResult); } } } if(IsValid) { //If it has a result then remove it if (dbmatch.HasResult()) MatchResultRep.Delete(dbmatch.Result); DataSession.Save(dbmatch); //only add match if there is one! if (matchResult.ResultType != null) { matchResult.Match = dbmatch; DataSession.Save(matchResult); } } return Redirect("/ben/matches"); }
public ActionResult EditBoxer(Boxer boxer, Record record, int Id, int Nationality, int Weight, bool Prospect) { var Boxerreppository = GetRepository<Boxer>(); var Nationalityrep = GetRepository<Nationality>(); var Weightrep = GetRepository<Weight>(); var repRecord = GetRepository<Record>(); Boxer dbBoxer = Boxerreppository.Get(Id); boxer.Nationality = Nationalityrep.Get(Nationality); boxer.Weight = Weightrep.Get(Weight); //Add or remove the boxer depending on checkbox! if (Prospect & !dbBoxer.IsProspect) { var ProspectRep = GetRepository<Prospect>(); var prospect = new Prospect { Boxer = dbBoxer }; ProspectRep.Add(prospect); } else if (dbBoxer.IsProspect & !Prospect) { var ProspectRep = GetRepository<Prospect>(); ProspectRep.Delete(ProspectRep.Get(dbBoxer.Id)); } if (dbBoxer.UpdateBoxer(boxer, record) == true) { repRecord.Add(dbBoxer.Record); DataSession.Save(dbBoxer); } return Redirect("/ben"); }
public ActionResult CreateMatch(int[] prospect, string[] opponent, string[] matchdate, string[] location, int[] matchlength) { var repositoryBoxer = GetRepository<Boxer>(); var repositoryMatch = GetRepository<Match>(); int count = prospect.Count(); for (var i = 0; i < count; i++) { Match CreateMatch = new Match(); var GetProspect = repositoryBoxer.Get(prospect[i]); CreateMatch.Boxers.Add(GetProspect); //if not opponent then its a TBA match!!! if (opponent[i] != string.Empty) { Boxer GetOrCreateOpponent = repositoryBoxer.Query().GetByFullName(opponent[i]); if (GetOrCreateOpponent == null) { GetOrCreateOpponent = new Boxer(); //build new boxer string[] getname = opponent[i].Split('-'); GetOrCreateOpponent.FirstName = getname[0]; GetOrCreateOpponent.LastName = getname[1]; GetOrCreateOpponent.Weight = GetProspect.Weight; repositoryBoxer.Add(GetOrCreateOpponent); } CreateMatch.Boxers.Add(GetOrCreateOpponent); } CreateMatch.Rounds = matchlength[i]; CreateMatch.Location = location[i]; CreateMatch.MatchDate = DateTime.Parse(matchdate[i]); repositoryMatch.Add(CreateMatch); } return Redirect("/ben"); }
public ActionResult CreateBoxer(string FirstName, string LastName, string DateOfBirth, string Weight, string BoxRec, string Credentials, string Nationality, string RankingPts, string Won, string KO, string Lost, string Drawn, bool Prospect) { var repNationality = GetRepository<Nationality>(); var repWeight = GetRepository<Weight>(); var repBoxer = GetRepository<Boxer>(); var repRecord = GetRepository<Record>(); var repProspect = GetRepository<Prospect>(); var boxer = new Boxer { FirstName = FirstName, LastName = LastName, Boxrec = BoxRec, Credentials = Credentials != string.Empty ? Credentials : null, Weight = repWeight.Get(int.Parse(Weight)), Nationality = repNationality.Get(int.Parse(Nationality)), RankingPts = decimal.Parse(RankingPts) }; if (!string.IsNullOrEmpty(DateOfBirth)) boxer.DateOfBirth = DateTime.Parse(DateOfBirth); DataSession.Save(boxer); //Create boxers Record var record = new Record { Boxer = boxer, Won = int.Parse(Won), KO = int.Parse(KO), Lost = int.Parse(Lost), Drawn = int.Parse(Drawn) }; repRecord.Add(record); //Match Boxer a prospect if (Prospect) { var prospect = new Prospect { Boxer = boxer }; repProspect.Add(prospect); } return Redirect("/ben"); }