public static TModel FromScheduledExercise <TModel>(ScheduledExercise scheduledExercise) where TModel : ScheduledExerciseApiModel, new() { var model = new TModel(); model.Id = scheduledExercise.Id; model.TenantId = scheduledExercise.TenantId; model.Name = scheduledExercise.Name; return(model); }
public async Task <Response> Handle(Request request) { var entity = await _context.ScheduledExercises .Include(x => x.Tenant) .SingleOrDefaultAsync(x => x.Id == request.ScheduledExercise.Id && x.Tenant.UniqueId == request.TenantUniqueId); if (entity == null) { var tenant = await _context.Tenants.SingleAsync(x => x.UniqueId == request.TenantUniqueId); _context.ScheduledExercises.Add(entity = new ScheduledExercise() { TenantId = tenant.Id }); } entity.Name = request.ScheduledExercise.Name; await _context.SaveChangesAsync(); _bus.Publish(new AddedOrUpdatedScheduledExerciseMessage(entity, request.CorrelationId, request.TenantUniqueId)); return(new Response()); }
public static ScheduledExerciseApiModel FromScheduledExercise(ScheduledExercise scheduledExercise) => FromScheduledExercise <ScheduledExerciseApiModel>(scheduledExercise);
public bool scheduleNewExercise(Int32 exerciseID, DateTime start, Int32 userID, bool notification) { bool rc = false; using (var context = new Layer2Container()) { LimitBreaker lb = context.LimitBreakers.Where(x => x.id == userID).FirstOrDefault(); if (lb != null) { List<scheduledItem> scheduledItemsForThatDay = new List<scheduledItem>(); ScheduledExercise newScheduledExercise = new ScheduledExercise(); //This part is for validating if the exercise can be scheduled for a certain time /* scheduledItemsForThatDay = getScheduledItemsByDay(userID, start); foreach (var item in scheduledItemsForThatDay) { if (item != null && start.AddHours(-1) <= item.startTime && start.AddHours(1) >= item.startTime) { return false; } } */ Exercise exercise = context.Exercises.Where(e => e.id == exerciseID).FirstOrDefault(); newScheduledExercise.Exercise = exercise; newScheduledExercise.startTime = start; newScheduledExercise.LimitBreakers = lb; newScheduledExercise.needEmailNotification = notification; context.ScheduledExercises.AddObject(newScheduledExercise); context.SaveChanges(); rc = true; } return rc; } }
public AddedOrUpdatedScheduledExerciseMessage(ScheduledExercise scheduledExercise, Guid correlationId, Guid tenantId) { Payload = new { Entity = scheduledExercise, CorrelationId = correlationId }; TenantUniqueId = tenantId; }