Beispiel #1
0
        public void Delete(DalContent e)
        {
            var content = e.ToOrmContent();

            content = context.Set <Content>().Single(c => c.Id == content.Id);
            context.Set <Content>().Remove(content);
        }
Beispiel #2
0
        public void Update(DalContent entity)
        {
            /*
             * var updatedContent = entity.ToOrmContent();
             * context.Set<Content>().Attach(updatedContent);
             *
             * var entry = context.Entry(updatedContent);
             * if (updatedContent.Name != null && original.Name != updatedContent.Name)
             *  entry.Property(e => e.Name).IsModified = true;
             *
             * if (updatedContent.Description != null && original.Description != updatedContent.Description)
             *  entry.Property(e => e.Description).IsModified = true;
             *
             * if (entity.Rating != null && original.Rating != updatedContent.Rating)
             *  entry.Property(e => e.Rating).IsModified = true;
             *
             * if (updatedContent.VotedUsers.Any() && original.VotedUsers.SequenceEqual(updatedContent.VotedUsers) )
             *  entry.Property(e => e.VotedUsers).IsModified = true;*/
            var original = context.Set <Content>().First(u => u.Id == entity.Id);

            var updatedContent = entity.ToOrmContent();

            if (updatedContent.Name != null)
            {
                original.Name = updatedContent.Name;
            }
            if (updatedContent.Description != null)
            {
                original.Description = updatedContent.Description;
            }
        }
Beispiel #3
0
        public DalContent Create(DalContent e)
        {
            var content = e.ToOrmContent();

            content.Date = DateTime.Now;
            content.User = context.Set <User>().Find(e.UserId);
            return(context.Set <Content>().Add(content).ToDalContent()); //CONTENT VALIDATION TODO
        }
        public int Create(DalContent entity)
        {
            var dbBook = context.Books.FirstOrDefault(e => e.BookID == entity.BookID);
            var dbUser = context.Users.FirstOrDefault(e => e.UserID == entity.UserID);

            if (dbBook != null && dbUser != null)
            {
                context.Contents.Add(entity.ToOrmContent());
            }
            return(0);
        }