public ActionResult <object> Post([FromBody] EnigmaUsersViewModel user) { if (user == null) { var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 404, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } else { try { var id = _enigmaUsersServiceAsync.Add(user); var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 200, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } catch { var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 502, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } } }
public async Task <ActionResult <object> > PutAsync(int id, [FromBody] EnigmaUsersViewModel user) { if (user == null || user.Id != id) { var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 404, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } else { try { int retVal = await _enigmaUsersServiceAsync.Update(user); if (retVal == 0 && retVal > 0) { var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 200, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } else { var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 404, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } } catch { var toSerialize = new MessageHelpers <EnigmaUsersViewModel>() { Status = 502, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } } }