public ActionResult Edit(int id)
        {
            Context.DaftarHargaKonsolidasi dbitem = RepoDHKonsolidasi.FindByPK(id);
            DaftarHargaKonsolidasi         model  = new DaftarHargaKonsolidasi(dbitem);

            ViewBag.name = model.NamaCustomer;
            return(View("Form", model));
        }
Ejemplo n.º 2
0
        public void save(DaftarHargaKonsolidasi dbitem, int id, string dhki = null)
        {
            var query = "";

            if (dbitem.Id == 0) //create
            {
                context.DaftarHargaKonsolidasi.Add(dbitem);
                query += "INSERT INTO dbo.\"DaftarHargaKonsolidasi\" (\"IdCust\", \"PeriodStart\", \"PeriodEnd\") VALUES (" + dbitem.IdCust + ", " + dbitem.PeriodStart + ", " + dbitem.PeriodEnd + ");";
            }
            else //edit
            {
                context.DaftarHargaKonsolidasi.Attach(dbitem);
                query += "UPDATE dbo.\"DaftarHargaKonsolidasi\" SET \"IdCust\" = " + dbitem.IdCust + ", \"PeriodStart\" = " + dbitem.PeriodStart + ", \"PeriodEnd\" = " + dbitem.PeriodEnd +
                         " WHERE \"Id\" = " + dbitem.Id + ";";
                var entry = context.Entry(dbitem);
                entry.State = EntityState.Modified;
            }
            context.SaveChanges();
            query += "DELETE FROM dbo.\"DaftarHargaKonsolidasiAttachment\" WHERE \"IdDaftarHargaKonsolidasi\" = " + dbitem.Id + ";";
            foreach (Context.DaftarHargaKonsolidasiAttachment dhka in dbitem.DaftarHargaKonsolidasiAttachment)
            {
                query += "INSERT INTO dbo.\"DaftarHargaKonsolidasiAttachment\" (\"IdDaftarHargaKonsolidasi\", \"FileName\", \"RFileName\") VALUES (" + dbitem.Id + ", " + dhka.FileName + ", " + dhka.RFileName + ");";
            }
            query += "DELETE FROM dbo.\"DaftarHargaKonsolidasiKondisi\" WHERE \"IdDaftarHargaKonsolidasi\" = " + dbitem.Id + ";";
            foreach (Context.DaftarHargaKonsolidasiKondisi dhkk in dbitem.DaftarHargaKonsolidasiKondisi)
            {
                query += "INSERT INTO dbo.\"DaftarHargaKonsolidasiKondisi\" (\"IdDaftarHargaKonsolidasi\", kondisi, \"IsInclude\", \"IsBill\", value, \"IsDefault\", \"IsKota\", \"IsTitik\", " +
                         "\"ValKota\", \"ValTitik\", \"IsDelete\") VALUES (" + dhkk.Id + ", " + dhkk.kondisi + ", " + dhkk.IsInclude + ", " + dhkk.IsBill + ", " + dhkk.value + ", " + dhkk.IsDefault + ", " +
                         dhkk.IsKota + ", " + dhkk.IsTitik + ", " + dhkk.ValKota + ", " + dhkk.ValTitik + ", " + dhkk.IsDelete + ");";
            }
            if (dbitem.Id == 0) //create
            {
                context.DaftarHargaKonsolidasi.Add(dbitem);
                foreach (Context.DaftarHargaKonsolidasiItem item in dbitem.DaftarHargaKonsolidasiItem)
                {
                    query += "INSERT INTO dbo.\"DaftarHargaKonsolidasiItem\" (\"IdDaftarHargaKonsolidasi\", \"NamaDaftarHargaRute\", \"ListIdRute\", \"ListNamaRute\", \"IdJenisKendaraan\", " +
                             "\"MinKg\", \"MaxKg\", \"Harga\", \"IsAsuransi\", \"Premi\", \"NilaiTanggungan\", \"Keterangan\", \"PihakPenanggung\", \"TipeNilaiTanggungan\", \"IdSatuanHarga\") VALUES ( " +
                             dbitem.Id + ", " + item.NamaDaftarHargaRute + ", " + item.ListIdRute + ", " + item.ListNamaRute + ", " + item.IdJenisKendaraan + ", " + item.MinKg + ", " + item.MaxKg + ", " +
                             item.Harga + ", " + item.IsAsuransi + ", " + item.Premi + ", " + item.NilaiTanggungan + ", " + item.Keterangan + ", " + item.PihakPenanggung + ", " + item.TipeNilaiTanggungan +
                             ", " + item.IdSatuanHarga + ");";
                }
            }
            else
            {
                query += dhki;
            }
            var auditrail = new Auditrail {
                Actionnya     = dbitem.Id == 0 ? "Add" : "Edit", EventDate = DateTime.Now, Modulenya = "Daftar Harga Konsolidasi", QueryDetail = query,
                RemoteAddress = AppHelper.GetIPAddress(), IdUser = id
            };

            context.Auditrail.Add(auditrail);
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public void delete(DaftarHargaKonsolidasi dbitem, int id)
        {
            context.DaftarHargaKonsolidasi.Remove(dbitem);
            var query     = "DELETE FROM dbo.\"DaftarHargaKonsolidasi\" WHERE \"Id\" = " + dbitem.Id + ";";
            var auditrail = new Auditrail {
                Actionnya = "Delete", EventDate = DateTime.Now, Modulenya = "Harga Konsolidasi", QueryDetail = query, RemoteAddress = AppHelper.GetIPAddress(), IdUser = id
            };

            context.Auditrail.Add(auditrail);
            context.SaveChanges();
        }
Ejemplo n.º 4
0
 public void FindRuteTruk(int id, out string IdRute, out int idJenisTruk)
 {
     try
     {
         DaftarHargaKonsolidasi     db     = context.DaftarHargaKonsolidasi.Where(d => d.DaftarHargaKonsolidasiItem.Any(i => i.Id == id)).FirstOrDefault();
         DaftarHargaKonsolidasiItem dbitem = db.DaftarHargaKonsolidasiItem.Where(i => i.Id == id).FirstOrDefault();
         IdRute      = dbitem.ListIdRute;
         idJenisTruk = dbitem.IdJenisKendaraan.Value;
     }
     catch (Exception)
     {
         IdRute      = "";
         idJenisTruk = -1;
     }
 }
        public ActionResult Add(DaftarHargaKonsolidasi model)
        {
            //validasi kondisi
            DaftarHargaKonsolidasiItem[] result = JsonConvert.DeserializeObject <DaftarHargaKonsolidasiItem[]>(model.StrItem);
            model.listItem = result.ToList();

            DaftarHargaKonsolidasiAttachment[] resultAtt = JsonConvert.DeserializeObject <DaftarHargaKonsolidasiAttachment[]>(model.StrAttachment);
            model.listAtt = resultAtt.ToList();

            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 (ModelState.IsValid)
            {
                bool palid = true;
                if (RepoDHKonsolidasi.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.DaftarHargaKonsolidasi dbitem = new Context.DaftarHargaKonsolidasi();
                model.setDb(dbitem);
                RepoDHKonsolidasi.save(dbitem, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }


            return(View("Form", model));
        }
        public ActionResult Add()
        {
            DaftarHargaKonsolidasi model = new DaftarHargaKonsolidasi();

            return(View("Form", model));
        }
        public ActionResult Edit(DaftarHargaKonsolidasi 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 (RepoDHKonsolidasi.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 (ModelState.IsValid)
            {
                Context.DaftarHargaKonsolidasi dbitem = RepoDHKonsolidasi.FindByPK(model.Id);
                model.setDb(dbitem);
                DaftarHargaKonsolidasiItem[] results = JsonConvert.DeserializeObject <DaftarHargaKonsolidasiItem[]>(model.StrItem);
                List <Context.DaftarHargaKonsolidasiItem> DummyItems = dbitem.DaftarHargaKonsolidasiItem.ToList();
                List <int> ListAnuTeuDiHapus = new List <int>();
                var        query             = "";
                foreach (DaftarHargaKonsolidasiItem item in results)
                {
                    if (item.Id != 0)
                    {
                        query += "UPDATE dbo.\"DaftarHargaKonsolidasiItem\" SET \"NamaDaftarHargaRute\" = " + item.NamaRuteDaftarHarga + ", \"ListIdRute\" = " + item.ListIdRute + ", \"ListNamaRute\" = " +
                                 item.ListNamaRute + ", \"IdJenisKendaraan\" = " + item.IdJenisKendaraan + ", \"MinKg\" = " + item.MinKg + ", \"MaxKg\" = " + item.MaxKg + ", \"Harga\" = " + item.Harga +
                                 ", \"IsAsuransi\" = " + item.IsAsuransi + ", \"Premi\" = " + item.Premi + ", \"NilaiTanggungan\" = " + item.NilaiTanggungan + ", \"Keterangan\" = " + item.Keterangan +
                                 ", \"PihakPenanggung\" = " + item.PihakPenanggung + ", \"TipeNilaiTanggungan\" = " + item.TipeNilaiTanggungan + ", \"IdSatuanHarga\" = " + item.IdSatuanHarga +
                                 " WHERE \"Id\" = " + item.Id + ";";
                        ListAnuTeuDiHapus.Add(item.Id);
                    }
                    else
                    {
                        query += "INSERT INTO dbo.\"DaftarHargaKonsolidasiItem\" (\"IdDaftarHargaKonsolidasi\", \"NamaDaftarHargaRute\", \"ListIdRute\", \"ListNamaRute\", \"IdJenisKendaraan\", " +
                                 "\"MinKg\", \"MaxKg\", \"Harga\", \"IsAsuransi\", \"Premi\", \"NilaiTanggungan\", \"Keterangan\", \"PihakPenanggung\", \"TipeNilaiTanggungan\", \"IdSatuanHarga\") VALUES ( " +
                                 dbitem.Id + ", " + item.NamaRuteDaftarHarga + ", " + item.ListIdRute + ", " + item.ListNamaRute + ", " + item.IdJenisKendaraan + ", " + item.MinKg + ", " + item.MaxKg + ", " +
                                 item.Harga + ", " + item.IsAsuransi + ", " + item.Premi + ", " + item.NilaiTanggungan + ", " + item.Keterangan + ", " + item.PihakPenanggung + ", " + item.TipeNilaiTanggungan +
                                 ", " + item.IdSatuanHarga + ");";
                    }
                }
                foreach (Context.DaftarHargaKonsolidasiItem dbhapus in DummyItems)
                {
                    if (!ListAnuTeuDiHapus.Any(d => d == dbhapus.Id))
                    {
                        query += "DELETE FROM dbo.\"DaftarHargaKonsolidasiItem\" WHERE \"IdDaftarHargaKonsolidasi\" = " + dbitem.Id + ";";
                    }
                }
                RepoDHKonsolidasi.save(dbitem, UserPrincipal.id, query);

                return(RedirectToAction("Index"));
            }
            ViewBag.name = model.NamaCustomer;

            DaftarHargaKonsolidasiItem[] result = JsonConvert.DeserializeObject <DaftarHargaKonsolidasiItem[]>(model.StrItem);
            model.listItem = result.ToList();

            DaftarHargaKonsolidasiAttachment[] resultAtt = JsonConvert.DeserializeObject <DaftarHargaKonsolidasiAttachment[]>(model.StrAttachment);
            model.listAtt = resultAtt.ToList();

            return(View("Form", model));
        }