public void Add(Pengaduan item) { if(item.Id==null) { if (Save(item)) { item.Distrik = DataBasic.GetKecamatan().Where(x => x.Id == item.KodeDistrik).FirstOrDefault(); this.list.Add(item); if (OnChange != null) OnChange(true); } } else { Save(item); } }
public PengaduanServices() { using (var db = new DbContext()) { try { var aaa = db.DataPengaduan.Select(); var data = from pengaduan in db.DataPengaduan.Select() join dis in DataBasic.GetKecamatan() on pengaduan.KodeDistrik equals dis.Id join pelapor in db.DataPelapor.Select().DefaultIfEmpty() on pengaduan.Id equals pelapor.PengaduanId join dampak in db.DataDampak.Select().DefaultIfEmpty() on pengaduan.Id equals dampak.PengaduanId join kondisi in db.DataKondisiKorban.Select().DefaultIfEmpty() on pengaduan.Id equals kondisi.PengaduanId select new Pengaduan() { StatusPelapor = pengaduan.StatusPelapor, StatusPelaporText = pengaduan.StatusPelaporText, TanggalKejadian = pengaduan.TanggalKejadian, TempatKejadian = pengaduan.TempatKejadian, WaktuKejadian = pengaduan.WaktuKejadian, KodeDistrik = pengaduan.KodeDistrik, Distrik = dis, Catatan = pengaduan.Catatan, Id = pengaduan.Id, Nomor = pengaduan.Nomor, Penerima = pengaduan.Penerima, Rujukan = pengaduan.Rujukan, TanggalLapor = pengaduan.TanggalLapor, WaktuLapor = pengaduan.WaktuLapor, UraianKejadian = pengaduan.UraianKejadian, TempatLapor = pengaduan.TempatLapor, Dampak = dampak, Kondisi = kondisi, Pelapor = pelapor, }; if (data.Count() >0) { foreach (var item in data) { var id = item.Id.Value; item.Korban = db.DataKorban.Where(x => x.PengaduanId == id).ToList(); foreach (var korban in item.Korban) { var penangananKorban = from a in db.Penanganan.Where(x => x.IdentiasId == korban.Id && x.IdentitasType == "Korban") join i in db.Instansi.Select().DefaultIfEmpty() on a.InstansiId equals i.Id select new Penanganan { DataIdentias = korban, Deskripsi = a.Deskripsi, DetailLayanan = a.DetailLayanan, IdPenanganan = a.IdPenanganan, IdentiasId = a.IdentiasId, IdentitasType = a.IdentitasType, InstansiId = a.InstansiId, Instansi = i, Layanan = a.Layanan, Tanggal = a.Tanggal }; korban.DataPenanganan = penangananKorban.ToList(); } item.Terlapor = db.DataTerlapor.Where(x => x.PengaduanId == id).ToList(); foreach (var terlapor in item.Terlapor) { var penangananKorban = from a in db.Penanganan.Where(x => x.IdentiasId == terlapor.Id && x.IdentitasType == "Terlapor") join i in db.Instansi.Select().DefaultIfEmpty() on a.InstansiId equals i.Id select new Penanganan { DataIdentias = terlapor, Deskripsi = a.Deskripsi, DetailLayanan = a.DetailLayanan, IdPenanganan = a.IdPenanganan, IdentiasId = a.IdentiasId, IdentitasType = a.IdentitasType, InstansiId = a.InstansiId, Instansi = i, Layanan = a.Layanan, Tanggal = a.Tanggal }; terlapor.DataPenanganan = penangananKorban.ToList(); var hubs = from a in db.DataHubungan.Where(x => x.TerlaporId == terlapor.Id) join b in item.Korban on a.KorbanId equals b.Id select new HubunganDenganKorban(terlapor.Id, b) { Id = a.Id, Korban = b, KorbanId = a.Id, JenisHubungan = a.JenisHubungan, TerlaporId = a.TerlaporId }; terlapor.Hubungan = hubs.ToList(); } list.Add(item); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }