Exemplo n.º 1
0
        private static async Task<HttpStatusCode> RemoveLikeAsync(
            ApplicationDbContext dbContext, string userId, int entryId, LikeKind kind)
        {
            TimelineEntry entryEntity = await dbContext.TimelineEntries
                .SingleOrDefaultAsync(te => te.TimelineEntryId == entryId);
            if (entryEntity == null)
            {
                return HttpStatusCode.NotFound;
            }

            var likeEntity = new Like
            {
                UserId = userId,
                Kind = kind,
                UserTextId = entryEntity.MessageUserTextId
            };
            dbContext.Likes.Add(likeEntity);

            await dbContext.SaveChangesAsync();

            return HttpStatusCode.OK;
        }
Exemplo n.º 2
0
        private static async Task<HttpStatusCode> AddLikeAsync(
            ApplicationDbContext dbContext,
            string userId,
            PropertyInfo likedIdProperty,
            int likedId,
            LikeKind kind)
        {
            var likeEntity = new Like
            {
                UserId = userId,
                Kind = kind
            };

            likedIdProperty.SetValue(likeEntity, likedId);


            dbContext.Likes.Add(likeEntity);

            await dbContext.SaveChangesAsync();
            return HttpStatusCode.OK;
        }