public async Task <bool> AddRepresentation(Representation representation)
        {
            using (var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false))
            {
                var result = true;
                try
                {
                    var record = new Model.Representation
                    {
                        Id           = representation.Id,
                        Created      = representation.Created,
                        LastModified = representation.LastModified,
                        ResourceType = representation.ResourceType,
                        Version      = representation.Version,
                        Attributes   = GetRepresentationAttributes(representation)
                    };
                    _context.Representations.Add(record);
                    await _context.SaveChangesAsync().ConfigureAwait(false);

                    transaction.Commit();
                }
                catch
                {
                    result = false;
                    transaction.Rollback();
                }

                return(result);
            }
        }
        private List <RepresentationAttribute> GetRepresentationAttributes(Model.Representation representation)
        {
            if (representation.Attributes == null)
            {
                return(new List <RepresentationAttribute>());
            }

            return(GetRepresentationAttributes(representation.Attributes));
        }
        public static Model.Representation SetData(this Model.Representation representation, Domain.Representation repr)
        {
            if (repr == null)
            {
                throw new ArgumentNullException(nameof(repr));
            }

            representation.Created      = repr.Created;
            representation.LastModified = repr.LastModified;
            representation.ResourceType = repr.ResourceType;
            representation.Version      = repr.Version;
            return(representation);
        }
        public static Domain.Representation ToDomain(this Model.Representation representation)
        {
            if (representation == null)
            {
                throw new ArgumentNullException(nameof(representation));
            }

            return(new Domain.Representation
            {
                Id = representation.Id,
                Created = representation.Created,
                LastModified = representation.Created,
                ResourceType = representation.ResourceType,
                Version = representation.Version
            });
        }
Exemple #5
0
        private List <RepresentationAttribute> GetRepresentationAttributes(Model.Representation representation)
        {
            if (representation.Attributes == null)
            {
                return(new List <RepresentationAttribute>());
            }

            var result = new List <RepresentationAttribute>();

            foreach (var attribute in representation.Attributes)
            {
                var transformed = _transformers.Transform(attribute);
                if (transformed == null)
                {
                    continue;
                }

                result.Add(transformed);
            }

            return(result);
        }