public ActionResult Edit(SingleTeamModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); if (Set_TempData(username) == "user") { return(RedirectToAction("Racun", "User")); } var dal = new Team_services(); if (model.Team.Name == null || model.Team.Country == null || model.Team.Fans_Name == null || /*model.Team.Stadium == null ||*/ model.Team.Webpage == null) { return(RedirectToAction("Edit", new { greska = "Popunite sve podatke o klubu!", id = model.Team.ID })); } MemoryStream target = new MemoryStream(); if (model.Image != null) { model.Image.InputStream.CopyTo(target); model.Team.Emblem = target.ToArray(); } dal.Edit_Team(model); return(RedirectToAction("Index", new { id = model.Team.ID })); }
public ActionResult Add(SingleTeamModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); if (Set_TempData(username) == "user") { return(RedirectToAction("Racun", "User")); } var dal = new Team_services(); if (model.Team.Name == null || model.Team.Country == null || model.Image == null || model.Team.Fans_Name == null || /*model.Team.Stadium == null ||*/ model.Team.Webpage == null) { return(RedirectToAction("Add", new { greska = "Popunite sve podatke o klubu!" })); } if (dal.Check_existing(model.Team.Name) != null) { return(RedirectToAction("Add", new { greska = "Klub već postoji!" })); } MemoryStream target = new MemoryStream(); model.Image.InputStream.CopyTo(target); model.Team.Emblem = target.ToArray(); dal.New_Team(model, username); return(RedirectToAction("Index", new { id = dal.Check_existing(model.Team.Name).ID })); }
public ActionResult NewPlayer(SingleTeamModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } var dal = new Team_services(); dal.Add_Player(model); return(RedirectToAction("Index", new { id = model.Team.ID })); }
public void Add_Player(SingleTeamModel model) { using (var ctx = new Context()) { Team_player newPlayer = new Team_player(); newPlayer.Player = ctx.Players.FirstOrDefault(m => m.ID == model.Player); newPlayer.Team = ctx.Teams.FirstOrDefault(m => m.ID == model.Team.ID); newPlayer.Season = DateTime.Today.Year; ctx.Team_players.Add(newPlayer); ctx.SaveChanges(); } }
public void Add_comment(SingleTeamModel model, string username) { using (var ctx = new Context()) { Team_comment commentDB = new Team_comment(); commentDB.Comment = model.Comment; commentDB.Active = true; commentDB.Date = DateTime.UtcNow; commentDB.Team = ctx.Teams.Include("Sport").Include("User").FirstOrDefault(t => t.ID == model.Team.ID); commentDB.User = ctx.Users.FirstOrDefault(u => u.Username == username); ctx.Team_comments.Add(commentDB); ctx.SaveChanges(); } }
public ActionResult Index(SingleTeamModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); var dal = new Team_services(); if (model.Comment != null) { dal.Add_comment(model, username); } return(RedirectToAction("Index", new { teamname = model.Team.ID })); }
public ActionResult Edit(int id, string greska = "") { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); Set_TempData(username); TempData["Greska"] = greska; var dal = new Team_services(); SingleTeamModel model = new SingleTeamModel { Team = dal.Check_existing(id) }; return(View(model)); }
public void Edit_Team(SingleTeamModel model) { using (var ctx = new Context()) { Team team = ctx.Teams.Include("Sport").Include("User").Include("Team_comments").Include("Team_comments.User").FirstOrDefault(t => t.ID == model.Team.ID); team.Name = model.Team.Name; team.Country = model.Team.Country; team.Fans_Name = model.Team.Fans_Name; team.Founded = model.Team.Founded; //team.Stadium = model.Team.Stadium; if (model.Team.Emblem != null) { team.Emblem = model.Team.Emblem; } team.Webpage = model.Team.Webpage; ctx.SaveChanges(); } }
public ActionResult Index(int id) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); Set_TempData(username); var dal = new Team_services(); BindingList <Player> players = dal.Igraci(dal.Check_existing(id).Sport); ViewBag.Players = players; SingleTeamModel model = new SingleTeamModel { Team = dal.Check_existing(id) }; return(View(model)); }
public void New_Team(SingleTeamModel model, string username) { using (var ctx = new Context()) { Team team = new Team(); team.Name = model.Team.Name; team.Country = model.Team.Country; team.Fans_Name = model.Team.Fans_Name; team.Founded = model.Team.Founded; team.Emblem = model.Team.Emblem; team.Webpage = model.Team.Webpage; team.Sport = ctx.Sports.FirstOrDefault(u => u.ID == model.Team.Sport.ID); team.User = ctx.Users.FirstOrDefault(u => u.Username == username); ctx.Teams.Add(team); ctx.SaveChanges(); if (model.Comment != null) { Team_comment commentDB = new Team_comment(); commentDB.Comment = model.Comment; commentDB.Active = true; commentDB.Date = DateTime.UtcNow; commentDB.Team = team; commentDB.User = ctx.Users.FirstOrDefault(u => u.Username == username); ctx.Team_comments.Add(commentDB); ctx.SaveChanges(); } if (model.Stadiums != null) { foreach (var one in model.Stadiums) { Stadium stadium = ctx.Stadiums.FirstOrDefault(m => m.ID == one); stadium.Team = team; ctx.SaveChanges(); } } } }