/// <summary>
        /// Saves or updates the entity without its children.
        /// </summary>
        ///
        /// <param name="entity">
        /// Entity to save or update.
        /// </param>
        ///
        /// <param name="options">
        /// Optional options.
        /// </param>
        ///
        /// <returns>
        /// The number of affected rows.
        /// </returns>
        private int Persist(ref VahapYigit.Test.Models.ProcessErrorLog entity, SaveOptions options = null)
        {
            if (entity.State != VahapYigit.Test.Models.EntityState.ToInsert &&
                entity.State != VahapYigit.Test.Models.EntityState.ToUpdate)
            {
                return(0);
            }

            IList <TranslationEnum> errors;

            if (!entity.IsValid(out errors))
            {
                throw new EntityValidationException(errors);
            }

            int rowCount = 0;

            using (var et = new ExecutionTracerService(tag: entity.State.ToString()))
            {
                var parameters = new Dictionary <string, object>();

                parameters.Add("@ProcessErrorLog_Id", entity.Id);
                parameters.Add("@ProcessErrorLog_Date", entity.Date);
                parameters.Add("@ProcessErrorLog_ProcedureName", entity.ProcedureName);
                parameters.Add("@ProcessErrorLog_ErrorMessage", entity.ErrorMessage);
                parameters.Add("@ProcessErrorLog_ErrorSeverity", entity.ErrorSeverity);
                parameters.Add("@ProcessErrorLog_ErrorState", entity.ErrorState);
                parameters.Add("@ProcessErrorLog_Data", entity.Data);

                var collection = base.ToEntityCollection("ProcessErrorLog_Save", parameters, withDeepMapping: false);
                if (!collection.IsNullOrEmpty())
                {
                    entity.Map(collection[0]);
                    rowCount = 1;
                }

                return(rowCount);
            }
        }
예제 #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("@Translation_Id", id);

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

                    this.OnDeleted(id);

                    scope.Complete();
                }

            return(rowCount);
        }
예제 #3
0
        protected IDataReader ToDataReader(string procedure, IDictionary <string, object> parameters, out DbConnection connection)
        {
            IDataReader dbReader  = null;
            SqlCommand  dbCommand = null;

            try
            {
                connection = this.GetSqlConnection(true);
                dbCommand  = new SqlCommand();

                dbCommand.CommandType = CommandType.StoredProcedure;
                dbCommand.CommandText = procedure;

                dbCommand.Connection = (SqlConnection)connection;

                this.AddParameters(dbCommand, parameters);

                using (var et = new ExecutionTracerService(procedure))
                {
                    dbReader = dbCommand.ExecuteReader();
                }
            }
            catch (Exception x)
            {
                if (this.OperationError != null)
                {
                    this.OperationError(this, new CrudOperationErrorEventArgs(x, procedure, parameters));
                }

                throw;
            }
            finally
            {
                dbCommand.SafeDispose();
            }

            return(dbReader);
        }
예제 #4
0
        /// <summary>
        /// Saves or updates the entity without its children.
        /// </summary>
        ///
        /// <param name="entity">
        /// Entity to save or update.
        /// </param>
        ///
        /// <param name="options">
        /// Optional options.
        /// </param>
        ///
        /// <returns>
        /// The number of affected rows.
        /// </returns>
        private int Persist(ref VahapYigit.Test.Models.UserRole entity, SaveOptions options = null)
        {
            if (entity.State != VahapYigit.Test.Models.EntityState.ToInsert &&
                entity.State != VahapYigit.Test.Models.EntityState.ToUpdate)
            {
                return(0);
            }

            IList <TranslationEnum> errors;

            if (!entity.IsValid(out errors))
            {
                throw new EntityValidationException(errors);
            }

            int rowCount = 0;

            using (var et = new ExecutionTracerService(tag: entity.State.ToString()))
            {
                if (options.CheckUniqueConstraints)
                {
                    IList <TranslationEnum> ucErrors   = new List <TranslationEnum>();
                    SearchOptions           searchOpts = new SearchOptions();

                    searchOpts.Clear();

                    if (entity.State == VahapYigit.Test.Models.EntityState.ToUpdate)
                    {
                        searchOpts.Filters.Add(VahapYigit.Test.Models.UserRole.ColumnNames.Id, FilterOperator.Different, entity.Id);
                    }

                    searchOpts.Filters.Add(VahapYigit.Test.Models.UserRole.ColumnNames.IdUser, FilterOperator.Equals, entity.IdUser);
                    searchOpts.Filters.Add(VahapYigit.Test.Models.UserRole.ColumnNames.IdRole, FilterOperator.Equals, entity.IdRole);

                    if (this.HasResult(searchOpts))
                    {
                        ucErrors.Add(TranslationEnum.CrudUserRoleIdUser_IdRoleUniqueConstraint);
                    }

                    if (ucErrors.Count != 0)
                    {
                        throw new EntityValidationException(ucErrors);
                    }
                }

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

                parameters.Add("@UserRole_Id", entity.Id);
                parameters.Add("@UserRole_IdUser", entity.IdUser);
                parameters.Add("@UserRole_IdRole", entity.IdRole);

                var collection = base.ToEntityCollection("UserRole_Save", parameters, withDeepMapping: false);
                if (!collection.IsNullOrEmpty())
                {
                    entity.Map(collection[0]);
                    rowCount = 1;
                }

                return(rowCount);
            }
        }