public ActionResult <Home> Post([FromBody] Home newHome) { try { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; newHome.UserId = userId; return(Ok(_hs.Create(newHome))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult Create(KeyValuesViewModel data) { HomeService service = new HomeService(); bool res = service.Create(data, out string errMsg); if (res) { var result = JsonConvert.SerializeObject(new { IsOk = true, Message = "儲存成功" }, new JsonSerializerSettings() { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); return(Content(result, "application/json")); } else { var result = JsonConvert.SerializeObject(new { IsOk = false, Message = "儲存失敗" + errMsg }, new JsonSerializerSettings() { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); return(Content(result, "application/json")); } }
public JsonResult Create(News data) { var result = service.Create(data); return(Json(result)); }