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)); } }
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)); } }
// 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)); } }
public void Post([FromBody] PlayerViewModel playerViewModel) { _playerAppService.Add(playerViewModel); }
public override Task OnConnectedAsync() { _playerAppService.Add(Context.ConnectionId); return(base.OnConnectedAsync()); }