internal override void BeforeCreate(Data.Model.Occurrence entity, Data.Dto.Occurrence dto) { var schedule = entity.Schedule ?? Context.Schedules.FirstOrDefault(s => s.Id == entity.ScheduleId); entity.Date = entity.Date.LessSeconds(); var date = entity.Date; if (schedule.AsEarlyAsN.HasValue) { switch (schedule.AsEarlyAsFrequency) { case "Minute(s)": entity.AsEarlyAsDate = date.AddMinutes(-(double)schedule.AsEarlyAsN); break; case "Hour(s)": entity.AsEarlyAsDate = date.AddHours(-(double)schedule.AsEarlyAsN); break; case "Day(s)": entity.AsEarlyAsDate = date.AddDays(-(double)schedule.AsEarlyAsN); break; case "Week(s)": entity.AsEarlyAsDate = date.AddDays(-(double)(schedule.AsEarlyAsN * 7)); break; case "Month(s)": entity.AsEarlyAsDate = date.AddMonths(-schedule.AsEarlyAsN.Value); break; } } }
internal override async Task <EntityResult> AfterUpdateAsync(Data.Model.Occurrence entity, bool notifyAll = false) { await Context.Entry(entity).Reference(e => e.Asset).LoadAsync(); await Context.Entry(entity).Reference(e => e.User).LoadAsync(); await Context.Entry(entity).Reference(e => e.Task).LoadAsync(); await Context.Entry(entity).Reference(e => e.Schedule).LoadAsync(); var instance = TaskInstance.FromSchedule(entity.Task, entity.Date, entity.Schedule).MergeOccurrence(entity); SignalRHub.NotifyOccurrenceUpdate(ClientId, instance, entity.ToDto()); return(EntityResult.Succeded(0)); }