Example #1
0
        public async Task <IActionResult> Post([FromBody] WidgetModel widget)
        {
            if (widget == null || !ModelState.IsValid)
            {
                throw new ApiException("Model error encountered", HttpStatusCode.BadRequest, ModelState);
            }

            var result = await service.Create(widget.ToEntity(this.User.GetUserId()));

            return(Created(Url.Link(RouteConstants.WidgetSelfRoute, new { id = result.Id }), result));
        }
        public ActionResult Create(WidgetViewModelBase widget)
        {
            var currentUserId = User.Identity.GetUserId();

            widget.ApplicationUserId = currentUserId;
            try
            {
                if (!ModelState.IsValid)
                {
                    return(JsonHelper.JsonError(Resources.Global.UnvalidForm));
                }

                var addedSqlServer = _widgetService.Create(widget);
                return(Json(new { Result = "OK", Record = addedSqlServer, Message = Resources.Global.Success }));
            }
            catch (Exception ex)
            {
                return(JsonHelper.JsonError(ex.Message));
            }
        }