Example #1
0
        public async Task <IActionResult> AddLikeAsync(
            [FromBody][Required] LikeDto newLikeDto,
            CancellationToken cancellationToken)
        {
            var currentUserId = _userManager.GetUserIdAsInt(HttpContext.User);

            var likeEntity = new LikeEntity {
                PostId = newLikeDto.PostId,
                UserId = currentUserId
            };

            var updatedPost = await _post.DoAddLikeAsync(likeEntity, cancellationToken)
                              .ConfigureAwait(false);

            var notification = new NotificationEntity {
                Type           = NotificationType.AddLike,
                SentByUserId   = currentUserId,
                ReceivedUserId = updatedPost !.UserId,
                TriggeredOn    = DateTimeOffset.Now // TODO - add post to notification
            };

            await _notification.DoAddAsync(notification, cancellationToken)
            .ConfigureAwait(false);

            await _notification.DoBroadcastNotifications(updatedPost !.UserId)
            .ConfigureAwait(false);

            return(Ok(CreatePostDto(updatedPost !)));
        }
        public async Task <ActionResult> Like([FromBody] LikeRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var oPostId = new ObjectId(request.postId);

            var check = await _likeRepository.GetAsync(x =>
                                                       x.userId == userId && x.postId == oPostId);


            if (check != null)
            {
                return(Ok(new ResultModel {
                    result = true
                }));
            }

            var likeModel = new LikeEntity
            {
                postId = oPostId,
                userId = userId
            };

            await _likeRepository.AddAsync(likeModel);

            return(Ok(new ResultModel {
                result = true
            }));
        }
 public static LikeViewModel ToMvcLike(this LikeEntity likeEntity)
 {
     return(new LikeViewModel()
     {
         LikeId = likeEntity.Id,
         PhotoId = likeEntity.PhotoId,
         UserId = likeEntity.UserId
     });
 }
 public static DalLike ToDalLike(this LikeEntity likeEntity)
 {
     return(new DalLike()
     {
         Id = likeEntity.Id,
         ImageId = likeEntity.ImageId,
         UserId = likeEntity.UserId
     });
 }
Example #5
0
 public static LikeVM ToPLEntity(this LikeEntity item)
 {
     return(new LikeVM()
     {
         Id = item.Id,
         PostId = item.PostId,
         UserId = item.UserId
     });
 }
Example #6
0
 public static DalLike ToDal(this LikeEntity likeEntity)
 {
     return(new DalLike()
     {
         Id = likeEntity.Id,
         UserId = likeEntity.UserId,
         PhotoId = likeEntity.PhotoId
     });
 }
        public ActionResult DeleteLike(int postId)
        {
            int userId = ((UserVM)Session["UserInfo"]).Id;

            LikeEntity item = _likeService.Get(x => x.PostId == postId && x.UserId == userId);

            _likeService.Delete(item.Id);

            ViewBag.LikesCount = _likeService.GetAll(x => x.PostId == postId).Count();
            return(PartialView("LikePartial"));
        }
Example #8
0
        public bool AddOrRemoveLike(LikeEntity like = null, int userId = 0)
        {
            if (userId > 0)
            {
                _ctx.Remove(like);
            }
            if (userId == 0)
            {
                _ctx.Add(like);
            }

            return(Save());
        }
Example #9
0
        public static DALLike ToDALEntity(this LikeEntity item)
        {
            if (ReferenceEquals(item, null))
            {
                return(null);
            }

            return(new DALLike()
            {
                Id = item.Id,
                PostId = item.PostId,
                UserId = item.UserId
            });
        }
Example #10
0
        public async Task <ActionResult <GetPostDto> > DeleteLikeAsync(
            [FromBody][Required] LikeDto deletedLikeDto,
            CancellationToken cancellationToken)
        {
            var currentUserId = _userManager.GetUserIdAsInt(HttpContext.User);

            var likeEntity = new LikeEntity {
                PostId = deletedLikeDto.PostId,
                UserId = currentUserId
            };

            var updatedPost = await _post.DoDeleteLikeAsync(likeEntity, cancellationToken)
                              .ConfigureAwait(false);

            return(Ok(CreatePostDto(updatedPost !)));
        }
