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 <IActionResult> Add([FromBody] Policy policy)
        {
            if (policy == null)
            {
                return(BadRequest());
            }

            await _service.Add(policy);

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Policy> > Create([FromBody] Policy policy)
        {
            try
            { if (policy is null)
              {
                  throw new ArgumentNullException("wrong policy data received");
              }

              await _policyRepository.Add(policy);

              return(CreatedAtRoute("GetByPolicyNumber", new { policy.PolicyNumber }, policy)); }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.ToString()));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult Post([FromBody] List <PolicyDTO> data)
        {
            data = PolicyHttpApiController.GetCall().Result;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                List <PolicyDTO> clientsInserted =
                    iService.Add(data);
            }
            catch (Exception)
            {
                throw;
            }

            return(CreatedAtRoute("DefaultApi",
                                  new { id = data.First().Id }, data));
        }