Beispiel #1
0
        public string Vote(DateTime date, string login, string restaurant)
        {
            VoteModel vModel = new VoteModel();
            Vote      vote   = new Vote(restaurant, date, login);

            try
            {
                vModel.Vote(vote);
            }catch (Exception except) { return(except.Message); }

            return("Voto inserido com sucesso!");
        }
        public async Task <IActionResult> CreateVote([FromBody] VoteModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new FailedResponse
                {
                    Errors = ModelState.Values.SelectMany(x => x.Errors.Select(e => e.ErrorMessage))
                }));
            }
            try
            {
                var vote = model.Vote();
                await _context.Votes.AddAsync(vote);

                await _context.SaveChangesAsync();

                return(Ok("Vote Posted"));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Operation Failed. Please Try agin !!"));
            }
        }