public ActionResult <object> Post([FromBody] UserViewModel user) { if (user == null) { var toSerialize = new MessageHelpers <UserViewModel>() { Status = 404, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } else { try { var id = _userServiceAsync.Add(user); var toSerialize = new MessageHelpers <UserViewModel>() { Status = 200, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } catch { var toSerialize = new MessageHelpers <UserViewModel>() { Status = 502, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } } }
public async Task <IActionResult> Create([FromBody] UserViewModel user) { if (user == null) { return(BadRequest()); } var id = await _userServiceAsync.Add(user); return(Created($"api/User/{id}", id)); //HTTP201 Resource created }
public async Task <IActionResult> Create([FromBody] UserPassViewModel user) { if (user == null) { return(BadRequest()); } try { var id = await _userServiceAsync.Add(user); return(Created($"api/User/{id}", id)); //HTTP201 Resource created } catch (Exception ex) { return(BadRequest(ex.Message)); } }