Example #1
0
 private async Task<bool> CreatePostBroadcastAsync(StatusPost post)
 {
     try
     {
         List<PersonAllin> people = await GetPersonInvolve(post.PostBy.AuthorTypeId, post.PostBy.AuthorId);
         if (people == null || people.Count==0) return false;
         List<Task> tasks = new List<Task>();
         //for (int i = 0; i < people.Count - 1; i++)
         //{
         //    tasks.Add(Task.Run(() =>
         //    {
         //        PostBroadcastPerson postBroadcast = new PostBroadcastPerson();
         //        postBroadcast.PostId = post.Id;
         //        postBroadcast.Receivers.Add(people[i].Person.Id);
         //        postBroadcast.PostType = PostTypeEnum.StatusPost;
         //        post.PostTime = post.PostTime;
         //        m_PostbroadcastPersonRepositoryM.Create(postBroadcast);
         //    }));
         //}
         await Task.WhenAll(tasks);
         return true;
     }
     catch
     {
         return false;
     }
 }
Example #2
0
        public async Task Test_CreateStatusPost()
        {
            StatusPost post = new StatusPost();

            post.Comments     = 4;
            post.Likes        = 10;
            post.Shares       = 1;
            post.Views        = 15;
            post.PostTime     = DateTime.UtcNow;
            post.PostTimeUnix = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            post.Images       = null;
            post.Privacy      = (int)PostPrivacyType.All;
            post.Content      = "Yeah";
            post.PostBy       = new Author()
            {
                DisplayName  = "",
                AuthorId     = "5ad063f571db6e14c4681aa9",
                AuthorTypeId = (int)my8.Api.my8Enum.AuthorType.Page
            };

            await server.Call(HttpMethod.Post, "/api/StatusPost/create", post, (rp) =>
            {
                Assert.NotNull(rp);
                Assert.NotNull(rp.Content);
                Assert.True(rp.IsSuccessStatusCode);

                var body = rp.Content.ReadAsStringAsync().Result;

                Assert.NotNull(body);
            });
        }
 private AddStatusRequest CreateRequestWithPost(StatusPost status)
 {
     return(new AddStatusRequest()
     {
         StatusPost = status
     });
 }
Example #4
0
        private async Task <bool> CreatePostBroadcastAsync(StatusPost post)
        {
            try
            {
                List <PersonAllin> people = await GetPersonInvolve(post.PostBy);

                if (people == null || people.Count == 0)
                {
                    return(false);
                }
                List <Task> tasks = new List <Task>();
                for (int i = 0; i < people.Count; i++)
                {
                    PostBroadcastPerson postBroadcast = new PostBroadcastPerson();
                    postBroadcast.PostId     = post.Id;
                    postBroadcast.ReceiverId = people[i].Person.Id;
                    postBroadcast.PostType   = PostType.StatusPost;
                    postBroadcast.KeyTime    = post.PostTimeUnix;
                    tasks.Add(Task.Run(() =>
                    {
                        _PostbroadcastPersonRepositoryM.Create(postBroadcast);
                    }));
                }
                await Task.WhenAll(tasks);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #5
0
        public IActionResult Put(int id, [FromBody] PostModel model)
        {
            ResponsePostRental response   = new ResponsePostRental();
            StatusPost         statusPost = (StatusPost)model.Status;

            if (model == null && model?.Status == null)
            {
                response = ResponseMessage(statusPost);
                return(BadRequest(response));
            }
            try
            {
                RentalPost updatePost = new RentalPost();
                RentalPost rentalPost = _rentalPostService.GetById(id);
                switch (statusPost)
                {
                case StatusPost.Pending:
                    rentalPost.Status = (byte)StatusPost.Pending;
                    _rentalPostService.UppdatePost(rentalPost);
                    break;

                case StatusPost.Approved:
                    rentalPost.Status = (byte)StatusPost.Approved;
                    _rentalPostService.UppdatePost(rentalPost);
                    break;

                case StatusPost.Cancel:
                    rentalPost.Status = (byte)StatusPost.Cancel;
                    _rentalPostService.UppdatePost(rentalPost);
                    break;

                case StatusPost.Setp4:
                    _rentalPostService.DeletePictureForPost(rentalPost.Id);
                    _rentalPostService.DeleteUtilitiesOfPost(rentalPost.Id);
                    _rentalPostService.InsertPicturesForPost(model.PictureIds, rentalPost.Id);
                    _rentalPostService.InsertUtilitiesForPost(model.UtilitiesIds, rentalPost.Id);
                    updatePost = model.ConvertSetp(rentalPost);
                    _rentalPostService.UppdatePost(updatePost);
                    break;

                case StatusPost.Delete:
                    rentalPost.Status = (byte)StatusPost.Delete;
                    _rentalPostService.UppdatePost(rentalPost);
                    break;

                default:
                    break;
                }
                response = ResponseMessage(StatusPost.Susscess);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response = ResponseMessage(StatusPost.Susscess);
                _logger.Error("Post PostRentalController", ex);
                return(BadRequest(response));
            }
        }
Example #6
0
        public async Task <StatusPost> Post(StatusPost post)
        {
            post.PostTime     = DateTime.UtcNow;
            post.PostTimeUnix = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            string id = await m_StatuspostRepositoryM.Post(post);

            post.Id = id;
            return(post);
        }
Example #7
0
        /// <summary>
        /// ステータスポストをFrostに投稿します。
        /// </summary>
        /// <param name="text">投稿する本文</param>
        /// <returns></returns>
        public async Task <StatusPost> CreateStatusPost(string text)
        {
            var res = await _Request(HttpMethod.Post, "posts/post_status", new Dictionary <string, string> {
                ["text"] = text
            });

            var dic = JsonConvert.DeserializeObject <Dictionary <string, JToken> >(res.ContentJson);

            return(StatusPost.FromJson(dic["postStatus"].ToString()));
        }
Example #8
0
        public void Parameter_Voltage_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                Voltage = 222.3m
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[7], Is.EqualTo("222.3"));
        }
