public void CreateToken(ModelToken model, string username, int testid) { using (var transaction = _ctx.Database.BeginTransaction()) { try { model.TokenActive = true; model.TokenString = RandomString(); model.Username = username; model.TestID = testid; var entity = model.ToEntity(); _ctx.Insert(entity); _ctx.SaveChanges(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new ArgumentException(e.Message); } } }
public void CreateToken(ModelToken model, string[] usernames, int testid) { using (var transaction = _ctx.Database.BeginTransaction()) { try { model.TokenActive = true; model.TestID = testid; Each(usernames, x => { ModelToken check = GetTokenByUsernameAndTest(x, testid); if (check == null) { model.TokenString = RandomString(); model.Username = x; var entity = model.ToEntity(); _ctx.Insert(entity); _ctx.SaveChanges(); } }); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new ArgumentException(e.Message); } } }
public void CreateToken(ModelToken model) { using (var transaction = _ctx.Database.BeginTransaction()) { try { model.TokenActive = true; var entity = model.ToEntity(); _ctx.Insert(entity); _ctx.SaveChanges(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new ArgumentException(e.Message); } } }