//删除产品 public IActionResult DeleteProduct() { var db = new EFContext(); //先删除数据 var deleteIds = Request.Query.ContainsKey("deleteIds") ? Request.Query["deleteIds"].ToString() : ""; if (!string.IsNullOrEmpty(deleteIds)) { var delete = db.Products.Where(u => deleteIds.Contains(u.ID + ",")); db.RemoveRange(delete); db.SaveChanges(); } var searchWord = ""; if (Request.Query.ContainsKey("searchWord")) { searchWord = Request.Query["searchWord"]; } var dbList = db.Products.Where(u => u.ProductTitle.Contains(searchWord)).OrderByDescending(u => u.ProductTitle).ToList(); var temp = new DeleteProductVm(); temp.SearchWord = searchWord; temp.Products = dbList; var requestUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}{HttpContext.Request.QueryString}"; temp.SignVm = WxCommonService.GetJsSignVm(requestUrl); temp.CurrentHost = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}"; return(View(temp)); }
public async Task ClearOldPosts() { //Get posts older than 2 days and other type than raids var Posts = await Queryable.Where(_db.ReactionPosts, item => item.Date < DateTime.Now.AddDays(-2) && item.Type == "Daily").ToListAsync(); if (Posts == null) { return; } //List for servers var servers = new List <IGuild>(); //Get the unique server ids var uniqueIds = Posts.GroupBy(item => item.ServerId).Select(winner => winner.First()).ToList(); //Get the servers via unique ids foreach (var server in uniqueIds) { servers.Add(_client.GetGuild(server.ServerId)); } foreach (var server in servers) { foreach (var message in Posts) { if (server.Id == message.ServerId) { try { //Get the message channel from the server var channel = await server.GetTextChannelAsync(message.ChannelId); //remove the message await channel.DeleteMessageAsync(message.Id); _logger.LogCritical($"[{message.Id}] removed from discord"); } catch (Exception e) { _logger.LogError(e.ToString()); } } } } _db.RemoveRange(Posts); await _db.SaveChangesAsync(); await AddEvent(EventType.ClearingOldPosts); _logger.LogInformation("Finished clearing the database from old posts"); }
public CGMessage SaveCard(Card inputCard) { CGMessage returnMessage = new(); try { Card card = _context.Cards.FirstOrDefault(c => c.Id.Equals(inputCard.Id)); if (card != null) { card.Name = inputCard.Name; // Set properties individually to register with EF, otherwise doesn't detect changes card.Description = inputCard.Description; card.Gold = inputCard.Gold; card.ReputationPoints = inputCard.ReputationPoints; card.Image = inputCard.Image; IQueryable <CardsWithRole> deleteCardWithRole = _context.CardsWithRoles.Where(cwr => cwr.CardId.Equals(card.Id)); // Only delete Cards with Roles if card already exists _context.RemoveRange(deleteCardWithRole); _context.SaveChanges(); } else { _context.Cards.Add(inputCard); _context.SaveChanges(); card = _context.Cards.FirstOrDefault(c => c.Id.Equals(inputCard.Id)); } if (inputCard.DefinedDice != null && card != null) { foreach (CardRole cr in inputCard.DefinedDice) // Add all the DefinedDice to join table { _context.CardsWithRoles.Add(new CardsWithRole() { CardId = card.Id, CardRoleId = cr.Id }); } _context.SaveChanges(); } else { _logger.Log(LogLevel.Error, $"{ClassName}.SaveCard; Defined Dice or Card is null. This is not right!!"); } return(GetCards()); } catch (Exception ex) { _logger.Log(LogLevel.Error, $"SaveCard; Error: {ex.Message}"); } return(returnMessage); }