public async Task <IEnumerable <MasterAreaDto> > GetAllAsync(MasterAreaDto param)
        {
            using var context = new AppDbContext();

            IQueryable <MasterArea> query = (from area in context.MasterArea
                                             join wilayah in context.MasterWilayah on area.KodeWil equals wilayah.KodeWil into gWilayah
                                             from wilayah in gWilayah.DefaultIfEmpty()
                                             select new MasterArea()
            {
                KodeArea = area.KodeArea,
                NamaArea = area.NamaArea,
                KodeWil = area.KodeWil,
                MasterWilayah = area.MasterWilayah,
            });

            if (!string.IsNullOrWhiteSpace(param.KodeArea))
            {
                query = query.Where(n => n.KodeArea == param.KodeArea);
            }

            if (!string.IsNullOrWhiteSpace(param.NamaArea))
            {
                query = query.Where(n => EF.Functions.Like(n.NamaArea, $"%{param.NamaArea}%"));
            }

            if (!string.IsNullOrWhiteSpace(param.KodeWil))
            {
                query = query.Where(n => n.KodeWil == param.KodeWil);
            }

            var data = await query.ToListAsync();

            return(_mapper.Map <IEnumerable <MasterAreaDto> >(data));
        }
Example #2
0
        public async Task <JsonResult> GetAsync(string kodearea, string namaarea, string kodewil)
        {
            var watch = Stopwatch.StartNew();

            try
            {
                var param = new MasterAreaDto()
                {
                    KodeArea = kodearea,
                    NamaArea = namaarea,
                    KodeWil  = kodewil
                };

                AppResponse.ResponseGetData(await areaService.GetAll(param));
            }
            catch (Exception e)
            {
                AppResponse.ResponseErrorGetData(e.InnerException != null ? e.InnerException.Message : e.Message);
            }

            watch.Stop();
            AppResponse._result.execution_time = watch.ElapsedMilliseconds;
            return(new JsonResult(AppResponse._result));
        }
Example #3
0
 public async Task <IEnumerable <MasterAreaDto> > GetAll(MasterAreaDto param)
 {
     return(await area.GetAllAsync(param));
 }