public Tag Save(Tag tag) { EntityEntry <Tag> entry = context.Tags.Add(tag); context.SaveChanges(); return(entry.Entity); }
public Category Save(Category category) { category.CreatedDate = DateTime.Now; EntityEntry <Category> entry = context.Categories.Add(category); context.SaveChanges(); return(entry.Entity); }
public Post Save(Post post) { // Weird lame hack post.CategoryFk = post.Category.Id; post.Category = null !; post.UserFk = post.User.Id; post.User = null !; var saved = context.Add(post); context.SaveChanges(); return(saved.Entity); }
public bool Save(int userId) { try { return(_ctx.SaveChanges(userId) >= 0); } catch (Exception ex) { _logger.LogError($"Failed in Save: {ex}"); return(false); } }
public Comment SaveForPost(int postId, Comment comment) { comment.PostFk = postId; comment.Post = null !; comment.UserFk = comment.User?.Id; comment.User = null !; var saved = context.Add(comment); context.SaveChanges(); saved.Entity.User = context.Users.Single(user => user.Id == comment.UserFk); return(saved.Entity); }
public void MarkAsRead(int userId, int notificationId) { Notification?existing = context.Notifications.Find(notificationId); if (existing == null) { throw new Exception(); } EntityEntry <Notification> entry = context.Entry(existing); entry.CurrentValues["Read"] = true; context.SaveChanges(); }