Esempio n. 1
0
        public Response <ListPermohonanResponse[]> listpermohonan([FromBody] FilterPermohonanRequest request)
        {
            string userlogin = string.Empty;
            string token     = Request.Headers["Authorization"];

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

            if (!string.IsNullOrEmpty(info.Username))
            {
                return(this.bantuanHukumService.listpermohonan(request));
            }
            else
            {
                response.message = "Unauthorize";
            }
            return(response);
        }
        private IQueryable <ListPermohonanResponse> mainQueryHeader(FilterPermohonanRequest request)
        {
            IQueryable <HeaderConversation> datas = from x in this.Db.BantuanHukum
                                                    select new HeaderConversation {
                HeaderID      = x.ID,
                Status        = x.LastStatus.ID,
                CreatedDate   = x.CreatedDate,
                KodeLaporan   = x.KodeLaporan,
                IsiPermohonan = x.IsiPermohonan
            };

            if (!string.IsNullOrWhiteSpace(request.TanggalMulai) && !string.IsNullOrWhiteSpace(request.TanggalAkhir))
            {
                // Filter By Date
                DateTime dtstart = DateTime.Parse(request.TanggalMulai.ToString());
                DateTime dtend   = DateTime.Parse(request.TanggalAkhir.ToString());
                datas = datas.Where(a => a.CreatedDate >= dtstart && a.CreatedDate <= dtend);
            }

            IQueryable <HeaderConversation> queries = from x in datas
                                                      from z in this.Db.Conversations
                                                      where
                                                      x.HeaderID == z.Header.ID
                                                      select new HeaderConversation {
                HeaderID = x.HeaderID, Status = z.Status.ID, KodeLaporan = x.KodeLaporan, IsiPermohonan = x.IsiPermohonan
            };

            // Filter By KodeLaporan
            if (!string.IsNullOrWhiteSpace(request.KodeLaporan))
            {
                queries = queries.Where(a => a.KodeLaporan == request.KodeLaporan);
            }

            // Search By Content
            if (!string.IsNullOrWhiteSpace(request.Konten))
            {
                queries = queries.Where(a => a.IsiPermohonan.Contains(request.Konten));
            }

            // Filter By Status
            if (request.Status != null && request.Status.Count() > 0)
            {
                queries = from x in queries
                          from y in request.Status
                          where x.Status == y
                          select x;
            }

            //  Grouping By Header
            var groupHeader = from x in queries
                              group x by x.HeaderID
                              into grp
                              select new GroupingByStatus {
                ID = grp.Key, Status =

                    (from st in  (from yw in grp.Select(a => a.Status) group yw by yw into ywg select ywg)
                     from stm in this.Db.StatusBantuan
                     where st.Key == stm.ID select new StatusBantuanRow {
                    ID = stm.ID, Name = stm.Name
                })
            };

            //  var groupByStatus = from x in groupHeader.
            IQueryable <ListPermohonanResponse> response = from g in groupHeader
                                                           from header in this.Db.BantuanHukum
                                                           from country in this.Db.Countries

                                                           where g.ID == header.ID &&
                                                           header.Kewarganegaraan.CountryID == country.CountryID
                                                           select new ListPermohonanResponse {
                ID                  = g.ID,
                KodeLaporan         = header.KodeLaporan,
                Tanggal             = header.CreatedDate,
                IsLaporanDiproses   = (g.Status.Where(a => a.ID == 1).Count() > 0),
                IsLaporanDiterima   = (g.Status.Where(a => a.ID == 2).Count() > 0),
                IsLaporanDianalisa  = (g.Status.Where(a => a.ID == 3).Count() > 0),
                IsLaporanDitolak    = (g.Status.Where(a => a.ID == 4).Count() > 0),
                IsLaporanSelesai    = (g.Status.Where(a => a.ID == 5).Count() > 0),
                NamaLengkap         = header.NamaLengkap,
                Umur                = header.Umur,
                Pekerjaan           = header.Pekerjaan,
                JenisKelamin        = header.JenisKelamin,
                Agama               = header.Agama,
                Kewarganegaraan     = header.Kewarganegaraan.CountryID,
                Telpn               = header.Telpn,
                Identitas           = header.Identitas,
                NoIdentitas         = header.NoIdentitas,
                Email               = header.Email,
                IsiPermohonan       = header.IsiPermohonan,
                FileName            = header.FileName,
                KewarganegaraanText = country.Name
            };

            return(response);
        }
        public Response <ListPermohonanResponse[]> listpermohonan(FilterPermohonanRequest request)
        {
            Response <ListPermohonanResponse[]> response = new Response <ListPermohonanResponse[]>();

            try
            {
                // Main Query
                IQueryable <ListPermohonanResponse> mainQuery = this.mainQueryHeader(request);

                // Sorting Asc or Descending
                switch (request.SortField)
                {
                case "KodeLaporan_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.KodeLaporan);
                    break;

                case "KodeLaporan_asc":
                    mainQuery = mainQuery.OrderBy(a => a.KodeLaporan);
                    break;

                case "IsiPermohonan_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.IsiPermohonan);
                    break;

                case "IsiPermohonan_asc":
                    mainQuery = mainQuery.OrderBy(a => a.IsiPermohonan);
                    break;

                case "Tanggal_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.Tanggal);
                    break;

                case "Tanggal_asc":
                    mainQuery = mainQuery.OrderBy(a => a.Tanggal);
                    break;

                case "IsLaporanDitolak_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.IsLaporanDitolak);
                    break;

                case "IsLaporanDitolak_asc":
                    mainQuery = mainQuery.OrderBy(a => a.IsLaporanDitolak);
                    break;

                case "IsLaporanDianalisa_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.IsLaporanDianalisa);
                    break;

                case "IsLaporanDianalisa_asc":
                    mainQuery = mainQuery.OrderBy(a => a.IsLaporanDianalisa);
                    break;

                case "IsLaporanDiproses_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.IsLaporanDiproses);
                    break;

                case "IsLaporanDiproses_asc":
                    mainQuery = mainQuery.OrderBy(a => a.IsLaporanDiproses);
                    break;

                case "IsLaporanDiterima_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.IsLaporanDiterima);
                    break;

                case "IsLaporanDiterima_asc":
                    mainQuery = mainQuery.OrderBy(a => a.IsLaporanDiterima);
                    break;

                case "IsLaporanSelesai_desc":
                    mainQuery = mainQuery.OrderByDescending(a => a.IsLaporanSelesai);
                    break;

                case "IsLaporanSelesai_asc":
                    mainQuery = mainQuery.OrderBy(a => a.IsLaporanSelesai);
                    break;

                default:
                    mainQuery = mainQuery.OrderBy(a => a.KodeLaporan);
                    break;
                }


                // Paging
                var count = mainQuery.Count();
                var items = mainQuery.Skip((request.pageIndex - 1) * request.pageSize).Take(request.pageSize).ToArray();

                response.data = items;

                // Property Information for javascript client
                response.count      = count;
                response.totalpages = (int)Math.Ceiling(count / (double)request.pageSize);
                response.totalpages = response.totalpages < 0 ? 1 : response.totalpages;
            }
            catch (Exception exc)
            {
                response.message      = exc.Message;
                response.message_type = 2;
            }

            return(response);
        }