public static async Task<ContentResult> Add(SocialGamificationAssetContext db, Match match, Actor actor) { // Add actors to this match var matchActor = new MatchActor { MatchId = match.Id, ActorId = actor.Id }; db.MatchActors.Add(matchActor); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError); } for (var i = 1; i <= match.TotalRounds; ++i) { // Add round(s) entry for each Actor var matchRound = new MatchRound { MatchActorId = matchActor.Id, RoundNumber = i }; db.MatchRounds.Add(matchRound); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError); } } return null; }
public static async Task <ContentResult> Add(SocialGamificationAssetContext db, Match match, Actor actor) { // Add actors to this match var matchActor = new MatchActor { MatchId = match.Id, ActorId = actor.Id }; db.MatchActors.Add(matchActor); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return(HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError)); } for (var i = 1; i <= match.TotalRounds; ++i) { // Add round(s) entry for each Actor var matchRound = new MatchRound { MatchActorId = matchActor.Id, RoundNumber = i }; db.MatchRounds.Add(matchRound); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { return(HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError)); } } return(null); }
protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { throw e; } }
/// <summary> /// Asynchronously save data /// </summary> /// <returns> /// <para> /// ErrorContentResult if /// <see cref="System.Data.Entity.Infrastructure.DbUpdateException" /> /// </para> /// <para>exception occurs</para> /// </returns> public static async Task <ContentResult> SaveChanges( SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { return(HttpResponseHelper.ErrorContentResult( GetExceptionString(e), StatusCodes.Status500InternalServerError)); } return(null); }
/// <summary> /// Asynchronously save data /// </summary> /// <returns> /// <para> /// ErrorContentResult if /// <see cref="System.Data.Entity.Infrastructure.DbUpdateException" /> /// </para> /// <para>exception occurs</para> /// </returns> public static async Task<ContentResult> SaveChanges( SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { return HttpResponseHelper.ErrorContentResult( GetExceptionString(e), StatusCodes.Status500InternalServerError); } return null; }
protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false) { try { if (isAsync) { await _context.SaveChangesAsync(); } else { _context.SaveChanges(); } } catch (DbUpdateException e) { throw e; } }