public async Task <bool> Create(Account entity) { _context.Accounts.Add(entity); await _context.SaveChangesAsync(); return(true); }
//public async Task SaveCoins(string email,double coins) //{ // List<User> users = await _ctx.Users.ToListAsync(); // User user = _ctx.Users.FirstOrDefault(u => u.Email == email); // user.Coins = user.Coins + coins; // await _ctx.SaveChangesAsync(); //} public async Task SaveCoinsOnLoose(string email, double coins) { List <User> users = await _ctx.Users.ToListAsync(); User user = _ctx.Users.FirstOrDefault(u => u.Email == email); user.Coins = user.Coins - coins; await _ctx.SaveChangesAsync(); }
public async Task <ActionResult> ValidateEmail(string userId, string validationCode) { if (userId == null || validationCode == null) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } try { User user = await _userManager.GetUserByIdAsync(userId); if (user == null || validationCode != user.ValidationCode) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } user = UpdateUserEmailConfirmation(user); _ctx.Update(user); await _ctx.SaveChangesAsync(); } catch (Exception ex) { await _logger.LogCustomExceptionAsync(ex, null); return(RedirectToAction("Error", "Home")); } return(View("ConfirmEmail")); }
public async Task LogCustomExceptionAsync(Exception ex, string id = null) { CustomException exception = new CustomException(ex, id); _ctx.CustomExceptions.Add(exception); await _ctx.SaveChangesAsync(); }
public async Task <bool> Update(IEnumerable <AccountAdmin> currentAccountAdmins, IEnumerable <AccountAdmin> newAccountAdmins) { _context.Set <AccountAdmin>().RemoveRange(currentAccountAdmins.Except(newAccountAdmins, x => x.UserId)); _context.Set <AccountAdmin>().AddRange(newAccountAdmins.Except(currentAccountAdmins, x => x.UserId)); await _context.SaveChangesAsync(); return(true); }
public async Task AddCoinsByEmail(string email, double coinsToAdd) { List <User> users = await _ctx.Users.ToListAsync(); User user = _ctx.Users.FirstOrDefault(u => u.Email == email); user.Coins = user.Coins + coinsToAdd; await _ctx.SaveChangesAsync(); }
public async Task <bool> Update(IEnumerable <UserGate> currentGateUsers, IEnumerable <UserGate> newGateUsers) { _context.Set <UserGate>().RemoveRange(currentGateUsers.Except(newGateUsers, x => x.UserId)); _context.Set <UserGate>().AddRange(newGateUsers.Except(currentGateUsers, x => x.UserId)); await _context.SaveChangesAsync(); foreach (var newGateUser in newGateUsers) { var userGate = _context.UserGates.FirstOrDefault(x => x.UserId == newGateUser.UserId && x.GateId == newGateUser.GateId); userGate.AccessRight = newGateUser.AccessRight; userGate.AdminRight = newGateUser.AdminRight; userGate.ModifiedBy = newGateUser.ModifiedBy; userGate.MoidifiedAt = newGateUser.MoidifiedAt; _context.UserGates.Update(userGate); } await _context.SaveChangesAsync(); return(true); }
public async Task <User> CreateUser(string firstName, string lastName, string email, DateTime birth, string rfidKey) { if (_context.Users.Any(x => x.Email == email)) { throw new Exception("User already exist!"); } var newUser = new User { FirstName = firstName, LastName = lastName, Email = email, Birth = birth, IsActive = true, RfidKey = rfidKey, CreatedAt = DateTime.UtcNow, CreatedBy = "SYSTEM", RoleId = 1 }; var result = _context.Users.Add(newUser); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task RegisterAsync(User user) { await _ctx.Users.AddAsync(user); await _ctx.SaveChangesAsync(); }