public async Task <IActionResult> Post([FromBody] AddDetailModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SubItemDetailModel subItemDetailModel = new SubItemDetailModel() { Name = model.Name, SubMenuItemId = model.MenuId }; var created = await repo.AddAsync(subItemDetailModel); return(Created("SubItemDetail", new AddDetailModel() { Id = created.Id, MenuId = created.SubMenuItemId, Name = created.Name })); }
public IActionResult Post([FromBody] AddDetailModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SubItemDetailModel subItemDetailModel = new SubItemDetailModel() { Name = model.Name, SubMenuItemId = model.MenuId }; var result = repo.Add(subItemDetailModel); if (result.IsSuccess) { return(Created("SubItemDetail", new AddDetailModel() { Id = result.Value.Id, MenuId = result.Value.SubMenuItemId, Name = result.Value.Name })); } return(BadRequest(result.Error)); }
public async Task <AddDetailModel> Add(AddDetailModel model, string token) { if (!_httpClient.DefaultRequestHeaders.Contains("Authorization") && !string.IsNullOrEmpty(token)) { _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); } var jsonData = JsonSerializer.Serialize(model); var modelJson = new StringContent(jsonData, Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("api/SubItemDetail/detail", modelJson); if (response.IsSuccessStatusCode) { var temp1 = await response.Content.ReadAsStreamAsync(); var temp = await JsonSerializer.DeserializeAsync <AddDetailModel>(temp1); return(temp); } return(null); }