public async Task CrearLike()
        {
            try
            {
                PeticionesUsuarioPublicacion peticion = new PeticionesUsuarioPublicacion()
                {
                    idUsuario     = Usuario.idUsuario,
                    idPublicacion = Publicacion.idPublicacion
                };
                APIResponse response = await CreateLike.RunStrategy(peticion);

                if (response.IsSuccess)
                {
                    //isenablechange
                }
                else
                {
                    ((MessageViewModel)PopUp.BindingContext).Message = "Error al reaccionar publicacion";
                    await PopupNavigation.Instance.PushAsync(PopUp);
                }
            }
            catch (Exception e)
            {
            }
        }
        public async Task <ActionResult <string> > Create([FromBody] CreateLike jsonRequest)
        {
            var response = await _mediator.Send(jsonRequest);

            var json = JsonSerializer.Serialize(response);

            return(json);
        }
예제 #3
0
 public ActionResult Like(CreateLike model)
 {
     if (repo.GetElements().ToList()[model.DisId].Comments.Where(x => x.Author == user).Count() > 0)
     {
         LikeD like = new LikeD();
         like.Side    = repo.GetElements().ToList()[model.DisId].Comments.First(x => x.Author == user).Kind;
         like.Author  = user;
         like.Comment = repo.GetElements().ToList()[model.DisId].Comments.ToList()[model.ComId];
         if (repo.SetLike(like))
         {
             return(Content("true"));
         }
         else
         {
             return(Content("false"));
         }
     }
     return(Content("false"));
 }
        public async Task <Dictionary <string, object> > Handle(CreateLike request, CancellationToken cancellationToken)
        {
            string requestAddress         = "https://localhost:5001/api/users/username/" + request.Username;
            string likeUserRequestAddress = "https://localhost:5001/api/users/" + request.PersonId;
            string userResponseString     = await client.GetStringAsync(requestAddress);

            string likeUSerResponseString = await client.GetStringAsync(likeUserRequestAddress);

            UserResponse userResponse     = JsonConvert.DeserializeObject <UserResponse>(userResponseString);
            UserResponse likeUSerResponse = JsonConvert.DeserializeObject <UserResponse>(likeUSerResponseString);
            var          response         = new Dictionary <string, object>();
            var          succes           = true;
            var          emailSent        = false;

            if (request.PersonLike == 1)
            {
                emailSent = SendEmail(userResponse.user.Email, likeUSerResponse.user.UserName);
            }

            try
            {
                var like = Like.Create(request.PersonId, request.PetId, userResponse.user.Id, request.PersonLike, request.PetLike);
                LikeContext.Likes.Add(like);
                await LikeContext.SaveChangesAsync(cancellationToken);

                response.Add("like", like);
            }
            catch (InvalidOperationException)
            {
                succes = false;
            }

            response.Add("succes", succes);
            response.Add("emailSent", emailSent);
            return(response);
        }