Пример #1
0
        public Response <ConversationResponse[]> listMessage([FromBody] ListMessageRequest request)
        {
            string userlogin = string.Empty;
            string token     = Request.Headers["Authorization"];

            // Get user login from token
            var info = this._authService.checkToken(token);
            Response <ConversationResponse[]> response = new Response <ConversationResponse[]>();

            //if (!string.IsNullOrEmpty(info.Username))
            //{
            return(this.bantuanHukumService.listMessages(request));
            //}
            //else
            //{
            //  response.message = "Unauthorize";
            // response.message_type = 2;
            //}
            // return response;
        }
        public Response <ConversationResponse[]> listNotification(ListMessageRequest request)
        {
            Response <ConversationResponse[]> response = new Response <ConversationResponse[]>();


            // Query diubah menjadi ascending, permintaan tgl 22Agustus 2018.
            var query = from x in this.Db.Conversations
                        from y in this.Db.BantuanHukum
                        from w in this.Db.StatusBantuan
                        where x.Header.ID == y.ID && x.Status.ID == w.ID
                        orderby x.CreatedDate descending
                        select new ConversationResponse
            {
                isUser      = x.CreatedBy.Contains("user_" + y.KodeLaporan),
                By          = x.CreatedBy.Contains("user_" + y.KodeLaporan) ? x.Header.NamaLengkap : x.CreatedBy,
                ID          = x.ID,
                KodeLaporan = y.KodeLaporan,
                Message     = x.Message,
                isRead      = x.IsRead,
                Status      = x.Status.ID,
                Tanggal     = x.CreatedDate,
                StatusText  = w.Name
            };

            if (!string.IsNullOrWhiteSpace(request.KodeLaporan))
            {
                query = query.Where(a => a.KodeLaporan == request.KodeLaporan);
            }

            ///isRead: 0 = keluarkan semua, 1 = hanya yang sudah dibaca, 2 = yang belum dibaca
            if (request.isRead > 0)
            {
                query = query.Where(a => a.isRead == (request.isRead == 1));
            }


            if (request.IsUser)
            {
                query = query.Where(a => a.isUser == request.IsUser);
            }

            // Status Filter
            if (request.Status != 0)
            {
                query = query.Where(a => a.Status == request.Status);
            }


            response.count = query.Count();
            // Set Paging
            int perpage = 10;
            var num     = (Convert.ToDecimal(response.count) / Convert.ToDecimal(perpage));

            response.totalpages = (int)Math.Ceiling(num);


            int take = request.pageIndex == 1 ? perpage : request.pageIndex * perpage;
            int skip = request.pageIndex > 1 ? (request.pageIndex - 1) * perpage : 0;

            response.data = query.Skip(skip).Take(take).ToArray();

            // Setelah final dipaging ambil foto profle Operator

            var dataUser = (from x in this.Db.Users

                            from y in response.data.Where(a => a.isUser == false).GroupBy(a => a.By)
                            where x.UserName == y.Key
                            select new { profile = x.ProfilePicture, username = x.UserName }).ToArray();

            foreach (var item in response.data)
            {
                if (item.isUser == false)
                {
                    var getProfile = dataUser.SingleOrDefault(a => a.username == item.By);
                    if (getProfile != null)
                    {
                        item.ProfilePicture = "staticFiles/" + getProfile.profile;
                    }
                }
            }


            return(response);
        }
Пример #3
0
        /// <summary>
        /// Begin a new asynchornous ListMessageRequest
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public async Task <ListMessageResponse> ListMessageRequestAsync(ListMessageRequest requestData)
        {
            var res = await Requestor.PostStringAsync(Urls.ListMessageRequest, JsonHelper.SerializeData(requestData));

            return(JsonConvert.DeserializeObject <ListMessageResponse>(res.ResponseJson));
        }
Пример #4
0
 /// <summary>
 /// Begin a new ListMessageRequest
 /// </summary>
 /// <param name="requestData"></param>
 /// <returns></returns>
 public ListMessageResponse ListMessageRequest(ListMessageRequest requestData)
 {
     return(JsonConvert.DeserializeObject <ListMessageResponse>(Requestor.PostString(Urls.ListMessageRequest, JsonHelper.SerializeData(requestData)).ResponseJson));
 }