コード例 #1
0
ファイル: HomeController.cs プロジェクト: KristinaTodd/really
 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));
     }
 }
コード例 #2
0
        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"));
            }
        }
コード例 #3
0
        public JsonResult Create(News data)
        {
            var result = service.Create(data);

            return(Json(result));
        }