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> Create(EditRepostScenarioViewModel model) { if (!_userHelperService.HasSelectedGroup(User)) { return(RedirectToAction(nameof(GroupsController.Index), "Groups")); } var selectedGroup = _userHelperService.GetSelectedGroup(User); ViewBag.Chains = await _context.Chains .Where(x => x.IdGroup == selectedGroup.Key) .ToDictionaryAsync(x => x.Id, x => x.Name); ViewBag.Posts = await _context.WallPosts .Where(x => x.IdGroup == selectedGroup.Key) .OrderByDescending(x => x.DtAdd) .ToDictionaryAsync(x => x.Id, x => $"{x.DtAdd.ToLocalTime():dd.MM.yyyy HH.mm}: {x.TextPart}"); return(View("Edit", model)); }
public async Task <IActionResult> Edit(EditRepostScenarioViewModel model) { var selectedGroup = _userHelperService.GetSelectedGroup(User); ViewBag.Chains = await _context.Chains .Where(x => x.IdGroup == selectedGroup.Key) .ToDictionaryAsync(x => x.Id, x => x.Name); if (model.IdCheckingChain.HasValue) { ViewBag.ChainContents = await _context.ChainContents .Where(x => x.IdChain == model.IdCheckingChain.Value) .Include(x => x.Message) .ToDictionaryAsync(x => x.Id, x => x.Message.TextPart); } ViewBag.Posts = await _context.WallPosts .Where(x => x.IdGroup == selectedGroup.Key) .OrderByDescending(x => x.DtAdd) .ToDictionaryAsync(x => x.Id, x => $"{x.DtAdd:dd.MM.yyyy HH.mm}: {x.TextPart}"); return(View("Edit", model)); }