Ejemplo n.º 1
0
        /// <summary>
        /// Saves (or updates) the entity in the database.
        /// </summary>
        ///
        /// <param name="entity">
        /// Entity to save or update.
        /// </param>
        ///
        /// <param name="options">
        /// Optional options.
        /// </param>
        ///
        /// <returns>
        /// The number of affected rows.
        /// </returns>
        public override int Save(ref VahapYigit.Test.Models.UserRole entity, SaveOptions options = null)
        {
            ConditionChecker.Required(
                entity != null,
                new ArgumentNullException("entity"));

            if (options == null)
            {
                options = SaveOptions.Default;
            }

            int rowCount = 0;

            using (var scope = TransactionScopeHelper.CreateDefaultTransactionScope())
            {
                this.OnSaving(ref entity, options);

                if (options.SaveChildren)
                {
                    rowCount = this.PersistWithChildren(ref entity, new ObjectIDGenerator(), options);
                }
                else
                {
                    rowCount = this.Persist(ref entity, options);
                }

                this.OnSaved(ref entity, options);

                scope.Complete();
            }

            return(rowCount);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes the entity given its unique ID.
        /// </summary>
        ///
        /// <param name="id">
        /// Unique ID.
        /// </param>
        ///
        /// <returns>
        /// The number of affected rows.
        /// </returns>
        public override int Delete(long id)
        {
            int rowCount = 0;

            using (var et = new ExecutionTracerService())
                using (var scope = TransactionScopeHelper.CreateDefaultTransactionScope())
                {
                    this.OnDeleting(id);

                    var parameters = new Dictionary <string, object>();

                    parameters.Add("@UserRole_Id", id);

                    rowCount = base.ExecuteScalar <int>("UserRole_Delete", parameters);

                    this.OnDeleted(id);

                    scope.Complete();
                }

            return(rowCount);
        }