private void ApproveVacation(ApproveVacation message) { if (!this.eventsById.ContainsKey(message.Event.EventId)) { throw new Exception($"Vacation with id {message.Event.EventId} is not found"); } var calendarEvent = this.eventsById[message.Event.EventId]; var approvals = this.approvalsByEvent[message.Event.EventId]; if (approvals.Any(a => a.ApprovedBy == message.ApprovedBy)) { this.Sender.Tell(Abstractions.EmployeeVacations.ApproveVacation.Success.Instance); return; } this.Persist(new UserGrantedCalendarEventApproval { EventId = message.Event.EventId, TimeStamp = message.Timestamp, UserId = message.ApprovedBy }, ev => { this.OnSuccessfulApprove(ev); this.Sender.Tell(new ApproveVacation.Success(calendarEvent, approvals.ToList(), message.ApprovedBy, message.Timestamp)); }); }
private async Task <CalendarEventWithAdditionalData> ApproveVacation(ApproveVacation message) { var vacation = await this.GetVacation(message.Event.EmployeeId, message.Event.EventId); if (vacation == null) { throw new Exception($"Vacation with id {message.Event.EventId} is not found"); } var calendarEvent = vacation.CalendarEvent; var approvals = vacation.Approvals; if (approvals.Any(a => a.ApprovedBy == message.ApprovedBy)) { return(null); } await this.vacationsSyncExecutor.UpsertVacationApproval(calendarEvent, message.Timestamp, message.ApprovedBy); var newEvent = await this.GetVacation(calendarEvent.EmployeeId, calendarEvent.EventId); return(newEvent); }
private async Task <ApproveVacationSuccessData> GrantVacationApproval(ApproveVacation message) { this.EnsureApprovalAvailable(message.Event); var response = await this.vacationsRegistry.Ask <ApproveVacation.Response>(message); switch (response) { case ApproveVacation.Success success: string nextApprover = null; CalendarEvent newEvent = success.Event; if (success.Event != null) { nextApprover = await this.GetNextApproverId(success.Event, success.Approvals); if (nextApprover == null) { newEvent = await this.CompleteVacation(newEvent, message.ApprovedBy, message.Timestamp); } } return(new ApproveVacationSuccessData( newEvent, message.Event, success.Approvals, message.ApprovedBy, message.Timestamp, nextApprover)); case ApproveVacation.Error error: throw new Exception("Error occured on vacation approval granted", error.Exception); default: throw new Exception("Not expected response type"); } }