public async Task <IActionResult> Save(EditRepostScenarioViewModel model) { if (!ModelState.IsValid) { return(await Edit(model)); } var selectedGroup = _userHelperService.GetSelectedGroup(User); RepostScenarios newRepostScenario = null; if (model.Id.HasValue) { newRepostScenario = await _context.RepostScenarios.FirstOrDefaultAsync(x => x.Id == model.Id.Value); } if (newRepostScenario == null) { newRepostScenario = new RepostScenarios() { IsEnabled = true, DtCreate = DateTime.UtcNow }; await _context.RepostScenarios.AddAsync(newRepostScenario); } newRepostScenario.Name = model.Name; newRepostScenario.CheckAfterSeconds = model.CheckAfterHours * 60 * 60 + model.CheckAfterMinutes * 60; newRepostScenario.IdPost = model.CheckLastPosts ? null : model.IdPost; newRepostScenario.CheckAllPosts = model.CheckLastPosts ? model.CheckAllPosts : false; newRepostScenario.CheckLastPosts = model.CheckLastPosts; newRepostScenario.LastPostsCount = model.CheckLastPosts ? (model.CheckAllPosts ? null : model.LastPostsCount) : null; newRepostScenario.IdCheckingChainContent = model.IdCheckingChainContent.Value; newRepostScenario.IdGoToChain = model.IdGoToChain; newRepostScenario.IdGoToErrorChain1 = model.IdGoToErrorChain1; newRepostScenario.CheckIsSubscriber = model.CheckIsSubscriber; newRepostScenario.IdGoToErrorChain2 = model.CheckIsSubscriber ? model.IdGoToErrorChain2 : null; newRepostScenario.IdGoToErrorChain3 = model.CheckIsSubscriber ? model.IdGoToErrorChain3 : null; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Delete([FromQuery] Guid?idRepostScenario) { if (!idRepostScenario.HasValue) { return(NotFound(idRepostScenario)); } RepostScenarios removingRepostScenario = await _context.RepostScenarios.FirstOrDefaultAsync(x => x.Id == idRepostScenario.Value); if (removingRepostScenario == null) { return(NotFound(idRepostScenario)); } _context.CheckedSubscribersInRepostScenarios.RemoveRange(_context.CheckedSubscribersInRepostScenarios.Where(x => x.IdRepostScenario == idRepostScenario.Value)); _context.RepostScenarios.Remove(removingRepostScenario); await _context.SaveChangesAsync(); return(Ok()); }