public async Task <Button> Apply(Guid buttonStateId, ISwitchSubsystemManager <SwitchEntity, SwitchEntity> switchRepo)
        {
            var buttonstate = await dbContext.ButtonStates.Include(i => i.SwitchSettings).Where(i => i.ButtonStateId == buttonStateId).FirstAsync();

            var switchIds = buttonstate.SwitchSettings.Select(i => i.SwitchId);
            var switches  = await dbContext.Switches.Where(i => switchIds.Contains(i.SwitchId)).ToListAsync();

            var switchInputs = switches.Select(i =>
            {
                var setting = buttonstate.SwitchSettings.Where(j => j.SwitchId == i.SwitchId).First();

                //Update the switch status on the entity
                i.Value      = setting.Value;
                i.HexColor   = setting.HexColor;
                i.Brightness = (byte?)setting.Brightness; //TODO: Fix this type

                return(i);
            });

            foreach (var item in switchInputs)
            {
                await switchRepo.Set(item);
            }

            //Save switch status updates
            await dbContext.SaveChangesAsync();

            //Reload button info
            var buttonState = await dbContext.ButtonStates.Include(i => i.Button).Where(i => i.ButtonStateId == buttonStateId).FirstAsync();

            return(mapper.MapButton(buttonState.Button, new Button()));
        }
示例#2
0
 public async Task <Button> Apply([FromBody] ApplyButtonInput input, [FromServices] IButtonStateRepository buttonStateRepo, [FromServices] ISwitchSubsystemManager <SwitchEntity, SwitchEntity> switchRepo)
 {
     return(await buttonStateRepo.Apply(input.ButtonStateId, switchRepo));
 }
示例#3
0
 public ButtonRepository(AppDbContext dbContext, AppMapper mapper, ISwitchSubsystemManager <SwitchEntity, SwitchEntity> switchRepo)
 {
     this.dbContext  = dbContext;
     this.mapper     = mapper;
     this.switchRepo = switchRepo;
 }
 public async Task <Button> Apply(Guid buttonStateId, [FromServices] ISwitchSubsystemManager <SwitchEntity, SwitchEntity> switchRepo)
 {
     return(await repo.Apply(buttonStateId, switchRepo));
 }