Example #9
0
        public void Parameter_Temperature_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                Temperature = 18.9m
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[6], Is.EqualTo("18.9"));
        }
Example #10
0
        public void Parameter_PowerConsumption_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                PowerConsumption = 4444
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[5], Is.EqualTo("4444"));
        }
Example #11
0
        public void Parameter_EnergyConsumption_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                EnergyConsumption = 3333
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[4], Is.EqualTo("3333"));
        }
Example #12
0
        public void Parameter_PowerGeneration_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                PowerGeneration = 2222
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[3], Is.EqualTo("2222"));
        }
Example #13
0
        public void Parameter_EnergyGeneration_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                EnergyGeneration = 1111
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[2], Is.EqualTo("1111"));
        }
Example #14
0
        public void Parameter_Timestamp_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                Timestamp = new DateTime(2020, 2, 1, 13, 12, 20)
            };

            string[] postArray = GetSplitStatusPostLine(post);
            Assert.That(postArray[0], Is.EqualTo("20200201"));
            Assert.That(postArray[1], Is.EqualTo("13:12"));
        }
Example #15
0
        public async Task <IActionResult> CreatePost([FromBody] StatusPost model)
        {
            StatusPost post = await m_statusPostBusiness.Post(model);

            bool result = false;

            if (post != null)
            {
                result = await m_FeedSmart.BroadcastToPerson(model);
            }
            return(ToResponse(result));
        }
Example #16
0
        private ResponsePostRental ResponseMessage(StatusPost codeMessage)
        {
            ResponsePostRental response = new ResponsePostRental();

            switch (codeMessage)
            {
            case StatusPost.Pending:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Approved:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Cancel:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Block:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Setp4:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Delete:
                response.MessageCode = (int)StatusPost.Pending;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Pending);
                break;

            case StatusPost.Error:
                response.MessageCode = (int)StatusPost.Error;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Error);
                break;

            case StatusPost.Susscess:
                response.MessageCode = (int)StatusPost.Susscess;
                response.Message     = CommonHelper.DescriptionEnum(StatusPost.Susscess);
                break;

            default:
                response.MessageCode = 0;
                response.Message     = "Không tìm được, dữ liệu phù hợp";
                break;
            }
            return(response);
        }
		public object Deserialize(JsonValue json, JsonMapper mapper)
		{
			StatusPost post = null;
			if ( json != null && !json.IsNull )
			{
				post = new StatusPost();
				post.ID          = json.ContainsName("id"          ) ? json.GetValue<string>("id") : String.Empty;
				post.CreatedTime = json.ContainsName("created_time") ? JsonUtils.ToDateTime(json.GetValue<string>("created_time"), "yyyy-MM-ddTHH:mm:ss") : DateTime.MinValue;
				post.UpdatedTime = json.ContainsName("updated_time") ? JsonUtils.ToDateTime(json.GetValue<string>("updated_time"), "yyyy-MM-ddTHH:mm:ss") : DateTime.MinValue;
				
				post.From        = mapper.Deserialize<Reference>(json.GetValue("from"));
			}
			return post;
		}
Example #18
0
        public object Deserialize(JsonValue json, JsonMapper mapper)
        {
            StatusPost post = null;

            if (json != null && !json.IsNull)
            {
                post             = new StatusPost();
                post.ID          = json.ContainsName("id") ? json.GetValue <string>("id") : String.Empty;
                post.CreatedTime = json.ContainsName("created_time") ? JsonUtils.ToDateTime(json.GetValue <string>("created_time"), "yyyy-MM-ddTHH:mm:ss") : DateTime.MinValue;
                post.UpdatedTime = json.ContainsName("updated_time") ? JsonUtils.ToDateTime(json.GetValue <string>("updated_time"), "yyyy-MM-ddTHH:mm:ss") : DateTime.MinValue;

                post.From = mapper.Deserialize <Reference>(json.GetValue("from"));
            }
            return(post);
        }
