/// <summary> /// Create a new <see cref="Keybinding"/> from an existing database model. /// </summary> public Keybinding(ulong owner, AccountKeybindingModel model) { Owner = owner; InputActionId = model.InputActionId; DeviceEnum00 = model.DeviceEnum00; DeviceEnum01 = model.DeviceEnum01; DeviceEnum02 = model.DeviceEnum02; Code00 = model.Code00; Code01 = model.Code01; Code02 = model.Code02; MetaKeys00 = model.MetaKeys00; MetaKeys01 = model.MetaKeys01; MetaKeys02 = model.MetaKeys02; EventTypeEnum00 = model.EventTypeEnum00; EventTypeEnum01 = model.EventTypeEnum01; EventTypeEnum02 = model.EventTypeEnum02; }
public void Save(AuthContext context) { if ((saveMask & BindingSaveMask.Create) != 0) { var model = new AccountKeybindingModel { Id = (uint)Owner, InputActionId = InputActionId, DeviceEnum00 = DeviceEnum00, DeviceEnum01 = DeviceEnum01, DeviceEnum02 = DeviceEnum02, Code00 = Code00, Code01 = Code01, Code02 = Code02, MetaKeys00 = MetaKeys00, MetaKeys01 = MetaKeys01, MetaKeys02 = MetaKeys02, EventTypeEnum00 = EventTypeEnum00, EventTypeEnum01 = EventTypeEnum01, EventTypeEnum02 = EventTypeEnum02 }; context.Add(model); } else { var model = new AccountKeybindingModel { Id = (uint)Owner, InputActionId = InputActionId }; if ((saveMask & BindingSaveMask.Delete) != 0) { context.Entry(model).State = EntityState.Deleted; } else { EntityEntry <AccountKeybindingModel> entity = context.Attach(model); if ((saveMask & BindingSaveMask.DeviceEnum00) != 0) { model.DeviceEnum00 = DeviceEnum00; entity.Property(p => p.DeviceEnum00).IsModified = true; } if ((saveMask & BindingSaveMask.DeviceEnum01) != 0) { model.DeviceEnum01 = DeviceEnum01; entity.Property(p => p.DeviceEnum01).IsModified = true; } if ((saveMask & BindingSaveMask.DeviceEnum02) != 0) { model.DeviceEnum02 = DeviceEnum02; entity.Property(p => p.DeviceEnum02).IsModified = true; } if ((saveMask & BindingSaveMask.Code00) != 0) { model.Code00 = Code00; entity.Property(p => p.Code00).IsModified = true; } if ((saveMask & BindingSaveMask.Code01) != 0) { model.Code01 = Code01; entity.Property(p => p.Code01).IsModified = true; } if ((saveMask & BindingSaveMask.Code02) != 0) { model.Code02 = Code02; entity.Property(p => p.Code02).IsModified = true; } if ((saveMask & BindingSaveMask.MetaKeys00) != 0) { model.MetaKeys00 = MetaKeys00; entity.Property(p => p.MetaKeys00).IsModified = true; } if ((saveMask & BindingSaveMask.MetaKeys01) != 0) { model.MetaKeys01 = MetaKeys01; entity.Property(p => p.MetaKeys01).IsModified = true; } if ((saveMask & BindingSaveMask.MetaKeys02) != 0) { model.MetaKeys02 = MetaKeys02; entity.Property(p => p.MetaKeys02).IsModified = true; } if ((saveMask & BindingSaveMask.EventTypeEnum00) != 0) { model.EventTypeEnum00 = EventTypeEnum00; entity.Property(p => p.EventTypeEnum00).IsModified = true; } if ((saveMask & BindingSaveMask.EventTypeEnum01) != 0) { model.EventTypeEnum01 = EventTypeEnum01; entity.Property(p => p.EventTypeEnum01).IsModified = true; } if ((saveMask & BindingSaveMask.EventTypeEnum02) != 0) { model.EventTypeEnum02 = EventTypeEnum02; entity.Property(p => p.EventTypeEnum02).IsModified = true; } saveMask = BindingSaveMask.None; } } }