public ActionResult Add(DaftarHargaOnCall model) { //validasi kondisi int idx = 0; foreach (DaftarHargaKondisi item in model.listKondisi.Where(d => d.IsDelete == false)) { if (item.kondisi != "Biaya Multidrop" && item.IsDefault == true && item.IsInclude == true && item.IsBill == false && item.value == null) { ModelState.AddModelError("listKondisi[" + idx + "].value", "Nilai harus diisi."); } if (item.kondisi == "Biaya Multidrop" && item.IsKota == true && item.ValKota == null) { ModelState.AddModelError("listKondisi[" + idx + "].ValKota", "Nilai harus diisi."); } if (item.kondisi == "Biaya Multidrop" && item.IsTitik == true && item.ValTitik == null) { ModelState.AddModelError("listKondisi[" + idx + "].ValTitik", "Nilai harus diisi."); } if (item.IsDefault == false) { if (item.kondisi == "" || item.kondisi == null) { ModelState.AddModelError("listKondisi[" + idx + "].kondisi", "Nama kondisi harus diisi."); } if (item.IsInclude == true && item.IsBill == false && item.value == null) { ModelState.AddModelError("listKondisi[" + idx + "].value", "Nilai harus diisi."); } } idx++; } DaftarHargaOnCallItem[] result = JsonConvert.DeserializeObject <DaftarHargaOnCallItem[]>(model.StrItem); model.listItem = result.ToList(); DaftarHargaOnCallAttachment[] resultAtt = JsonConvert.DeserializeObject <DaftarHargaOnCallAttachment[]>(model.StrAttachment); model.listAtt = resultAtt.ToList(); if (ModelState.IsValid) { bool palid = true; if (RepoDHO.IsPeriodValid(model.PeriodStart.Value, model.PeriodEnd.Value, model.IdCust.Value)) { ModelState.AddModelError("PeriodStart", "Periode awal tidak boleh overlaping."); ModelState.AddModelError("PeriodEnd", "Periode akhir tidak boleh overlaping."); palid = false; } if (!palid) { return(View("Form", model)); } Context.DaftarHargaOnCall dbitem = new Context.DaftarHargaOnCall(); model.setDb(dbitem); RepoDHO.save(dbitem); return(RedirectToAction("Index")); } return(View("Form", model)); }
public ActionResult Edit(DaftarHargaOnCall model) { //validasi kondisi int idx = 0; foreach (DaftarHargaKondisi item in model.listKondisi.Where(d => d.IsDelete == false)) { if (item.kondisi != "Biaya Multidrop" && item.IsDefault == true && item.IsInclude == true && item.IsBill == false && item.value == null) { ModelState.AddModelError("listKondisi[" + idx + "].value", "Nilai harus diisi."); } if (item.kondisi == "Biaya Multidrop" && item.IsKota == true && item.ValKota == null) { ModelState.AddModelError("listKondisi[" + idx + "].ValKota", "Nilai harus diisi."); } if (item.kondisi == "Biaya Multidrop" && item.IsTitik == true && item.ValTitik == null) { ModelState.AddModelError("listKondisi[" + idx + "].ValTitik", "Nilai harus diisi."); } if (item.IsDefault == false) { if (item.kondisi == "" || item.kondisi == null) { ModelState.AddModelError("listKondisi[" + idx + "].kondisi", "Nama kondisi harus diisi."); } if (item.IsInclude == true && item.IsBill == false && item.value == null) { ModelState.AddModelError("listKondisi[" + idx + "].value", "Nilai harus diisi."); } } idx++; } if (RepoDHO.IsPeriodValid(model.PeriodStart.Value, model.PeriodEnd.Value, model.IdCust.Value, model.Id)) { ModelState.AddModelError("PeriodStart", "Periode awal tidak boleh overlaping."); ModelState.AddModelError("PeriodEnd", "Periode akhir tidak boleh overlaping."); } //if (RepoDHO.IsUsedPrices(model.Id)) //{ // //ModelState.AddModelError("PeriodStart", "Periode awal tidak boleh overlaping."); // ViewBag.errorMsg = "Daftar Harga sudah digunakan, Proses tidak dapat dilanjutkan"; // return View("Form", model); //} if (ModelState.IsValid) { Context.DaftarHargaOnCall dbitem = RepoDHO.FindByPK(model.Id); model.setDb(dbitem); RepoDHO.save(dbitem); return(RedirectToAction("Index")); } ViewBag.name = model.NamaCustomer; DaftarHargaOnCallItem[] result = JsonConvert.DeserializeObject <DaftarHargaOnCallItem[]>(model.StrItem); model.listItem = result.ToList(); DaftarHargaOnCallAttachment[] resultAtt = JsonConvert.DeserializeObject <DaftarHargaOnCallAttachment[]>(model.StrAttachment); model.listAtt = resultAtt.ToList(); return(View("Form", model)); }