Пример #1
0
        public Guid CreateVote(CreateVoteCommand command, string userId)
        {
            var vote = command.ToVote(userId);

            _context.Add(vote);
            _context.SaveChanges();

            return(vote.Id);
        }
Пример #2
0
        public async Task <IActionResult> Create(CreateVoteCommand command)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = await GetCurrentUserAsync();

                    var id = _voteService.CreateVote(command, user.Id);
                    return(RedirectToAction(nameof(Details), new { id = id }));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(View(command));
        }
Пример #3
0
 public async Task <IActionResult> Create(CreateVoteCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }