コード例 #1
0
ファイル: GamesController.cs プロジェクト: Grigann/PopWeb
        /// <summary>
        /// Saves a new gaming session and creates a new game if necessary
        /// </summary>
        /// <param name="gameEntry">A game entry</param>
        /// <returns>A JSON representation of a timeline entry</returns>
        public JsonResult QuickSave(GameEntry gameEntry)
        {
            // Used to emulate a failure
            if (gameEntry.Developper == "FAIL") {
                throw new Exception("Une erreur");
            }

            GamingSession gamingSession;
            using (var uow = new UnitOfWork(true)) {
                var game = uow.Games.FindByTitle(gameEntry.Title) ??
                           new Game() { Title = gameEntry.Title, Developper = gameEntry.Developper };

                gamingSession = new GamingSession() {
                    Date = DateTime.ParseExact(gameEntry.EntryDate, "dd/MM/yyyy", null),
                    Note = gameEntry.Note };
                game.AddGamingSession(gamingSession);

                uow.Games.SaveOrUpdate(game);
                uow.Commit();
            }

            var timelineEntry = new TimelineEntry(gamingSession, this);
            return Json(timelineEntry);
        }
コード例 #2
0
ファイル: TimelineEntry.cs プロジェクト: Grigann/PopWeb
 /// <summary>
 /// Initializes the entry with a gaming session
 /// </summary>
 /// <param name="gamingSession">A gaming session</param>
 /// <param name="controller">A controller</param>
 private void Initialize(GamingSession gamingSession, Controller controller)
 {
     this.ViewUrl = controller.Url.Action("View", "Games", new { id = gamingSession.Game.Id });
     this.Title = EscapeString(gamingSession.Game.Title);
     this.Details = string.IsNullOrEmpty(gamingSession.Game.ReleaseDate)
             ? EscapeString(gamingSession.Game.Developper)
             : EscapeString(gamingSession.Game.Developper + ", " + gamingSession.Game.ReleaseDate);
     this.ImageUrl = string.IsNullOrEmpty(gamingSession.Game.CoverFileName)
             ? "/Content/images/no_cover.jpg"
             : "/Content/images/games/" + gamingSession.Game.MediumThumbName;
     this.ImageAlt = EscapeString("Couverture de " + gamingSession.Game.Title);
 }