private bool NeedToStoreCalendarEvent(CalendarEvent @event) { var calendarEventStatuses = new CalendarEventStatuses(); var pendingStatuses = calendarEventStatuses.PendingForType(@event.Type); var actualStatuses = calendarEventStatuses.ActualForType(@event.Type); return(actualStatuses.Contains(@event.Status) && !pendingStatuses.Contains(@event.Status)); }
public void Apply(Schema model, SchemaFilterContext context) { model.Properties[nameof(CalendarEventsModel.Type).ToLower()].Enum = new List <object>(CalendarEventTypes.All); var statuses = new CalendarEventStatuses(); var possibleStatusValues = CalendarEventTypes.All.SelectMany(statuses.AllForType).Distinct().ToList <object>(); model.Properties[nameof(CalendarEventsModel.Status).ToLower()].Enum = possibleStatusValues; }
private static bool CheckIfRejected(CalendarEvent existingEvent, CalendarEventsModel updatedEvent, EmployeePermissionsEntry employeePermissions) { var calendarEventStatuses = new CalendarEventStatuses(); var rejected = calendarEventStatuses.RejectedForType(existingEvent.Type); var statusChanged = StatusChanged(existingEvent, updatedEvent); if (statusChanged && updatedEvent.Status == rejected) { return(employeePermissions.HasFlag(EmployeePermissionsEntry.RejectCalendarEvents)); } return(true); }
public IActionResult GetStatusesForType(string type) { var statuses = new CalendarEventStatuses().AllForType(type); if (statuses.Length != 0) { return(this.Ok(statuses)); } else { return(this.NotFound()); } }
private static bool CheckIfCancelled(CalendarEvent existingEvent, CalendarEventsModel updatedEvent, EmployeePermissionsEntry employeePermissions) { var calendarEventStatuses = new CalendarEventStatuses(); var approvedStatus = calendarEventStatuses.ApprovedForType(existingEvent.Type); var cancelledStatus = calendarEventStatuses.CancelledForType(updatedEvent.Type); var statusChanged = StatusChanged(existingEvent, updatedEvent); if (statusChanged && existingEvent.Status == approvedStatus && updatedEvent.Status == cancelledStatus) { return(employeePermissions.HasFlag(EmployeePermissionsEntry.CancelApprovedCalendarEvents)); } return(true); }
private CalendarEvent CompleteCalendarEvent(CalendarEvent @event, string completeBy, DateTimeOffset timestamp) { var approvedStatus = new CalendarEventStatuses().ApprovedForType(@event.Type); var newEvent = new CalendarEvent( @event.EventId, @event.Type, @event.Dates, approvedStatus, @event.EmployeeId ); this.UpdateCalendarEvent(@event, completeBy, timestamp, newEvent, ev => { }); return(newEvent); }
private async Task <CalendarEvent> CompleteVacation(CalendarEvent @event, string completeBy, DateTimeOffset timestamp) { var approvedStatus = new CalendarEventStatuses().ApprovedForType(@event.Type); var newEvent = new CalendarEvent( @event.EventId, @event.Type, @event.Dates, approvedStatus, @event.EmployeeId ); var updateMessage = new UpdateVacation(newEvent, @event, completeBy, timestamp); var updatedVacation = await this.UpdateVacation(updateMessage, false); return(updatedVacation); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var statuses = new CalendarEventStatuses(); switch (validationContext.ObjectInstance) { case CalendarEventsModel model when statuses.AllForType(model.Type).Contains(value): return(ValidationResult.Success); case CalendarEventsModel model: var validTypes = string.Join(", ", statuses.AllForType(model.Type)); return(new ValidationResult($"Calendar event status `{value}` is not recognized. Must be one of the {validTypes}")); default: return(new ValidationResult($"Attribute usage error: ValidationContext must be applied to {typeof(CalendarEventsModel)}")); } }
private UntypedReceive GatherCalendarEvents(IEnumerable <EmployeeContainer> subordinates) { var calendarActorsToRespond = new HashSet <IActorRef>(); foreach (var subordinate in subordinates) { subordinate.Calendar.CalendarActor.Tell(GetCalendarEvents.Instance); calendarActorsToRespond.Add(subordinate.Calendar.CalendarActor); } var eventsByEmployeeId = new Dictionary <string, IEnumerable <CalendarEvent> >(); var statuses = new CalendarEventStatuses(); void OnMessage(object message) { switch (message) { case GetCalendarEvents.Response response: var pendingEvents = response.Events.Where(x => x.IsPending).ToList(); if (pendingEvents.Count > 0) { eventsByEmployeeId[response.EmployeeId] = pendingEvents; } calendarActorsToRespond.Remove(this.Sender); if (calendarActorsToRespond.Count == 0) { this.FinishProcessing(eventsByEmployeeId); } break; default: this.DefaultMessageHandler(message); break; } } return(OnMessage); }