Пример #1
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;
        }
Пример #2
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
 }
Пример #3
0
        public int UpVote(DalContent content, DalUser user)
        {
            var originalUser = context.Set<User>().First(u => u.Id == user.Id);
            var originalContent = context.Set<Content>().First(u => u.Id == content.Id);

            if (!originalUser.VotedPublications.Contains(originalContent))
            {
                originalContent.Rating++;
                originalUser.VotedPublications.Add(originalContent);
            }
            return (int)originalContent.Rating;
        }
Пример #4
0
 public static Content ToOrmContent(this DalContent e)
 {
     return(new Content()
     {
         Date = e.Date,
         Description = e.Description,
         Id = e.Id,
         Name = e.Name,
         Rating = e.Rating.Value,
         UrlToContent = e.UrlToContent,
         User = new User()
         {
             Id = e.UserId, Name = e.UserName
         },
         Comments = e.Comments?.Select(x => x.ToOrmComment()).ToList()
     });
 }
Пример #5
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);
 }