public ActionResult Create(int post_id) { like_post like = new like_post() { likeOrdislike = true, UserInfo = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name).UserInfo }; db.POSTs.Single(n => n.post_id == post_id).like_post.Add(like); db.SaveChanges(); return(RedirectToAction("index", "Posts")); }
public HttpResponseMessage Delete(like_post item) { try { var likes = db.like_post.Where(l => l.id_post == item.id_post && l.id_user == item.id_user).ToArray(); foreach (var like in likes) { r.Delete(like.id); } return(Request.CreateResponse(HttpStatusCode.OK, $"like_post fue eliminado correctamente")); } catch (Exception) { } return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, $"No eliminado, like_post")); }
public async Task <HttpResponseMessage> Post(like_post item) { if (item == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, $"El like_post no puede estar sin datos")); } try { var likeDado = db.like_post.SingleOrDefault(l => l.id_post == item.id_post && l.id_user == item.id_user); if (likeDado == default(like_post)) { item.fecha = DateTime.UtcNow; if (r.Post(item)) { //TODO TEST like Post var diccionarioPhone_Device = new System.Collections.Generic.Dictionary <string, string>(); var usuarioQueDioLike = db.users.SingleOrDefault(u => u.id_user == item.id_user); var publicacion = db.publicaciones.SingleOrDefault(u => u.id_post == item.id_post); diccionarioPhone_Device.Add(publicacion.users.Phone_OS, publicacion.users.Device_id); var pushNotifier = new AppCenterPush(diccionarioPhone_Device); await pushNotifier.Notify("like_post", $"A {usuarioQueDioLike.username} le gusta tu publicación", publicacion.descripcion, new System.Collections.Generic.Dictionary <string, string>() { { DLL.PushConstantes.gotoPage, DLL.PushConstantes.goto_post }, { DLL.PushConstantes.id_post, publicacion.id_post.ToString() }, { DLL.PushConstantes.id_user, publicacion.id_user.ToString() } }); return(Request.CreateResponse(HttpStatusCode.Created, "like_post guardado correctamente")); } } else { return(Request.CreateResponse(HttpStatusCode.OK, "Ya existe dicho like")); } } catch (Exception e) { Debug.Print(e.Message); } return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "No es posible guardar los datos del like_post")); }