Example #11
0
        /// <summary>
        /// like a post
        /// </summary>
        /// <param name="PostId"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public async Task <bool> LikePostAsync(int id, int userId)
        {
            try
            {
                var like = new LikeEntity(id, userId); // convert
                await _context.LikeEntities.AddAsync(like);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #12
0
        public async Task <Response <OperationResult> > CreatePost(PostDTO model)
        {
            var responce = new Response <OperationResult>();

            var entity = new PostEntity(model);

            await _context.Posts.AddAsync(entity);

            await _context.SaveChangesAsync();

            var likeInfo = new LikeEntity <PostEntity> {
                ModuleId = entity.Id
            };
            await _context.Likes.AddAsync(likeInfo);

            await _context.SaveChangesAsync();

            responce.Data = OperationResult.Success;
            return(responce);
        }
        public JsonResult like(LikeEntity likeData)
        {
            if (likeData != null && Session["FullName"] != null)
            {
                try
                {
                    Customer cus = (Customer)Session["TaiKhoan"];
                    if (likeData.isLike)
                    {
                        PostLike postLike = new PostLike
                        {
                            PostID     = likeData.PostID,
                            CustomerID = cus.CustomerID,
                            LikeTime   = DateTime.Now
                        };
                        if (ModelState.IsValid)
                        {
                            db.Entry(postLike).State = System.Data.Entity.EntityState.Added;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        var like = db.PostLikes.Where(n => n.PostID == likeData.PostID && n.CustomerID == cus.CustomerID).SingleOrDefault();
                        if (like == null)
                        {
                            return(Json(false));
                        }
                        db.Entry(like).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }

                    return(Json(true));
                }
                catch
                {
                    return(Json(false));
                }
            }
            return(Json(false));
        }
        public static List <LikeEntity> ToLikeEntities(Post post)
        {
            post.NullCheck(nameof(post));

            var result = new List <LikeEntity>();

            if (post.LikedByUsers != null)
            {
                foreach (var like in post.LikedByUsers)
                {
                    var newLike = new LikeEntity
                    {
                        UserId = like.Id,
                        PostId = post.Id
                    };
                    result.Add(newLike);
                }
            }
            ;

            return(result);
        }
 public void DeleteLike(LikeEntity like)
 {
     likeRepository.Delete(like.ToDal());
     uow.Commit();
 }
 public void CreateLike(LikeEntity like)
 {
     _likeRepository.Create(like.ToDalLike());
     _uow.Commit();
 }
Example #17
0
        public ActionResult Delete(List <string> delete)
        {
            if (User.Identity.Name != "*****@*****.**")
            {
                return(RedirectToAction("Index", "Home"));
            }
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("MS_AzureStorageAccountConnectionString"));


            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("UserInformation");

            if (delete != null)
            {
                foreach (var i in delete)
                {
                    //유저인포에서 해당 매장 삭제, 계정 테이블에서 해당 매장으로 등록된 블롭 삭제
                    var value = i.Split('^');

                    var OwnerID         = value[0];
                    var OwnerIDforTable = OwnerID.Split('@')[0];
                    var ShopLocation    = value[1];
                    var ShopName        = value[2];

                    TableOperation retrieveOperation = TableOperation.Retrieve <UserInfoEntity>(OwnerID, ShopLocation);
                    TableResult    retrievedResult   = table.Execute(retrieveOperation);

                    UserInfoEntity deleteEntity = (UserInfoEntity)retrievedResult.Result;

                    // Print the phone number of the result.
                    if (deleteEntity != null)
                    {
                        TableOperation updateOperation = TableOperation.Delete(deleteEntity);
                        table.Execute(updateOperation);
                    }


                    CloudTable tableOfOwner = tableClient.GetTableReference(OwnerIDforTable);

                    TableQuery <ContentsEntity> queryShopName = new TableQuery <ContentsEntity>().Where(
                        TableQuery.GenerateFilterCondition("ShopName", QueryComparisons.Equal, ShopName));
                    Dictionary <string, string> blobName = new Dictionary <string, string>();
                    foreach (ContentsEntity entity in tableOfOwner.ExecuteQuery(queryShopName))
                    {
                        TableOperation deleteOperation = TableOperation.Delete(entity);
                        tableOfOwner.Execute(deleteOperation);
                        blobName.Add(entity.RowKey, entity.LikeMember); //LikeMember 값 읽어와서 같이 저장해두기
                    }


                    CloudBlobClient    blobClient    = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer blobContainer = blobClient.GetContainerReference(OwnerIDforTable);
                    foreach (var blob in blobName)
                    {
                        CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(blob.Key);
                        blockBlob.Delete();
                        //LikeMember 아이디하고 BlobName 값 이용해서 LikeContents 지우기
                        var likeOwner = blob.Value.Split(':');
                        for (int ii = 0; ii < likeOwner.Length - 1; ii++)
                        {
                            CloudTable likeOwnerTable = tableClient.GetTableReference(likeOwner[ii]);

                            TableOperation likeEntityOperation = TableOperation.Retrieve <LikeEntity>(OwnerID, blob.Key);
                            TableResult    likeEntityResult    = likeOwnerTable.Execute(likeEntityOperation);
                            if (likeEntityResult.Result != null)
                            {
                                LikeEntity     likeEntity      = (LikeEntity)likeEntityResult.Result;
                                TableOperation deleteOperation = TableOperation.Delete(likeEntity);
                                likeOwnerTable.Execute(deleteOperation);
                            }
                        }
                    }


                    var tempBuilding = ShopLocation.Split(':');
                    var building     = tempBuilding[0];
                    var floor        = tempBuilding[1];
                    var location     = tempBuilding[2];

                    CloudTable     BuildingTable = tableClient.GetTableReference(building);
                    TableOperation retrieveBuildingInfoOperation = TableOperation.Retrieve <BuildingEntity>(floor, location);
                    TableResult    retrievedBuildingInfoResult   = BuildingTable.Execute(retrieveBuildingInfoOperation);

                    BuildingEntity buildingInfoEntity = (BuildingEntity)retrievedBuildingInfoResult.Result;

                    // Print the phone number of the result.
                    if (buildingInfoEntity != null)
                    {
                        TableOperation deleteOperation = TableOperation.Delete(buildingInfoEntity);
                        BuildingTable.Execute(deleteOperation);
                    }
                }
            }


            List <UserInfoEntity>       result        = new List <UserInfoEntity>();
            List <UserInfoEntity>       resultExpired = new List <UserInfoEntity>();
            TableQuery <UserInfoEntity> queryExpired  = new TableQuery <UserInfoEntity>().Where(
                TableQuery.GenerateFilterConditionForDate("Period", QueryComparisons.LessThan, DateTime.Now.AddDays(-7)));

            foreach (UserInfoEntity entity in table.ExecuteQuery(queryExpired))
            {
                entity.Period = entity.Period.AddHours(9);
                resultExpired.Add(entity);
            }
            result = resultExpired;

            return(View(result));
        }
Example #18
0
 public LikeDTO(LikeEntity <PostEntity> likeInfo)
 {
     Id           = likeInfo.Id;
     CountOfLikes = likeInfo.CountOfLikes;
     UsersLike    = likeInfo.LikeBindings.Select(x => x.UserId).ToList();
 }
 public void CreateLike(LikeEntity like)
 {
     DBTwoRepositories.LikeRepository.Create(like.ToDalLike());
     DBTwoRepositories.Commit();
 }