public ActionResult Create(Storm.Business.ViewModels.PlayerViewModel model)
        {
            try
            {
                var validation = _playerAppService.Add(model);
                if (validation.IsValid)
                {
                    ViewBag.Success = validation.Message;
                }
                else
                {
                    foreach (var error in validation.Erros)
                    {
                        ModelState.AddModelError(string.Empty, error.Message);
                    }
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(model));
            }
        }
Esempio n. 2
0
 public IActionResult Add([FromBody] PlayerViewModel player)
 {
     try
     {
         var playerDomain = _mapper.Map <PlayerViewModel, Player>(player);
         var response     = _mapper.Map <Player, PlayerViewModel>(_playerAppService.Add(playerDomain));
         return(Ok(response));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 3
0
        // POST: api/Players
        public HttpResponseMessage Post([FromBody] PlayerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new HttpError("Invalid Player")));
            }

            try
            {
                var validation = _playerAppService.Add(model);
                if (validation.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, validation.ToJson()));
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest, new HttpError(validation.Erros.ToJson())));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Esempio n. 4
0
 public void Post([FromBody] PlayerViewModel playerViewModel)
 {
     _playerAppService.Add(playerViewModel);
 }
Esempio n. 5
0
 public override Task OnConnectedAsync()
 {
     _playerAppService.Add(Context.ConnectionId);
     return(base.OnConnectedAsync());
 }