Пример #1
0
        public static int GetCurrentUserId()
        {
            var    result   = IM.NullI;
            string userName = IM.ConnectedUser();

            var employeeRs = new IMRecordset(Employee.TableName, IMRecordset.Mode.ReadOnly);

            employeeRs.Select(Employee.Fields.Id);
            employeeRs.SetWhere(Employee.Fields.AppUser, IMRecordset.Operation.Eq, userName);

            using (employeeRs.OpenWithScope())
            {
                if (!employeeRs.IsEOF())
                {
                    result = employeeRs.GetI(Employee.Fields.Id);
                }
            }

            return(result);
        }
Пример #2
0
        public static T ReadFirstEntity <T>(Action <IMRecordset> conditionHandler)
            where T : class, IRepositoryEntity, IRepositoryReadedEntity, new()
        {
            var entity = new T();

            var entityDbName = entity.GetTableName();
            var fields       = entity.GetFieldNames();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadOnly);

            source.Select(fields);
            conditionHandler(source);
            using (source.OpenWithScope())
            {
                if (source.IsEOF())
                {
                    return(default(T));
                }

                entity.LoadFromRecordset(source);
            }

            return(entity);
        }
Пример #3
0
        public static void UpdateEntity <T>(T entity)
            where T : class, IRepositoryEntity, IRepositoryUpdatedEntity, new()
        {
            var entityDbName = entity.GetTableName();
            var idFieldName  = entity.GetIdFieldName();
            var fields       = entity.GetFieldNames();
            var id           = entity.GetId();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadWrite);

            source.Select(fields);
            source.SetWhere(idFieldName, IMRecordset.Operation.Eq, id.ToString());
            using (source.OpenWithScope())
            {
                if (source.IsEOF())
                {
                    throw new InvalidOperationException($"Not found a record of {entityDbName} by Id #{id}");
                }

                source.Edit();
                entity.SaveToRecordset(source);
                source.Update();
            }
        }
Пример #4
0
        public static T ReadEntityById <T>(int id)
            where T : class, IRepositoryEntity, IRepositoryReadedEntity, new()
        {
            var entity = new T();

            var entityDbName = entity.GetTableName();
            var idFieldName  = entity.GetIdFieldName();
            var fields       = entity.GetFieldNames();

            var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadOnly);

            source.Select(fields);
            source.SetWhere(idFieldName, IMRecordset.Operation.Eq, id.ToString());
            using (source.OpenWithScope())
            {
                if (source.IsEOF())
                {
                    throw new InvalidOperationException($"Not found a record of {entityDbName} by Id #{id}");
                }
                entity.LoadFromRecordset(source);
            }

            return(entity);
        }