Ejemplo n.º 1
0
        public async Task <IHttpActionResult> VoteEdit(int voteId, CreateManaVote model)
        {
            if (model.Published)
            {
                model.PublishedDate = DateTime.UtcNow;
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var voteModel = model.ToModel();

            voteModel.Id = voteId;
            try
            {
                var updatedVote = await _store.UpdateVote(voteModel);

                var publishStateValid = await CheckAndPublish(updatedVote);

                if (!publishStateValid)
                {
                    return(BadRequest("Your changes have been saved but there was an issue publishing this vote."));
                }

                var response = new ManaVoteResponse(updatedVote);
                return(Ok(response));
            }
            catch (RecordNotFoundException)
            {
                return(NotFound());
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> VoteCreate(CreateManaVote model)
        {
            model.CreatedBy = User.Identity.GetUserId <int>();
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var voteModel = model.ToModel();

            if (voteModel.Published)
            {
                voteModel.PublishedDate = DateTime.UtcNow;
            }

            var vote = await _store.CreateVote(voteModel);

            var publishStateValid = await CheckAndPublish(vote);

            if (!publishStateValid)
            {
                return(BadRequest("Your changes have been saved but there was an issue publishing this vote."));
            }

            var response = new ManaVoteResponse(vote);

            return(Ok(response));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> VoteDetails(int voteId)
        {
            try
            {
                var vote = await _store.GetVoteById(voteId);

                var response = new ManaVoteResponse(vote);
                return(Ok(response));
            }
            catch (RecordNotFoundException)
            {
                return(NotFound());
            }
        }