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; }
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 void Delete(DalContent e) { var content = e.ToOrmContent(); content = context.Set<Content>().Single(c => c.Id == content.Id); context.Set<Content>().Remove(content); }