示例#1
0
        public ActionResult Post([FromBody] VoteViewModel vote)
        {
            if (vote == null)
            {
                return(BadRequest("Object to create is missing"));
            }
            if (vote.Feeling == null)
            {
                return(BadRequest("Feeling property missing"));
            }
            if (vote.Work == null)
            {
                return(BadRequest("Work property missing"));
            }

            var finalVote = Mapper.Map <Entities.Vote>(vote);

            _votesRepository.AddVote(finalVote);

            if (!_votesRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdVote = Mapper.Map <Models.VoteViewModel>(finalVote);

            return(Ok(finalVote));
        }