Exemplo n.º 1
0
        /// <summary>
        /// Persists model obtained from POST by calling Save in the app scope, returning JSON result
        /// </summary>
        public async Task <object> SaveNew(PersistedModel <ChangeResult> model)
        {
            model.NonNull(nameof(model)).FormMode = FormMode.Insert;
            var saved = await App.InjectInto(model)
                        .SaveAsync();

            if (saved.IsSuccess)
            {
                return(saved.Result);
            }

            throw new BusinessException($"Could not save model `{model.GetType().Name}`: {saved.Error.ToMessageWithType()}", saved.Error);
        }
Exemplo n.º 2
0
        private async Task <object> save(PersistedModel <ChangeResult> model)
        {
            var saved = await App.InjectInto(model)
                        .SaveAsync().ConfigureAwait(false);

            if (saved.IsSuccess)
            {
                var change = saved.Result;

                WorkContext.Response.StatusCode        = change.HttpStatusCode;
                WorkContext.Response.StatusDescription = change.HttpStatusDescription;
                return(change);
            }

            throw new BusinessException($"Could not save model `{model.GetType().DisplayNameWithExpandedGenericArgs()}`" +
                                        $"in mode `{model.FormMode}`: {saved.Error.ToMessageWithType()}", saved.Error);
        }