/// <summary> /// Add a Command to the Database /// </summary> /// <param name="AddModel"></param> public async void AddCommandAsync(Models.Commands.AddModel AddModel) { using (var context = new Core.Storage.StorageEntities()) { var commandEntry = context.Commands.SingleOrDefault(c => String.Compare(c.Command, AddModel.Command, true) == 0); // Command doesnt exist, create new if (commandEntry == null) { commandEntry = new Core.Storage.Commands { Command = AddModel.Command, CreatedAt = DateTime.Now, ModifiedAt = DateTime.Now, ExecutionRight = (int)AddModel.SelectedUserRight, Text = AddModel.Text, Cooldown = AddModel.Cooldown, Count = 0, }; context.Commands.Add(commandEntry); } else { // Command exists; update commandEntry.ExecutionRight = (int)AddModel.SelectedUserRight; commandEntry.ModifiedAt = DateTime.Now; commandEntry.Text = AddModel.Text; commandEntry.Cooldown = AddModel.Cooldown; } await context.SaveChangesAsync(); } // Load new CommandList LoadCommandList(); }
public async void AddTimerAsync(Models.Timers.AddModel model) { var timer = new Core.Storage.Timers { Active = model.Active, Autoreset = model.Autoreset, CreatedAt = DateTime.Now, Interval = model.Interval, Text = model.Text, Timer = model.Name }; using (var context = new Core.Storage.StorageEntities()) { context.Timers.Add(timer); await context.SaveChangesAsync(); } }