Exemplo n.º 1
0
        public T create(T model)
        {
            if (!policy.checkCreate(typeof(T)))
            {
                throw new UnauthorizedException("You do not have permission to create resources of type '" + typeof(T) + "'");
            }

            // adding timestamps
            this.beforeSave(model);
            var valueParams = this.transformer.getDbParams(model);

            valueParams.add(new DbParam("created_at", DateTime.Now.ToString(CultureInfo.InvariantCulture), SqlDbType.DateTime));
            valueParams.add(new DbParam("updated_at", DateTime.Now.ToString(CultureInfo.InvariantCulture), SqlDbType.DateTime));

            // updating
            var insertedId = DB.create(this.tableName, valueParams);
            var saved      = this.one(insertedId);

            this.afterSave(model, saved);

            return(saved);
        }