Exemplo n.º 1
0
        public JsonResult Add([FromBody] CharactersModelView character)
        {
            if (CheckColors(character.Color, HttpContext.Response, out var result))
            {
                return(result);
            }

            var check = _repository.Exists(character.Id);

            if (check)
            {
                HttpContext.Response.StatusCode = StatusCodes.Status409Conflict;
                return(Json(new ErrorMessage("already exists")));
            }
            var res = _repository.Create(new Character(
                                             character.Id,
                                             character.Name,
                                             character.Color[0],
                                             character.Color[1],
                                             character.Color[2],
                                             character.Color[3]
                                             ));

            return(Json(new CharactersModelView(res)));
        }