public async Task <bool> Handle(RequestStatusChangeCommand message) { var req = new Request { RequestId = message.RequestId, Status = message.NewStatus }; _context.Requests.Attach(req); _context.Entry(req).Property(x => x.Status).IsModified = true; var changedCount = await _context.SaveChangesAsync(); return(changedCount > 0); }
public async Task <bool> Handle(AddTeamMemberCommand message) { var itinerary = await _context.Itineraries .Where(x => x.Id == message.ItineraryId) .Select(x => new { x.EventId, x.Date }) .SingleOrDefaultAsync() .ConfigureAwait(false); if (itinerary == null) { // todo: sgordon: enhance this with a error message so the controller can better respond to the issue return(false); } // We requery for potential team members in case something has changed or the task signup id was modified before posting var potentialTaskSignups = await _mediator.SendAsync(new PotentialItineraryTeamMembersQuery { EventId = itinerary.EventId, Date = itinerary.Date }) .ConfigureAwait(false); var matchedSignup = false; foreach (var signup in potentialTaskSignups) { var id = int.Parse(signup.Value); if (id == message.TaskSignupId) { matchedSignup = true; break; } } if (matchedSignup) { var taskSignup = new TaskSignup { Id = message.TaskSignupId, ItineraryId = message.ItineraryId }; _context.TaskSignups.Attach(taskSignup); _context.Entry(taskSignup).Property(x => x.ItineraryId).IsModified = true; await _context.SaveChangesAsync().ConfigureAwait(false); await _mediator .PublishAsync(new IntineraryVolunteerListUpdated { TaskSignupId = message.TaskSignupId, ItineraryId = message.ItineraryId, UpdateType = UpdateType.VolunteerAssigned }) .ConfigureAwait(false); } return(true); }