Пример #1
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IComment.
 /// </param>
 /// <param name='commentId'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 public static object PostLikeByCommentidAndLikerequest(this IComment operations, int commentId, LikeRequest likeRequest)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IComment)s).PostLikeByCommentidAndLikerequestAsync(commentId, likeRequest);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Пример #2
0
        public bool dislike(LikeRequest likeRequest)
        {
            try
            {
                if (!verifyUser(likeRequest.connectionId))
                    return false;

                var userId = (from u in _entity.connections where u.connection_id == likeRequest.connectionId select u).FirstOrDefault();
                var exisitingVote = (from v in _entity.user_likes
                                     where v.user_id == userId.id && v.suggestion_id == likeRequest.suggestionId
                                     select v).FirstOrDefault();
                if (exisitingVote == null)
                {
                    _entity.user_likes.Add(new user_likes()
                    {
                        suggestion_id = likeRequest.suggestionId,
                        user_id = userId.user_id,
                        type = 0
                    });
                }
                else if (exisitingVote.type == 0)
                {
                    return false;
                }
                else
                {
                    exisitingVote.type = 0;
                }

                _entity.SaveChanges();

                var context = GlobalHost.ConnectionManager.GetHubContext<TitanHub>();
                var collabos = (from c in _entity.collaborators where c.event_id == likeRequest.eventId select c.user_id).ToList();
                foreach (var id1 in _entity.connections)
                {
                    if (collabos.Contains(id1.user_id))
                    {
                        context.Clients.Client(id1.connection_id).ReloadEventDetails(likeRequest.eventId);
                        TitanSync.NotifyClient(id1.connection_id, userId.user.name + " disliked a suggestion!", userId.user.name);
                    }
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Пример #3
0
        /// <param name='operations'>
        /// Reference to the Rg.ClientApp.IComment.
        /// </param>
        /// <param name='commentId'>
        /// Required.
        /// </param>
        /// <param name='likeRequest'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public static async Task <object> PostLikeByCommentidAndLikerequestAsync(this IComment operations, int commentId, LikeRequest likeRequest, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            Microsoft.Rest.HttpOperationResponse <object> result = await operations.PostLikeByCommentidAndLikerequestWithOperationResponseAsync(commentId, likeRequest, cancellationToken).ConfigureAwait(false);

            return(result.Body);
        }
Пример #4
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IComment.
 /// </param>
 /// <param name='commentId'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 public static object PostLikeByCommentidAndLikerequest(this IComment operations, int commentId, LikeRequest likeRequest)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IComment)s).PostLikeByCommentidAndLikerequestAsync(commentId, likeRequest);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Пример #5
0
        /// <param name='entryId'>
        /// Required.
        /// </param>
        /// <param name='likeRequest'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <object> > PostLikeByEntryidAndLikerequestWithOperationResponseAsync(int entryId, LikeRequest likeRequest, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            // Validate
            if (likeRequest == null)
            {
                throw new ArgumentNullException("likeRequest");
            }

            // Tracing
            bool   shouldTrace  = ServiceClientTracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("entryId", entryId);
                tracingParameters.Add("likeRequest", likeRequest);
                ServiceClientTracing.Enter(invocationId, this, "PostLikeByEntryidAndLikerequestAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/api/Timeline/";
            url = url + Uri.EscapeDataString(entryId.ToString());
            url = url + "/Like";
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.Method     = HttpMethod.Post;
            httpRequest.RequestUri = new Uri(url);

            // Set Headers

            // Set Credentials
            if (this.Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }

            // Serialize Request
            string requestContent = null;
            JToken requestDoc     = likeRequest.SerializeJson(null);

            requestContent      = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
            httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
            httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            // Send Request
            if (shouldTrace)
            {
                ServiceClientTracing.SendRequest(invocationId, httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
            }
            HttpStatusCode statusCode = httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (statusCode != HttpStatusCode.NoContent)
            {
                HttpOperationException <object> ex = new HttpOperationException <object>();
                ex.Request  = httpRequest;
                ex.Response = httpResponse;
                ex.Body     = null;
                if (shouldTrace)
                {
                    ServiceClientTracing.Error(invocationId, ex);
                }
                throw ex;
            }

            // Create Result
            HttpOperationResponse <object> result = new HttpOperationResponse <object>();

            result.Request  = httpRequest;
            result.Response = httpResponse;

            // Deserialize Response
            object resultModel = default(object);

            result.Body = resultModel;

            if (shouldTrace)
            {
                ServiceClientTracing.Exit(invocationId, result);
            }
            return(result);
        }
Пример #6
0
        /// <param name='operations'>
        /// Reference to the Rg.ClientApp.IUserImages.
        /// </param>
        /// <param name='id'>
        /// Required.
        /// </param>
        /// <param name='extension'>
        /// Required.
        /// </param>
        /// <param name='likeRequest'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public static async Task <object> PostLikeByIdAndExtensionAndLikerequestAsync(this IUserImages operations, int id, string extension, LikeRequest likeRequest, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            Microsoft.Rest.HttpOperationResponse <object> result = await operations.PostLikeByIdAndExtensionAndLikerequestWithOperationResponseAsync(id, extension, likeRequest, cancellationToken).ConfigureAwait(false);

            return(result.Body);
        }
Пример #7
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IUserImages.
 /// </param>
 /// <param name='id'>
 /// Required.
 /// </param>
 /// <param name='extension'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 public static object PostLikeByIdAndExtensionAndLikerequest(this IUserImages operations, int id, string extension, LikeRequest likeRequest)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IUserImages)s).PostLikeByIdAndExtensionAndLikerequestAsync(id, extension, likeRequest);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Пример #8
0
 public async void DislikeMessage([FromBody] LikeRequest likeRequest)
 {
     service.DislikeMessage(likeRequest);
 }
Пример #9
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IAlbums.
 /// </param>
 /// <param name='albumId'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 public static object PostLikeAlbumByAlbumidAndLikerequest(this IAlbums operations, int albumId, LikeRequest likeRequest)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IAlbums)s).PostLikeAlbumByAlbumidAndLikerequestAsync(albumId, likeRequest);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 public async Task <ServiceResponse <NewsDto> > LikeNews(LikeRequest request)
 {
     return(await _executeService.TryExecute(() => _service.LikeNewsAsync(request)));
 }
Пример #11
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IComment.
 /// </param>
 /// <param name='commentId'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 /// <param name='cancellationToken'>
 /// Cancellation token.
 /// </param>
 public static async Task<object> PostLikeByCommentidAndLikerequestAsync(this IComment operations, int commentId, LikeRequest likeRequest, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     Microsoft.Rest.HttpOperationResponse<object> result = await operations.PostLikeByCommentidAndLikerequestWithOperationResponseAsync(commentId, likeRequest, cancellationToken).ConfigureAwait(false);
     return result.Body;
 }
Пример #12
0
        public static async Task <HttpStatusCode> AddOrRemoveLikeAsync(
            ApplicationDbContext dbContext,
            string userId,
            int likedId,
            Expression <Func <Like, int?> > entryIdProperty,
            LikeRequest like)
        {
            using (var transaction = dbContext.Database.BeginTransaction())
            {
                bool succeeded = false;
                try
                {
                    LikeKind kind;
                    switch (like.LikeKind.ToLowerInvariant())
                    {
                    case "like":
                        kind = LikeKind.Like;
                        break;

                    case "frown":
                        kind = LikeKind.Frown;
                        break;

                    case "hug":
                        kind = LikeKind.Hug;
                        break;

                    default:
                        return(HttpStatusCode.BadRequest);
                    }

                    var match = (Expression <Func <Like, bool> >)Expression.Lambda(
                        Expression.Equal(
                            entryIdProperty.Body,
                            Expression.Convert(
                                Expression.Constant(likedId),
                                typeof(int?))),
                        entryIdProperty.Parameters[0]);

                    // Using First rather than Single because there are race conditions in which
                    // we can end up with multiple likes.
                    Like existingLikeEntity = await dbContext.Likes
                                              .Where(le => le.Kind == kind)
                                              .FirstOrDefaultAsync(match);

                    HttpStatusCode result;
                    if (like.Set)
                    {
                        if (existingLikeEntity != null)
                        {
                            // Ignore a relike
                            result = HttpStatusCode.OK;
                        }
                        var idProp = (PropertyInfo)((MemberExpression)entryIdProperty.Body).Member;
                        result = await AddLikeAsync(dbContext, userId, idProp, likedId, kind);
                    }
                    else
                    {
                        if (existingLikeEntity != null)
                        {
                            dbContext.Likes.Remove(existingLikeEntity);
                            await dbContext.SaveChangesAsync();
                        } // Ignore a reunlike
                        result = HttpStatusCode.OK;
                    }
                    transaction.Commit();
                    succeeded = true;
                    return(result);
                }
                finally
                {
                    if (!succeeded)
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
Пример #13
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IAlbums.
 /// </param>
 /// <param name='albumId'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 public static object PostLikeAlbumByAlbumidAndLikerequest(this IAlbums operations, int albumId, LikeRequest likeRequest)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IAlbums)s).PostLikeAlbumByAlbumidAndLikerequestAsync(albumId, likeRequest);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Пример #14
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IUserImages.
 /// </param>
 /// <param name='id'>
 /// Required.
 /// </param>
 /// <param name='extension'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 /// <param name='cancellationToken'>
 /// Cancellation token.
 /// </param>
 public static async Task<object> PostLikeByIdAndExtensionAndLikerequestAsync(this IUserImages operations, int id, string extension, LikeRequest likeRequest, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     Microsoft.Rest.HttpOperationResponse<object> result = await operations.PostLikeByIdAndExtensionAndLikerequestWithOperationResponseAsync(id, extension, likeRequest, cancellationToken).ConfigureAwait(false);
     return result.Body;
 }
Пример #15
0
 /// <param name='operations'>
 /// Reference to the Rg.ClientApp.IUserImages.
 /// </param>
 /// <param name='id'>
 /// Required.
 /// </param>
 /// <param name='extension'>
 /// Required.
 /// </param>
 /// <param name='likeRequest'>
 /// Required.
 /// </param>
 public static object PostLikeByIdAndExtensionAndLikerequest(this IUserImages operations, int id, string extension, LikeRequest likeRequest)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IUserImages)s).PostLikeByIdAndExtensionAndLikerequestAsync(id, extension, likeRequest);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }