public async Task <IActionResult> PutBooking(int id, Booking booking) { if (id != booking.Id) { return(BadRequest()); } var bookingToEdit = _context.Bookings.FirstOrDefault(x => x.Id == id); bookingToEdit.StartDate = booking.StartDate; bookingToEdit.EndDate = booking.EndDate; if (booking.ToolId != null && booking.ToolId != 0) { bookingToEdit.ToolId = booking.ToolId; } _context.Entry(bookingToEdit).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private async Task WhitelistWord() { WordToWhitelist = WordToWhitelist.Trim(); if (string.IsNullOrWhiteSpace(WordToWhitelist) || WordToWhitelist.Contains(" ")) { return; } var wluser = new WhitelistWord { Word = WordToWhitelist }; if (await _context.WhitelistWords.AnyAsync(u => u.Word.Equals(WordToWhitelist))) { return; } await _context.WhitelistWords.AddAsync(wluser); await _context.SaveChangesAsync(); WordToWhitelist = string.Empty; }
private async Task Whitelist(TwitchMessage twitchMessage) { var wluser = new WhitelistUser { TwitchId = twitchMessage.ChatMessage.UserId, Name = twitchMessage.Author, Channel = twitchMessage.Channel }; if (await _context.WhitelistUsers.AnyAsync(u => u.Channel.Equals(twitchMessage.Channel) && u.TwitchId.Equals(twitchMessage.ChatMessage.UserId))) { return; } await _context.WhitelistUsers.AddAsync(wluser); await _context.SaveChangesAsync(); _whitelistedUsers.Add(wluser); }