Exemplo n.º 1
0
        public async Task<ActionResult> AddSchedule([ModelBinder(typeof(DayOfWeekModelBinder))] DayOfWeek days)
        {
            var submitModel = new ScheduleSubmitModel{ Days = days };

            if (!this.TryUpdateModel(submitModel
                , new[]{"CheckForRain", "DeviceId", "Duration", "Hours", "Minutes", "Recurrence", "StartDate"}
                )
                )
            {
                return this.View("Add", submitModel);
            }

            var schedule = new Schedule
                               {
                                   CheckForRain = submitModel.CheckForRain,
                                   Days = submitModel.Recurrence ? submitModel.Days : null,
                                   DeviceId = submitModel.DeviceId,
                                   Duration = submitModel.Duration,
                                   Offset = new TimeSpan(submitModel.Hours, submitModel.Minutes, 0),
                                   Recurrence = submitModel.Recurrence,
                                   StartDate = submitModel.Recurrence ? null : submitModel.StartDate
                               };
            await this.scheduleCommandManager.AddScheduleAsync(this.HttpContext.User.Identity.GetUserId(), schedule);
            return this.RedirectToAction("Index", new { Id = schedule.Id, DeviceId = submitModel.DeviceId });
        }
        public async Task AddScheduleAsync(string personId, Schedule schedule)
        {
            var device = await this.deviceQueryManager.GetDeviceAsync(personId, schedule.DeviceId);

            var schedules = await this.scheduleQueryManager.GetSchedulesAsync(personId, device.Id);
            if (schedules.Any(x => x.StartDate == schedule.StartDate && x.Days == schedule.Days && x.Offset == schedule.Offset))
            {
                throw new ArgumentException("This device already has a schedule with the same trigger.");
            }

            schedule.DeviceId = device.Id;
            await this.scheduleCommandStore.AddScheduleAsync(schedule);
        }
Exemplo n.º 3
0
 public Task RemoveScheduleAsync(Schedule schedule)
 {
     this.databaseContext.Schedules.Attach(schedule);
     this.databaseContext.Schedules.Remove(schedule);
     return this.databaseContext.SaveChangesAsync();
 }
Exemplo n.º 4
0
 public Task AddScheduleAsync(Schedule schedule)
 {
     this.databaseContext.Schedules.Add(schedule);
     return this.databaseContext.SaveChangesAsync();
 }