public void New_Player(SinglePlayerModel model, string username) { using (var ctx = new Context()) { Player player = new Player(); player.Name = model.Player.Name; player.Country = model.Player.Country; player.Sex = model.Sex ? "Ženski" : "Muški"; player.Date_of_birth = model.Player.Date_of_birth; player.Picture = model.Player.Picture; player.Sport = ctx.Sports.FirstOrDefault(u => u.ID == model.Player.Sport.ID); player.User = ctx.Users.FirstOrDefault(u => u.Username == username); ctx.Players.Add(player); ctx.SaveChanges(); if (model.Comment != null) { Player_comment commentDB = new Player_comment(); commentDB.Comment = model.Comment; commentDB.Active = true; commentDB.Date = DateTime.UtcNow; commentDB.Player = player; commentDB.User = ctx.Users.FirstOrDefault(u => u.Username == username); ctx.Player_comments.Add(commentDB); ctx.SaveChanges(); } } }
public SinglePlayerViewModel() { MazeCols = MVVM.Properties.Settings.Default.MazeCols; MazeRows = MVVM.Properties.Settings.Default.MazeRows; Algo = MVVM.Properties.Settings.Default.SearchAlgorithm; this.m = new SinglePlayerModel(); }
public void Add_comment(SinglePlayerModel model, string username) { using (var ctx = new Context()) { Player_comment commentDB = new Player_comment(); commentDB.Comment = model.Comment; commentDB.Active = true; commentDB.Date = DateTime.UtcNow; commentDB.Player = ctx.Players.Include("Sport").Include("User").FirstOrDefault(t => t.ID == model.Player.ID); commentDB.User = ctx.Users.FirstOrDefault(u => u.Username == username); ctx.Player_comments.Add(commentDB); ctx.SaveChanges(); } }
/// <summary> /// Starts this instance. /// </summary> public void Start() { string cmd = GetCommandFromMenu(); if (cmd == null) { return; } //MessageBox.Show(string.Format("Command to send: '{0}'", cmd)); try { Communicator com = new Communicator(ip, port); com.SendMessage(cmd); cmd = com.ReadMessage(); com.Dispose(); Message m = Message.FromJSON(cmd); if (m.MessageType != MessageType.CommandResult) { // received notification when not expecting it. return; } CommandResult res = CommandResult.FromJSON(m.Data); // filter unwanted commands if (res.Command != Command.Generate) { return; } if (!res.Success) { MessageBox.Show(res.Data); return; } Maze maze = Maze.FromJSON(res.Data); // successfully created a game. pass the handle to the GameModel and start. SinglePlayerModel model = new SinglePlayerModel(maze); SinglePlayerVM vm = new SinglePlayerVM(model); SinglePlayerView view = new SinglePlayerView(vm); view.ShowDialog(); }catch (Exception e) { MessageBox.Show("Error connecting to the server!", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } }
public ActionResult Index(SinglePlayerModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); var dal = new Player_services(); if (model.Comment != null) { dal.Add_comment(model, username); } return(RedirectToAction("Index", new { teamname = model.Player.ID })); }
/// <summary> /// Handles the Clicked event of the SinglePlayerBtn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void SinglePlayerBtn_Clicked(object sender, RoutedEventArgs e) { var location = this.PointToScreen(new Point(0, 0)); // create a singleplayer model and give it the server ISinglePlayerModel model = new SinglePlayerModel(server); // set up and launch the single player window SinglePlayer singlePlayer = new SinglePlayer(model, this); singlePlayer.Left = location.X; singlePlayer.Top = location.Y; this.player.Pause(); singlePlayer.Show(); this.Hide(); }
public void Edit_Player(SinglePlayerModel model) { using (var ctx = new Context()) { Player player = ctx.Players.Include("Sport").Include("User").Include("Player_comments").Include("Player_comments.User").FirstOrDefault(t => t.ID == model.Player.ID); player.Name = model.Player.Name; player.Country = model.Player.Country; player.Sex = model.Sex ? "Ženski" : "Muški"; player.Date_of_birth = model.Player.Date_of_birth; if (model.Player.Picture != null) { player.Picture = model.Player.Picture; } 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 Player_services(); SinglePlayerModel model = new SinglePlayerModel { Player = dal.Check_existing(id) }; return(View(model)); }
public ActionResult Edit(SinglePlayerModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); var dal = new Player_services(); if (model.Player.Name == null || model.Player.Country == null) { return(RedirectToAction("Edit", new { greska = "Popunite sve podatke o igraču!", id = model.Player.ID })); } MemoryStream target = new MemoryStream(); if (model.Image != null) { model.Image.InputStream.CopyTo(target); model.Player.Picture = target.ToArray(); } dal.Edit_Player(model); return(RedirectToAction("Index", new { id = model.Player.ID })); }
public ActionResult Add(SinglePlayerModel model) { if (Request.Cookies["user"] == null) { return(RedirectToAction("Login", "User")); } string username = Logged_username(); var dal = new Player_services(); if (model.Player.Name == null || model.Player.Country == null || model.Image == null) { return(RedirectToAction("Add", new { greska = "Popunite sve podatke o igraču!" })); } if (dal.Check_existing(model.Player.Name) != null) { return(RedirectToAction("Add", new { greska = "Igrač već postoji!" })); } MemoryStream target = new MemoryStream(); model.Image.InputStream.CopyTo(target); model.Player.Picture = target.ToArray(); dal.New_Player(model, username); return(RedirectToAction("Index", new { id = dal.Check_existing(model.Player.Name).ID })); }
public SinglePlayerViewModel(SinglePlayerModel spm) : base(spm) { }
/// <summary> /// Initializes a new instance of the <see cref="SinglePlayerViewModel"/> class. /// </summary> /// <param name="model">The model.</param> public SinglePlayerViewModel(PlayerModel model) : base(model) { this.model = model as SinglePlayerModel; this.model.MazeGenerated += GenMaze; }