예제 #1
0
        public async Task <IHttpActionResult> CreateMetaType(MetaType model)
        {
            try {
                if (!this.ValidateAlphanumericString(model.Name, 1000, true))
                {
                    return(this.ApiErrorResult(ApiErrorCode.InvalidMetaTypeName));
                }
                var fieldErrorCode = this.ValidateMetaTypeFieldNames(model.Fields);
                if (fieldErrorCode.HasValue)
                {
                    return(this.ApiErrorResult(fieldErrorCode.Value));
                }

                using (var session = Storage.GetAsyncSession()) {
                    await session.StoreAsync(model);

                    await session.SaveChangesAsync();

                    await model.CreateDefaultModelByMetaTypeIndexAsync();

                    return(this.Created(string.Empty, model));
                }
            }
            //todo: implement a better way to enforce unique names for meta types
            catch (ConcurrencyException e) {
                if (e.Message.ToLowerInvariant()
                    == string.Format("put attempted on document 'metatypes${0}' using a non current etag", model.Name.ToLowerInvariant()))
                {
                    return(this.ApiErrorResult
                               (ApiErrorCode.DuplicateMetaTypeName, "A MetaType with the name: {0} already exists", model.Name));
                }

                throw;
            }
        }
예제 #2
0
        protected virtual MetaType CreateMetaType(string name)
        {
            var metaType = new MetaType {
                Name = name
            };

            using (var session = Storage.GetAsyncSession()) {
                session.StoreAsync(metaType).Wait();
                session.SaveChangesAsync().Wait();
                metaType.CreateDefaultModelByMetaTypeIndexAsync().Wait();
            }
            return(metaType);
        }