public async Task <IActionResult> Save([FromBody] NewPolicyViewModel viewModel) { var hasActivePoll = await _policyService.HasActivePoll(); if (hasActivePoll) { ModelState.AddModelError("", _localizer["HasActivePoll"]); return(BadRequest(Errors.GetErrorList(ModelState))); } var latestAuthorityPoll = await _pollService.GetLastPollOfType <AuthorityPoll>(); if (latestAuthorityPoll == null) { ModelState.AddModelError("", _localizer["CantStartPollBeforeAuthorityComplete"]); return(BadRequest(Errors.GetErrorList(ModelState))); } if (latestAuthorityPoll.Result == "Kararsız" || latestAuthorityPoll.Result == PollResults.Undecided.ToString()) { ModelState.AddModelError("", _localizer["CantStartPollBeforeAuthorityComplete"]); return(BadRequest(Errors.GetErrorList(ModelState))); } if (await _pollService.HasActivePollOfType <AuthorityPoll>()) { ModelState.AddModelError("", _localizer["AuthorityPollActivePollError"]); return(BadRequest(Errors.GetErrorList(ModelState))); } var userId = User.ApiGetUserId(); var policy = await _policyService.Add(new Policy { UserId = userId, TenantId = _tenantProvider.GetTenantId(), Body = viewModel.Body, Title = viewModel.Title, CreatedAt = DateTime.UtcNow, PolicyStatus = PolicyStatus.Voting }); var poll = await _pollViewModelService.NewPolicyChangePoll(new PolicyChangePollViewModel { UserId = userId, StartedBy = userId, Name = "Yönetmelik Değişim Oylaması", Description = viewModel.PollDescription, PolicyId = policy.Id }); await _pollService.NotifyUsers(poll.PollType, PollNotificationTypes.Started, poll); return(Ok(_mapper.Map <PolicyChangePoll, PolicyChangePollViewModel>(poll))); }
public async Task Should_Create_PolicyChangePoll() { var model = new PolicyChangePollViewModel { Description = "test desc", UserId = 1.ToString(), Name = "test" }; var poll = await _pollApiViewModelService.NewPolicyChangePoll(model); var result = _context.PolicyChangePolls.FirstOrDefault(a => a.Id == poll.Id); Assert.NotNull(result); Assert.Equal(model.Description, result.QuestionBody); Assert.Equal(model.UserId, result.UserId); Assert.Equal(model.Name, result.Name); }