public ActionResult Add(Venue venue) { if (!String.IsNullOrWhiteSpace(venue.Name)) { VenuesRepository VenuesRep = new VenuesRepository(); if (VenuesRep.GetAllVenues().Where(k => k.Name.ToLower() == venue.Name.ToLower()).Count() > 0) { ModelState.AddModelError("Name", "Stadium with the same name has already been registered"); } else { VenuesRep.Add(venue); VenuesRep.SaveChanges(); return(Redirect("/venues")); } } else { //No team entered ModelState.AddModelError("Name", "Please enter the correct name"); } return(View(venue)); }
// GET: Venues public ActionResult Index() { VenuesRepository VenuesRep = new VenuesRepository(); var myvenues = VenuesRep.GetAllVenues(); if (myvenues.Count() > 0) { ViewData["MyVenues"] = myvenues.OrderBy(k => k.Id); } return(View()); }
public ActionResult Add(Team team) { List <SelectListItem> venuelist = new List <SelectListItem>(); VenuesRepository VenuesRep = new VenuesRepository(); var myvenues = VenuesRep.GetAllVenues().OrderBy(k => k.Name); TeamsRepository teamsrep = new TeamsRepository(); //--- string fileName = Path.GetFileNameWithoutExtension(team.ImageUpload.FileName); // string extension = Path.GetExtension(team.ImageUpload.FileName); //fileName = fileName + DateTime.Now.ToString("yymmssff") + extension; // team.LogoUrl = "~/Content/images/" + fileName; // fileName = Path.Combine(Server.MapPath("~/Content/images/"), fileName); // team.ImageUpload.SaveAs(fileName); if (myvenues.Count() > 0) { foreach (Venue v in myvenues) { SelectListItem sli = new SelectListItem(); sli.Value = v.Id.ToString(); sli.Text = v.Name; venuelist.Add(sli); } } ViewData["Venues"] = venuelist; if (!String.IsNullOrWhiteSpace(team.Name)) { if (teamsrep.GetAllTeams().Where(k => k.Name.ToLower() == team.Name.ToLower()).Count() > 0) { ModelState.AddModelError("Name", "That team name is already in use"); } else { teamsrep.Add(team); teamsrep.SaveChanges(); return(Redirect("/teams")); } } else { //No team entered ModelState.AddModelError("Name", "Please enter team name"); } return(View(team)); }
public ActionResult Add() { List <SelectListItem> venuelist = new List <SelectListItem>(); VenuesRepository VenuesRep = new VenuesRepository(); var myvenues = VenuesRep.GetAllVenues().OrderByDescending(k => k.Id); if (myvenues.Count() > 0) { foreach (Venue v in myvenues) { SelectListItem sli = new SelectListItem(); sli.Value = v.Id.ToString(); sli.Text = v.Name; venuelist.Add(sli); } } ViewData["Venues"] = venuelist; return(View()); }
public ActionResult Add() { List <SelectListItem> teamlist = new List <SelectListItem>(); TeamsRepository TeamsRep = new TeamsRepository(); var myteams = TeamsRep.GetAllTeams().OrderBy(k => k.Name); if (myteams.Count() > 0) { foreach (Team t in myteams) { SelectListItem sli = new SelectListItem(); sli.Value = t.Id.ToString(); sli.Text = t.Name; teamlist.Add(sli); } } ViewData["Teams"] = teamlist; List <SelectListItem> venuelist = new List <SelectListItem>(); VenuesRepository VenuesRep = new VenuesRepository(); var myvenues = VenuesRep.GetAllVenues().OrderBy(k => k.Name); if (myvenues.Count() > 0) { foreach (Venue v in myvenues) { SelectListItem sli = new SelectListItem(); sli.Value = v.Id.ToString(); sli.Text = v.Name; venuelist.Add(sli); } } ViewData["Venues"] = venuelist; return(View()); }
public ActionResult Add(Fixture fixture) { List <SelectListItem> teamlist = new List <SelectListItem>(); TeamsRepository TeamsRep = new TeamsRepository(); var myteams = TeamsRep.GetAllTeams().OrderBy(k => k.Name); if (myteams.Count() > 0) { foreach (Team t in myteams) { SelectListItem sli = new SelectListItem(); sli.Value = t.Id.ToString(); sli.Text = t.Name; teamlist.Add(sli); } } ViewData["Teams"] = teamlist; List <SelectListItem> venuelist = new List <SelectListItem>(); VenuesRepository VenuesRep = new VenuesRepository(); var myvenues = VenuesRep.GetAllVenues().OrderBy(k => k.Name); if (myvenues.Count() > 0) { foreach (Venue v in myvenues) { SelectListItem sli = new SelectListItem(); sli.Value = v.Id.ToString(); sli.Text = v.Name; venuelist.Add(sli); } } ViewData["Venues"] = venuelist; FixturesRepository FixturesRep = new FixturesRepository(); if (fixture.TimeStamp > DateTime.Today) { if (fixture.TimeStamp != null) { if (fixture.HomeTeamId != fixture.AwayTeamId) { //if (teamsrep.GetAllTeams().Where(k => k.Name.ToLower() == team.Name.ToLower()).Count() > 0) if (FixturesRep.GetAllFixtures().Any(k => k.TimeStamp == fixture.TimeStamp && FixturesRep.GetAllFixtures().Any(s => s.VenueName == fixture.VenueName))) { ModelState.AddModelError("TimeStamp", "There is a match in this venue at this time, add valid fixture"); //FixturesRep.Add(fixture); //FixturesRep.SaveChanges(); //return Redirect("/fixtures"); } else { //ModelState.AddModelError("VenuedId", "There is a match at this venue at this time, add valid fixture"); FixturesRep.Add(fixture); FixturesRep.SaveChanges(); return(Redirect("/fixtures")); } } else { ModelState.AddModelError("HomeTeamId", "Please make sure that the teams are different for home and away sides"); ModelState.AddModelError("AwayTeamId", "Please make sure that the teams are different for home and away sides"); } } else { ModelState.AddModelError("TimeStamp", "Invalid date e.g. 20 November 2019"); } } else { ModelState.AddModelError("TimeStamp", "You can't add fixtures on the past, Enter a future date"); } return(View(fixture)); }