diff --git a/Controllers/ReduksiSampah/KompostingController.cs b/Controllers/ReduksiSampah/KompostingController.cs index bbc57a5..4e94e83 100644 --- a/Controllers/ReduksiSampah/KompostingController.cs +++ b/Controllers/ReduksiSampah/KompostingController.cs @@ -14,14 +14,47 @@ namespace BankSampahApp.Controllers.ReduksiSampah } [HttpGet] - public IActionResult Table([FromQuery] string? bulan) + public IActionResult Table([FromQuery] string? bulan, [FromQuery] string? tahun) { var data = ReduksiSampahDataStore .GetItems(Jenis) - .Where(item => ReduksiSampahDataStore.MatchesBulan(item, bulan)) - .Select(ReduksiSampahDataStore.ToResponse); + .Where(item => ReduksiSampahDataStore.MatchesPeriode(item, bulan, tahun)) + .Select(ReduksiSampahDataStore.ToDetailedResponse); return Json(new { data }); } + + [HttpPost] + public IActionResult Update([FromBody] MaggotController.MaggotUpdateRequest request) + { + if (request == null) + { + return BadRequest(new { message = "Permintaan tidak valid." }); + } + + var updated = ReduksiSampahDataStore.UpdateReduksiValues( + Jenis, + request.Id, + request.Status, + request.B1, + request.B2, + request.B3, + request.B4, + request.B5, + request.B6, + request.B7, + request.B8, + request.B9, + request.B10, + request.B11, + request.B12); + + if (!updated) + { + return NotFound(new { message = "Data komposting tidak ditemukan." }); + } + + return Ok(new { message = "Data komposting berhasil diperbarui." }); + } } } diff --git a/Controllers/ReduksiSampah/MaggotController.cs b/Controllers/ReduksiSampah/MaggotController.cs index 53990d1..1cfe3d2 100644 --- a/Controllers/ReduksiSampah/MaggotController.cs +++ b/Controllers/ReduksiSampah/MaggotController.cs @@ -14,14 +14,65 @@ namespace BankSampahApp.Controllers.ReduksiSampah } [HttpGet] - public IActionResult Table([FromQuery] string? bulan) + public IActionResult Table([FromQuery] string? bulan, [FromQuery] string? tahun) { var data = ReduksiSampahDataStore .GetItems(Jenis) - .Where(item => ReduksiSampahDataStore.MatchesBulan(item, bulan)) - .Select(ReduksiSampahDataStore.ToResponse); + .Where(item => ReduksiSampahDataStore.MatchesPeriode(item, bulan, tahun)) + .Select(ReduksiSampahDataStore.ToDetailedResponse); return Json(new { data }); } + + [HttpPost] + public IActionResult Update([FromBody] MaggotUpdateRequest request) + { + if (request == null) + { + return BadRequest(new { message = "Permintaan tidak valid." }); + } + + var updated = ReduksiSampahDataStore.UpdateReduksiValues( + Jenis, + request.Id, + request.Status, + request.B1, + request.B2, + request.B3, + request.B4, + request.B5, + request.B6, + request.B7, + request.B8, + request.B9, + request.B10, + request.B11, + request.B12); + + if (!updated) + { + return NotFound(new { message = "Data maggot tidak ditemukan." }); + } + + return Ok(new { message = "Data maggot berhasil diperbarui." }); + } + + public class MaggotUpdateRequest + { + public int Id { get; set; } + public string? Status { get; set; } + public decimal? B1 { get; set; } + public decimal? B2 { get; set; } + public decimal? B3 { get; set; } + public decimal? B4 { get; set; } + public decimal? B5 { get; set; } + public decimal? B6 { get; set; } + public decimal? B7 { get; set; } + public decimal? B8 { get; set; } + public decimal? B9 { get; set; } + public decimal? B10 { get; set; } + public decimal? B11 { get; set; } + public decimal? B12 { get; set; } + } } } diff --git a/Controllers/ReduksiSampah/ReduksiSampahDataStore.cs b/Controllers/ReduksiSampah/ReduksiSampahDataStore.cs index 83551f3..95d6dd0 100644 --- a/Controllers/ReduksiSampah/ReduksiSampahDataStore.cs +++ b/Controllers/ReduksiSampah/ReduksiSampahDataStore.cs @@ -16,7 +16,25 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Maggot", BeratReduksi = 8, BeratSampah = 15, - Alamat = AddressBlock("Tanah Abang", "Cideng", "002", "001") + Kecamatan = "Tanah Abang", + Kelurahan = "Cideng", + Rt = "002", + Rw = "001", + DetailAlamat = "Jl. Kebersihan No. 12", + Status = "Aktif", + B1 = 12.5m, + B2 = 13.2m, + B3 = 11.8m, + B4 = 14.4m, + B5 = 15.1m, + B6 = 12.9m, + B7 = 13.5m, + B8 = 12.3m, + B9 = 14.1m, + B10 = 13.7m, + B11 = 12.8m, + B12 = 13.0m, + Alamat = AddressBlock("Tanah Abang", "Cideng", "002", "001", "Jl. Kebersihan No. 12") }, new() { @@ -26,7 +44,25 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Maggot", BeratReduksi = 10, BeratSampah = 20, - Alamat = AddressBlock("Palmerah", "Kemanggisan", "003", "004") + Kecamatan = "Palmerah", + Kelurahan = "Kemanggisan", + Rt = "003", + Rw = "004", + DetailAlamat = "Jl. Kemanggisan Raya No. 9", + Status = "Aktif", + B1 = 10.2m, + B2 = 11.4m, + B3 = 10.8m, + B4 = 12.6m, + B5 = 13.3m, + B6 = 11.9m, + B7 = 12.8m, + B8 = 11.1m, + B9 = 12.4m, + B10 = 11.9m, + B11 = 11.4m, + B12 = 12.0m, + Alamat = AddressBlock("Palmerah", "Kemanggisan", "003", "004", "Jl. Kemanggisan Raya No. 9") }, new() { @@ -36,7 +72,25 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Maggot", BeratReduksi = 7, BeratSampah = 14, - Alamat = AddressBlock("Tebet", "Manggarai", "001", "002") + Kecamatan = "Tebet", + Kelurahan = "Manggarai", + Rt = "001", + Rw = "002", + DetailAlamat = "Jl. Manggarai Utara No. 7", + Status = "Tidak Aktif", + B1 = 9.5m, + B2 = 9.9m, + B3 = 10.1m, + B4 = 10.5m, + B5 = 10.2m, + B6 = 9.7m, + B7 = 9.9m, + B8 = 10.0m, + B9 = 9.8m, + B10 = 10.1m, + B11 = 9.6m, + B12 = 9.9m, + Alamat = AddressBlock("Tebet", "Manggarai", "001", "002", "Jl. Manggarai Utara No. 7") }, new() { @@ -46,7 +100,25 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Maggot", BeratReduksi = 6, BeratSampah = 12, - Alamat = AddressBlock("Cakung", "Jatinegara", "004", "006") + Kecamatan = "Cakung", + Kelurahan = "Jatinegara", + Rt = "004", + Rw = "006", + DetailAlamat = "Jl. Industri Hijau No. 5", + Status = "Aktif", + B1 = 14.6m, + B2 = 13.9m, + B3 = 14.1m, + B4 = 14.8m, + B5 = 15.3m, + B6 = 14.5m, + B7 = 15.0m, + B8 = 14.2m, + B9 = 15.1m, + B10 = 14.7m, + B11 = 14.3m, + B12 = 14.9m, + Alamat = AddressBlock("Cakung", "Jatinegara", "004", "006", "Jl. Industri Hijau No. 5") }, new() { @@ -56,7 +128,25 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Maggot", BeratReduksi = 9, BeratSampah = 16, - Alamat = AddressBlock("Koja", "Lagoa", "005", "003") + Kecamatan = "Koja", + Kelurahan = "Lagoa", + Rt = "005", + Rw = "003", + DetailAlamat = "Jl. Lagoa Mas No. 3", + Status = "Aktif", + B1 = 11.7m, + B2 = 11.3m, + B3 = 11.1m, + B4 = 11.8m, + B5 = 12.4m, + B6 = 11.5m, + B7 = 11.9m, + B8 = 11.2m, + B9 = 12.0m, + B10 = 11.6m, + B11 = 11.3m, + B12 = 11.9m, + Alamat = AddressBlock("Koja", "Lagoa", "005", "003", "Jl. Lagoa Mas No. 3") }, new() { @@ -66,7 +156,12 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Komposting", BeratReduksi = 11, BeratSampah = 18, - Alamat = AddressBlock("Beji", "Beji Timur", "006", "002") + Kecamatan = "Beji", + Kelurahan = "Beji Timur", + Rt = "006", + Rw = "002", + DetailAlamat = "Jl. Melati Hijau No. 10", + Alamat = AddressBlock("Beji", "Beji Timur", "006", "002", "Jl. Melati Hijau No. 10") }, new() { @@ -76,7 +171,12 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Komposting", BeratReduksi = 13, BeratSampah = 21, - Alamat = AddressBlock("Bekasi Timur", "Margahayu", "009", "005") + Kecamatan = "Bekasi Timur", + Kelurahan = "Margahayu", + Rt = "009", + Rw = "005", + DetailAlamat = "Jl. Margahayu Harmonis No. 8", + Alamat = AddressBlock("Bekasi Timur", "Margahayu", "009", "005", "Jl. Margahayu Harmonis No. 8") }, new() { @@ -86,7 +186,12 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Komposting", BeratReduksi = 9, BeratSampah = 15, - Alamat = AddressBlock("Bogor Utara", "Kedunghalang", "001", "004") + Kecamatan = "Bogor Utara", + Kelurahan = "Kedunghalang", + Rt = "001", + Rw = "004", + DetailAlamat = "Jl. Kedunghalang Sejahtera No. 2", + Alamat = AddressBlock("Bogor Utara", "Kedunghalang", "001", "004", "Jl. Kedunghalang Sejahtera No. 2") }, new() { @@ -96,7 +201,12 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Komposting", BeratReduksi = 8, BeratSampah = 13, - Alamat = AddressBlock("Karawaci", "Nusa Jaya", "008", "003") + Kecamatan = "Karawaci", + Kelurahan = "Nusa Jaya", + Rt = "008", + Rw = "003", + DetailAlamat = "Jl. Nusa Jaya Indah No. 11", + Alamat = AddressBlock("Karawaci", "Nusa Jaya", "008", "003", "Jl. Nusa Jaya Indah No. 11") }, new() { @@ -106,7 +216,12 @@ namespace BankSampahApp.Controllers.ReduksiSampah JenisLokasi = "Komposting", BeratReduksi = 12, BeratSampah = 19, - Alamat = AddressBlock("Ciwandan", "Kebonsari", "010", "002") + Kecamatan = "Ciwandan", + Kelurahan = "Kebonsari", + Rt = "010", + Rw = "002", + DetailAlamat = "Jl. Kebonsari Permai No. 4", + Alamat = AddressBlock("Ciwandan", "Kebonsari", "010", "002", "Jl. Kebonsari Permai No. 4") } }; @@ -133,6 +248,21 @@ namespace BankSampahApp.Controllers.ReduksiSampah return item.PeriodeBulan.Contains(bulan.Trim(), StringComparison.OrdinalIgnoreCase); } + public static bool MatchesPeriode(ReduksiSampahItem item, string? bulan, string? tahun) + { + if (!MatchesBulan(item, bulan)) + { + return false; + } + + if (string.IsNullOrWhiteSpace(tahun)) + { + return true; + } + + return item.PeriodeBulan.EndsWith(tahun.Trim(), StringComparison.OrdinalIgnoreCase); + } + public static object ToResponse(ReduksiSampahItem item) => new { id = item.Id, @@ -146,7 +276,78 @@ namespace BankSampahApp.Controllers.ReduksiSampah aksi = ActionButtons }; - private static string AddressBlock(string kecamatan, string kelurahan, string rt, string rw) + public static object ToDetailedResponse(ReduksiSampahItem item) => new + { + id = item.Id, + periode = item.PeriodeBulan, + kecamatan = item.Kecamatan, + kelurahan = item.Kelurahan, + rt = item.Rt, + rw = item.Rw, + detail_alamat = item.DetailAlamat, + status = item.Status, + b1 = item.B1, + b2 = item.B2, + b3 = item.B3, + b4 = item.B4, + b5 = item.B5, + b6 = item.B6, + b7 = item.B7, + b8 = item.B8, + b9 = item.B9, + b10 = item.B10, + b11 = item.B11, + b12 = item.B12 + }; + + public static bool UpdateReduksiValues( + string jenisLokasi, + int id, + string? status, + decimal? b1, + decimal? b2, + decimal? b3, + decimal? b4, + decimal? b5, + decimal? b6, + decimal? b7, + decimal? b8, + decimal? b9, + decimal? b10, + decimal? b11, + decimal? b12) + { + var item = Items.FirstOrDefault(x => + x.Id == id && + string.Equals(x.JenisLokasi, jenisLokasi, StringComparison.OrdinalIgnoreCase)); + + if (item == null) + { + return false; + } + + if (!string.IsNullOrWhiteSpace(status)) + { + item.Status = status; + } + + if (b1.HasValue) item.B1 = b1.Value; + if (b2.HasValue) item.B2 = b2.Value; + if (b3.HasValue) item.B3 = b3.Value; + if (b4.HasValue) item.B4 = b4.Value; + if (b5.HasValue) item.B5 = b5.Value; + if (b6.HasValue) item.B6 = b6.Value; + if (b7.HasValue) item.B7 = b7.Value; + if (b8.HasValue) item.B8 = b8.Value; + if (b9.HasValue) item.B9 = b9.Value; + if (b10.HasValue) item.B10 = b10.Value; + if (b11.HasValue) item.B11 = b11.Value; + if (b12.HasValue) item.B12 = b12.Value; + + return true; + } + + private static string AddressBlock(string kecamatan, string kelurahan, string rt, string rw, string detailAlamat) { return $@"
@@ -156,6 +357,7 @@ namespace BankSampahApp.Controllers.ReduksiSampah RT {rt} RW {rw}
+ {detailAlamat} "; } @@ -165,9 +367,27 @@ namespace BankSampahApp.Controllers.ReduksiSampah public string PeriodeBulan { get; set; } = string.Empty; public string NamaLokasi { get; set; } = string.Empty; public string Alamat { get; set; } = string.Empty; + public string DetailAlamat { get; set; } = string.Empty; + public string Kecamatan { get; set; } = string.Empty; + public string Kelurahan { get; set; } = string.Empty; + public string Rt { get; set; } = string.Empty; + public string Rw { get; set; } = string.Empty; public string JenisLokasi { get; set; } = string.Empty; + public string Status { get; set; } = "Aktif"; public double BeratReduksi { get; set; } public double BeratSampah { get; set; } + public decimal B1 { get; set; } + public decimal B2 { get; set; } + public decimal B3 { get; set; } + public decimal B4 { get; set; } + public decimal B5 { get; set; } + public decimal B6 { get; set; } + public decimal B7 { get; set; } + public decimal B8 { get; set; } + public decimal B9 { get; set; } + public decimal B10 { get; set; } + public decimal B11 { get; set; } + public decimal B12 { get; set; } } } } diff --git a/Views/ReduksiSampah/Komposting/Index.cshtml b/Views/ReduksiSampah/Komposting/Index.cshtml index e957d1e..bd1b037 100644 --- a/Views/ReduksiSampah/Komposting/Index.cshtml +++ b/Views/ReduksiSampah/Komposting/Index.cshtml @@ -1,253 +1,204 @@ @{ - var jenis = "Komposting"; - var tableUrl = Url.Content("~/ReduksiSampah/Komposting/Table"); - ViewData["Title"] = $"Reduksi Sampah - {jenis}"; +var jenis = "Komposting"; +var tableUrl = Url.Content("~/ReduksiSampah/Komposting/Table"); +ViewData["Title"] = $"Reduksi Sampah - {jenis}"; }
-
+
Reduksi Sampah - @jenis
-
- + + + + - + + +
- - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + +
- +
- - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -257,166 +208,232 @@ - @section Scripts { } \ No newline at end of file diff --git a/Views/ReduksiSampah/Maggot/Index.cshtml b/Views/ReduksiSampah/Maggot/Index.cshtml index 65e845b..3c5bc51 100644 --- a/Views/ReduksiSampah/Maggot/Index.cshtml +++ b/Views/ReduksiSampah/Maggot/Index.cshtml @@ -5,249 +5,200 @@ ViewData["Title"] = $"Reduksi Sampah - {jenis}"; }
-
+
Reduksi Sampah - @jenis
-
- + + + + - + + +
- - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + +
-
NoPeriodeNama LokasiAlamatJenis LokasiBerat Reduksi (Kg)Berat Sampah (Kg)Bukti KegiatanAksiNoLokasi Rumah KompostingStatusJumlah Sampah yang di Reduksi (Kg/Bulan)Aksi
KecamatanKelurahanRTRWDetail AlamatB1B2B3B4B5B6B7B8B9B10B11B12
- +
+ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -257,166 +208,229 @@ ViewData["Title"] = $"Reduksi Sampah - {jenis}"; - @section Scripts { } \ No newline at end of file diff --git a/Views/Shared/_LayoutApp.cshtml b/Views/Shared/_LayoutApp.cshtml index 8f760b6..282b39e 100644 --- a/Views/Shared/_LayoutApp.cshtml +++ b/Views/Shared/_LayoutApp.cshtml @@ -39,6 +39,7 @@ + @await RenderSectionAsync("Styles", required: false) @@ -69,6 +70,7 @@ + diff --git a/Views/Shared/_LayoutAppWithoutNavbar.cshtml b/Views/Shared/_LayoutAppWithoutNavbar.cshtml index 6e2f0d0..4f9e3ea 100644 --- a/Views/Shared/_LayoutAppWithoutNavbar.cshtml +++ b/Views/Shared/_LayoutAppWithoutNavbar.cshtml @@ -39,6 +39,7 @@ + @await RenderSectionAsync("Styles", required: false) @@ -63,6 +64,7 @@ +
NoPeriodeNama LokasiAlamatJenis LokasiBerat Reduksi (Kg)Berat Sampah (Kg)Bukti KegiatanAksiNoLokasi Rumah KompostingStatusJumlah Sampah yang di Reduksi (Kg/Bulan)Aksi
KecamatanKelurahanRTRWDetail AlamatB1B2B3B4B5B6B7B8B9B10B11B12