예제 #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);
        }
예제 #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);
        }
예제 #3
0
 /// <summary>
 /// Persists model state obtained from DELETE by calling Save in the app scope, returning JSON result.
 /// This method can be used to logically delete items via call to PersistedModel.Save()
 /// </summary>
 public async Task <object> SaveDeleteAsync(PersistedModel <ChangeResult> model)
 {
     model.NonNull(nameof(model)).FormMode = FormMode.Delete;
     return(await save(model).ConfigureAwait(false));
 }