public ActionResult Training(TrainingCriteria cc) { Player player = Player.GetPlayerByLogin(User.Identity.Name); if (cc.OpponentNumber <= 0) { return View(cc); } Player opponent = Player.GetPlayerById(cc.OpponentNumber); String[] hour = cc.Hour.ToString().Split(':'); DateTime date = (DateTime)cc.Date; DateTime dateOfPlay = new DateTime(date.Date.Year, date.Date.Month, date.Date.Day, int.Parse(hour[0]), int.Parse(hour[1]), 0); using (var db = new TennisOrganizerContext()) { db.Duels.Add(new Duel() { Accepted = false, GuestPlayerId = opponent.AccountId, HomePlayerId = player.AccountId, Seen = false, DateOfPlay = dateOfPlay }); db.SaveChanges(); try { Mailer.NotifyAboutChallenge(player.ToString(), opponent.Email, opponent.ToString()); } catch(FormatException e) { } TempData.Add("opponentName", Player.GetPlayerById(cc.OpponentNumber).ToString()); TempData.Add("dateOfPlay", cc.Date.ToShortDateString()); TempData.Add("hourOfPlay", cc.Hour); return RedirectToAction("TrainingSuccess", "Main"); } }
public ActionResult Training() { TrainingCriteria cc = new TrainingCriteria(); cc.SuitableOpponents = Trainer.GetTrainersList(); return View(cc); }