示例#1
0
        /// <summary>Convert from LookupValue DTO to entity</summary>
        /// <param name="dbContext">DB Context to use for attaching entity</param>
        /// <param name="dto">DTO to convert from</param>
        /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param>
        /// <returns>Resultant LookupValue entity</returns>
        public static LookupValue FromDto(FACTS.Framework.DAL.DbContext dbContext, LookupValueDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null)
        {
            dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>();
            if (dtoEntities.ContainsKey(dto))
            {
                return((LookupValue)dtoEntities[dto]);
            }

            LookupValue entity = new LookupValue();

            dtoEntities.Add(dto, entity);

            entity.Code           = dto.Code;
            entity.CreateDateTime = dto.CreateDateTime;
            entity.CreateUserId   = dto.CreateUserId;
            entity.Description    = dto.Description;
            entity.Name           = dto.Name;
            entity.Property       = dto.Property;
            entity.UpdateDateTime = dto.UpdateDateTime;
            entity.UpdateUserId   = dto.UpdateUserId;
            entity.Value          = dto.Value;

            entity.LookupCode     = (dto.LookupCode == null) ? null : LookupCode.FromDto(dbContext, dto.LookupCode, dtoEntities);
            entity.LookupProperty = (dto.LookupProperty == null) ? null : LookupProperty.FromDto(dbContext, dto.LookupProperty, dtoEntities);

            if (dbContext != null)
            {
                dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified));
            }

            return(entity);
        }
示例#2
0
        /// <summary>Convert from LookupValue entity to DTO</summary>
        /// <param name="dbContext">DB Context to use for setting DTO state</param>
        /// <param name="dto">DTO to use if already created instead of creating new one (can be inherited class instead as opposed to base class)</param>
        /// <param name="entityDtos">Used internally to track which entities have been converted to DTO's already (to avoid re-converting when circularly referenced)</param>
        /// <returns>Resultant LookupValue DTO</returns>
        public LookupValueDto ToDtoDeep(FACTS.Framework.DAL.DbContext dbContext, LookupValueDto dto = null, Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto> entityDtos = null)
        {
            entityDtos = entityDtos ?? new Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto>();
            if (entityDtos.ContainsKey(this))
            {
                return((LookupValueDto)entityDtos[this]);
            }

            dto = ToDto(dto);
            entityDtos.Add(this, dto);

            System.Data.Entity.Infrastructure.DbEntityEntry <LookupValue> entry = dbContext?.Entry(this);
            dto.IsNew     = (entry?.State == EntityState.Added);
            dto.IsDeleted = (entry?.State == EntityState.Deleted);

            if (entry?.Reference(x => x.LookupCode)?.IsLoaded == true)
            {
                dto.LookupCode = LookupCode?.ToDtoDeep(dbContext, entityDtos: entityDtos);
            }
            if (entry?.Reference(x => x.LookupProperty)?.IsLoaded == true)
            {
                dto.LookupProperty = LookupProperty?.ToDtoDeep(dbContext, entityDtos: entityDtos);
            }

            return(dto);
        }
示例#3
0
        protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, LookupValueDto dto, LookupValue entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities)
        {
            entity.Code           = dto.Code;
            entity.CreateDateTime = dto.CreateDateTime;
            entity.CreateUserId   = dto.CreateUserId;
            entity.Description    = dto.Description;
            entity.Name           = dto.Name;
            entity.Property       = dto.Property;
            entity.UpdateDateTime = dto.UpdateDateTime;
            entity.UpdateNumber   = dto.UpdateNumber;
            entity.UpdateProcess  = dto.UpdateProcess;
            entity.UpdateUserId   = dto.UpdateUserId;
            entity.Value          = dto.Value;

            entity.LookupCode     = (dto.LookupCode == null) ? null : LookupCode.FromDto(dbContext, dto.LookupCode, dtoEntities);
            entity.LookupProperty = (dto.LookupProperty == null) ? null : LookupProperty.FromDto(dbContext, dto.LookupProperty, dtoEntities);
        }
示例#4
0
        /// <summary>Convert from LookupCode DTO to entity</summary>
        /// <param name="dbContext">DB Context to use for attaching entity</param>
        /// <param name="dto">DTO to convert from</param>
        /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param>
        /// <returns>Resultant LookupCode entity</returns>
        public static LookupCode FromDto(FACTS.Framework.DAL.DbContext dbContext, LookupCodeDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null)
        {
            dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>();
            if (dtoEntities.ContainsKey(dto))
            {
                return((LookupCode)dtoEntities[dto]);
            }

            LookupCode entity = new LookupCode();

            dtoEntities.Add(dto, entity);
            FromDtoSet(dbContext, dto, entity, dtoEntities);

            if (dbContext != null)
            {
                dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified));
            }

            return(entity);
        }
示例#5
0
        /// <summary>Convert from LookupCode DTO to entity</summary>
        /// <param name="dbContext">DB Context to use for attaching entity</param>
        /// <param name="dto">DTO to convert from</param>
        /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param>
        /// <returns>Resultant LookupCode entity</returns>
        public static LookupCode FromDto(FACTS.Framework.DAL.DbContext dbContext, LookupCodeDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null)
        {
            dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>();
            if (dtoEntities.ContainsKey(dto))
            {
                return((LookupCode)dtoEntities[dto]);
            }

            LookupCode entity = new LookupCode();

            dtoEntities.Add(dto, entity);

            entity.Code           = dto.Code;
            entity.CreateDateTime = dto.CreateDateTime;
            entity.CreateUserId   = dto.CreateUserId;
            entity.Description    = dto.Description;
            entity.Display        = dto.Display;
            entity.Name           = dto.Name;
            entity.UpdateDateTime = dto.UpdateDateTime;
            entity.UpdateNumber   = dto.UpdateNumber;
            entity.UpdateProcess  = dto.UpdateProcess;
            entity.UpdateUserId   = dto.UpdateUserId;

            entity.LookupName = (dto.LookupName == null) ? null : LookupName.FromDto(dbContext, dto.LookupName, dtoEntities);
            if (dto.LookupValues != null)
            {
                foreach (LookupValueDto lookupValue in dto.LookupValues)
                {
                    entity.LookupValues.Add(DbEntities.LookupValue.FromDto(dbContext, lookupValue, dtoEntities));
                }
            }

            if (dbContext != null)
            {
                dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified));
            }

            return(entity);
        }
示例#6
0
        protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, LookupCodeDto dto, LookupCode entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities)
        {
            entity.Code           = dto.Code;
            entity.CreateDateTime = dto.CreateDateTime;
            entity.CreateUserId   = dto.CreateUserId;
            entity.Description    = dto.Description;
            entity.Display        = dto.Display;
            entity.Name           = dto.Name;
            entity.UpdateDateTime = dto.UpdateDateTime;
            entity.UpdateNumber   = dto.UpdateNumber;
            entity.UpdateProcess  = dto.UpdateProcess;
            entity.UpdateUserId   = dto.UpdateUserId;

            entity.LookupName = (dto.LookupName == null) ? null : LookupName.FromDto(dbContext, dto.LookupName, dtoEntities);
            if (dto.LookupValues != null)
            {
                foreach (LookupValueDto lookupValue in dto.LookupValues)
                {
                    entity.LookupValues.Add(DbEntities.LookupValue.FromDto(dbContext, lookupValue, dtoEntities));
                }
            }
        }