Exemple #1
0
        private Models.Image AddImage(Image entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var sEntity     = entity.ToPersistentEntity();
            var insertedRow = context.Images.Add(sEntity);

            context.SaveChanges();
            return(insertedRow);
        }
        public IArticle Add(Domain.Models.Article entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            //context.Sources.Attach((Source)entity.Source);

            var tagIds = entity.Tags != null
                ? entity.Tags.Select(x => x.Id)
                : new List <int>();

            var sEntity = entity.ToPersistentEntity();

            sEntity.Category = entity.Category != null
                ? context.Categories.Where(x => x.Id == entity.Category.Id).FirstOrDefault()
                : null;

            sEntity.Source = entity.Source != null
                ? context.Sources.Where(x => x.Id == entity.Source.Id).FirstOrDefault()
                : null;

            sEntity.SqlTags = context.Tags.Where(x => tagIds.Contains(x.Id)).Select(x => x).ToList();

            var insertedRow = context.Articles.Add(sEntity);

            context.SaveChanges();

            return(insertedRow.ToDomainEntity());
        }
Exemple #3
0
        public ISource Add(Source entity)
        {
            try
            {
                var sEntity     = entity.ToPersistentEntity();
                var insertedRow = context.Sources.Add(sEntity);
                context.SaveChanges();

                return(insertedRow.ToDomainEntity());
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        public IUserType Add(Domain.Models.UserType entity)
        {
            var sEntity     = entity.ToPersistentEntity();
            var insertedRow = context.UserTypes.Add(sEntity);

            context.SaveChanges();

            return(insertedRow.ToDomainEntity());
        }
Exemple #5
0
        public ICategory Add(Domain.Models.Category entity)
        {
            var sEntity     = entity.ToPersistentEntity();
            var insertedRow = context.Categories.Add(sEntity);

            context.SaveChanges();

            return(insertedRow.ToDomainEntity());
        }
Exemple #6
0
        public IUser Add(Domain.Models.User entity)
        {
            var sEntity = entity.ToPersistentEntity();

            if (entity.UserType == null)
            {
                sEntity.UserTypeId = 3;
            }
            var insertedRow = context.Users.Add(sEntity);

            context.SaveChanges();

            return(insertedRow.ToDomainEntity());
            //return entity;
        }