Exemplo n.º 1
0
        public IHttpActionResult InsertBlockDetails(RequestModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Id) || (string.IsNullOrEmpty(model.ScheduleId)))
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Blocking User Id and Blocked User Id are required.")));
                }

                UserBlockDetails details = new UserBlockDetails();
                details.BlockedUserId  = Convert.ToInt64(model.ScheduleId);
                details.BlockingUserId = Convert.ToInt64(model.Id);

                UserFollowerDetails userFollowDetails = new UserFollowerDetails();
                var userFollowList = _userFollowService.GetAllUserFollowList().Where(a => a.FollowerUserId == details.BlockedUserId && a.FollowingUserId == details.BlockingUserId).ToList();
                foreach (var item in userFollowList)
                {
                    _userFollowService.RemoveUserFollowDetailsByUserId(item.FollowerUserId, item.FollowingUserId);
                }
                userFollowList = _userFollowService.GetAllUserFollowList().Where(a => a.FollowerUserId == details.BlockingUserId && a.FollowingUserId == details.BlockedUserId).ToList();
                foreach (var item in userFollowList)
                {
                    _userFollowService.RemoveUserFollowDetailsByUserId(item.FollowerUserId, item.FollowingUserId);
                }
                var dateTime = DateTime.UtcNow;
                details.BlockingTime = dateTime.ToString(@"yyyy/MM/dd hh:mm tt", new CultureInfo("en-US"));
                _blockservice.InsertBlockDetails(details);
            }
            catch (Exception e)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)));
            }

            return(Ok("Block details inserted successfully."));
        }