public async Task <Result <Unit> > Handle(Commmand request, CancellationToken cancellationToken) { var activity = await _context.Activities .Include(a => a.Attendees) .ThenInclude(aa => aa.AppUser) .FirstOrDefaultAsync(a => a.Id == request.Id); var user = await _context.AppUsers.FirstOrDefaultAsync(x => x.UserName == _userAccessor.GetUsername()); if (user == null) { return(null); } var hostUsername = activity.Attendees.FirstOrDefault(x => x.IsHost)?.AppUser?.UserName; var attendance = activity.Attendees.FirstOrDefault(x => x.AppUser.UserName == user.UserName); if (attendance != null && hostUsername == user.UserName) { activity.IsCancelled = !activity.IsCancelled; } if (attendance != null && hostUsername != user.UserName) { activity.Attendees.Remove(attendance); } if (attendance == null) { attendance = new ActivityAttendee { AppUser = user, Activity = activity, IsHost = false }; activity.Attendees.Add(attendance); } var result = await _context.SaveChangesAsync() > 0; return(result ? Result <Unit> .Success(Unit.Value) : Result <Unit> .Failure("Problem updating activity")); }
/// <summary> /// Controls the motor direction/action /// </summary> /// <param name="command">The action</param> public virtual void Run(Commmand command) { if (command == Commmand.FORWARD) { _pca9685.SetPin(_in2, false); _pca9685.SetPin(_in1, true); } if (command == Commmand.BACKWARD) { _pca9685.SetPin(_in2, true); _pca9685.SetPin(_in1, false); } if (command == Commmand.RELEASE) { _pca9685.SetPin(_in1, false); _pca9685.SetPin(_in2, false); } }