Пример #1
0
        /// <summary>Convert from FormAttachment 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 FormAttachment DTO</returns>
        public FormAttachmentDto ToDtoDeep(FACTS.Framework.DAL.DbContext dbContext, FormAttachmentDto dto = null, Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto> entityDtos = null)
        {
            entityDtos = entityDtos ?? new Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto>();
            if (entityDtos.ContainsKey(this))
            {
                return((FormAttachmentDto)entityDtos[this]);
            }

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

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

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

            return(dto);
        }
Пример #2
0
        protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, FormAttachmentDto dto, FormAttachment entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities)
        {
            entity.CreateDateTime   = dto.CreateDateTime;
            entity.CreateUserId     = dto.CreateUserId;
            entity.DocumentId       = dto.DocumentId;
            entity.FormAttachmentId = dto.FormAttachmentId;
            entity.FormId           = dto.FormId;
            entity.UpdateDateTime   = dto.UpdateDateTime;
            entity.UpdateNumber     = dto.UpdateNumber;
            entity.UpdateProcess    = dto.UpdateProcess;
            entity.UpdateUserId     = dto.UpdateUserId;

            entity.Document = (dto.Document == null) ? null : Document.FromDto(dbContext, dto.Document, dtoEntities);
            entity.Form     = (dto.Form == null) ? null : Form.FromDto(dbContext, dto.Form, dtoEntities);
        }
Пример #3
0
        /// <summary>Convert from FormAttachment entity to DTO w/o checking entity state or entity navigation</summary>
        /// <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>
        /// <returns>Resultant FormAttachment DTO</returns>
        public FormAttachmentDto ToDto(FormAttachmentDto dto = null)
        {
            dto       = dto ?? new FormAttachmentDto();
            dto.IsNew = false;

            dto.CreateDateTime   = CreateDateTime;
            dto.CreateUserId     = CreateUserId;
            dto.DocumentId       = DocumentId;
            dto.FormAttachmentId = FormAttachmentId;
            dto.FormId           = FormId;
            dto.UpdateDateTime   = UpdateDateTime;
            dto.UpdateNumber     = UpdateNumber;
            dto.UpdateProcess    = UpdateProcess;
            dto.UpdateUserId     = UpdateUserId;

            return(dto);
        }
Пример #4
0
        /// <summary>Convert from FormAttachment 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 FormAttachment entity</returns>
        public static FormAttachment FromDto(FACTS.Framework.DAL.DbContext dbContext, FormAttachmentDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null)
        {
            dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>();
            if (dtoEntities.ContainsKey(dto))
            {
                return((FormAttachment)dtoEntities[dto]);
            }

            FormAttachment entity = new FormAttachment();

            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);
        }