/// <summary> /// Creates the given model. /// </summary> /// <typeparam name="T">Type of Model</typeparam> /// <param name="model">Model to be added. Do not nest models, this should be one model at a time.</param> /// <param name="validatePermissions">Validates that the current user and current application have access to do this. Hooks and rules will typically have this as false.</param> /// <returns></returns> public T Create <T>(T model, bool validatePermissions = true) where T : Model { var logName = string.Format("for {0}", typeof(T).Name); this.Logger.AppendLine(string.Format("Create started {0}", logName)); if (validatePermissions && _securityContext == null) { throw new InvalidAccessTokenException(); } var sw = Stopwatch.StartNew(); var createHelper = new CreateHelper <T>(model, this, validatePermissions); createHelper.Execute(); sw.Stop(); this.Logger.AppendLine(string.Format("Create done {0}: {1} ms", logName, sw.ElapsedMilliseconds)); //wanted to call GetSingle here to refresh the model, but if permissions are set to not read, that's a problem. //If you can create this guy, surely you can read him back, so attach all the includes here return(this.GetModel <T>(model.Id)); }