public void Handle(ChangeUserRoleCommand command) { using (var dbContext = new UserAccountDataContext()) { User user = dbContext.Users.SingleOrDefault(u => u.Id == command.UserId); if (user == null) { throw new ServerSideException("Ups, something went wrong! Refresh page and try agine"); } // TODO Check if user have league or team // if user have league or team then cant change role ChangeRole(user, command); dbContext.SaveChanges(); } }
public async Task Handle(ChangeUserRoleCommand command) { try { var user = await Repository.GetByKeyAsync<Domain.Models.User>(command.UserId); user.ChangeRole(command.Role); await Repository.SaveChangesAsync(); var @event = new UserRoleChangedEvent(command.UserId, command.Role); EventBus.RaiseEvent(@event); } catch (Exception ex) { var @event = new UserRoleNotChangedEvent(command.UserId, command.Role, ex.Message); EventBus.RaiseEvent(@event); throw; } }
private void ChangeRole(User user, ChangeUserRoleCommand command) { // TODO Check if user have league or team user.Role = (Role)command.Role; }
public ActionResult ChangeRole(ChangeUserRoleCommand command) { HandleCommand(command, Json("User role changed")); return(RedirectToAction("Index")); }
public async Task ChangeUserRoleAsync(ChangeUserRoleCommand command) { await _userRoleRepository.AddRangeAsync(command.RoleIds, command.UserId); }