Ejemplo n.º 1
0
    public Tag Save(Tag tag)
    {
        EntityEntry <Tag> entry = context.Tags.Add(tag);

        context.SaveChanges();
        return(entry.Entity);
    }
Ejemplo n.º 2
0
    public Category Save(Category category)
    {
        category.CreatedDate = DateTime.Now;
        EntityEntry <Category> entry = context.Categories.Add(category);

        context.SaveChanges();
        return(entry.Entity);
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
 public bool Save(int userId)
 {
     try
     {
         return(_ctx.SaveChanges(userId) >= 0);
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed in Save: {ex}");
         return(false);
     }
 }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
0
    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();
    }