Example #19
0
        public async Task <List <Comment> > GetByPost(string postId, int postType, int skip)
        {
            if (postType == (int)PostType.StatusPost)
            {
                StatusPost post = new StatusPost();
                post.Id = postId;
                List <Comment> comments = await _commentRepositoryM.GetByPost(post, skip, Utils.LIMIT_ROW_COMMENT);

                return(comments.OrderBy(p => p.CommentTime).ToList());
            }
            if (postType == (int)PostType.JobPost)
            {
                JobPost post = new JobPost();
                post.Id = postId;
                return(await _commentRepositoryM.GetByPost(post, skip, Utils.LIMIT_ROW_COMMENT));
            }
            return(null);
        }
Example #20
0
        public async Task <List <IPost> > GetHomeTimeline(string userId, int?limit = null)
        {
            var parameters = new Dictionary <string, string>();

            if (limit != null)
            {
                parameters.Add("limit", limit.ToString());
            }
            var res = await _Request(HttpMethod.Get, $"users/{userId}/timelines/home", parameters);

            var dic = JsonConvert.DeserializeObject <Dictionary <string, JToken> >(res.ContentJson);

            // TODO: エラー処理

            return(dic["posts"].Select((postJToken) =>
            {
                var post = postJToken.ToObject <Dictionary <string, JToken> >();
                var postType = post["type"].ToString();

                IPost result;

                if (postType == "status")
                {
                    result = StatusPost.FromJson(postJToken.ToString());
                }
                else if (postType == "article")
                {
                    throw new NotSupportedException("article post は未サポートです。");
                }
                else if (postType == "reference")
                {
                    throw new NotSupportedException("reference post は未サポートです。");
                }
                else
                {
                    throw new Exception("不明なタイプのポストが含まれています。");
                }

                return result;
            }).ToList());
        }
        public async Task <IActionResult> Create([FromBody] StatusPost model)
        {
            if (string.IsNullOrWhiteSpace(model.Content))
            {
                return(Json(false));
            }
            model.IsAds         = false;
            model.PostBy        = AutoMapper.Mapper.Map <Author>(_currentProcess.CurrentAccount.Account);//temperary
            model.PostTime      = DateTime.UtcNow;
            model.Privacy       = (int)PostPrivacyType.All;
            model.Comments      = 0;
            model.Likes         = 0;
            model.Shares        = 0;
            model.Views         = 0;
            model.PersonId      = _currentProcess.CurrentAccount.Account.PersonId;
            model.PostingAsType = ActionAsType.Person;//temperary
            if (!ModelState.IsValid)
            {
                return(ToResponse(false));
            }
            var result = await _httpClient.SendRequestAsync <ResponseActionJsonModel>(Request, _clientConfig, "/StatusPosts/create", HttpMethod.Post, model);

            return(ToResponse(result));
        }
Example #22
0
        public void Parameter_ExtendedValues_CreatesCorrectUriParameters()
        {
            var post = new StatusPost()
            {
                ExtendedValue1 = 1,
                ExtendedValue2 = 2,
                ExtendedValue3 = 3,
                ExtendedValue4 = 4,
                ExtendedValue5 = 5,
                ExtendedValue6 = 6
            };

            string[] postArray = GetSplitStatusPostLine(post);

            Assert.Multiple(() =>
            {
                Assert.That(postArray[8], Is.EqualTo("1"));
                Assert.That(postArray[9], Is.EqualTo("2"));
                Assert.That(postArray[10], Is.EqualTo("3"));
                Assert.That(postArray[11], Is.EqualTo("4"));
                Assert.That(postArray[12], Is.EqualTo("5"));
                Assert.That(postArray[13], Is.EqualTo("6"));
            });
        }
Example #23
0
 public async Task <bool> BroadcastToPerson(StatusPost post)
 {
     return(await CreatePostBroadcastAsync(post));
 }
Example #24
0
        public async Task <IActionResult> Get(string postId)
        {
            StatusPost post = await m_statusPostBusiness.Get(postId);

            return(ToResponse(post));
        }
 /// <summary>
 /// Resets the builder to it's default state. Ready to build a new status.
 /// </summary>
 public void Reset()
 {
     _statusPost = new StatusPost();
 }
        public async Task <IActionResult> BroadcastToPerson([FromBody] StatusPost model)
        {
            bool result = await m_PostBroadcastPersonBusiness.BroadcastToPerson(model);

            return(Json(result));
        }
 /// <summary>
 /// Creates a new builder.
 /// </summary>
 public StatusPostBuilder()
 {
     _statusPost = new StatusPost();
 }
Example #28
0
 public async Task <List <Comment> > GetByPost(StatusPost post, int skip, int limit)
 {
     return(await collection.Find($@"{{'PostId':'{post.Id}','PostType':{(int)PostType.StatusPost}}}").Skip(skip).Limit(limit).ToListAsync());
 }
Example #29
0
 public async Task<bool> BroadcastToPerson(StatusPost post)
 {
     bool result = await CreatePostBroadcastAsync(post);
     return result;
 }
Example #30
0
 public async Task <bool> UpdateViews(StatusPost post)
 {
     return(await m_StatuspostRepositoryM.UpdateViews(post.Id, true));
 }
Example #31
0
 public async Task <bool> UpdatePost(StatusPost post)
 {
     return(await m_StatuspostRepositoryM.UpdatePost(post));
 }