Exemple #1
0
        public ActionResult SaveTransaksi(TrxViewModel trxViewModel)
        {
            TrxMasterRepo trxMasterRepo = new TrxMasterRepo();

            if (trxMasterRepo.SaveTransaksi(trxViewModel))
            {
                return(Json(new { status = "berhasil" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { status = "gagal" }, JsonRequestBehavior.AllowGet));
            }
            //return View();
            //return Json(new { status = "berhasil" }, JsonRequestBehavior.AllowGet);
        }
Exemple #2
0
        public bool SaveTransaksi(TrxViewModel trxViewModel)
        {
            try
            {
                TrxMasterModel trxMasterModel = new TrxMasterModel();
                trxMasterModel.NoFaktur     = trxViewModel.NoFaktur;
                trxMasterModel.TglTransaksi = trxViewModel.TglTransaksi;
                trxMasterModel.NamaKaryawan = trxViewModel.NamaKaryawan;
                trxMasterModel.TotalHarga   = trxViewModel.TotalHarga;
                trxMasterModel.SisaHarga    = trxViewModel.SisaHarga;
                using (DataContext context = new DataContext())
                {
                    context.trxMasterModel.Add(trxMasterModel);
                    context.SaveChanges();
                }

                //section untuk save detail
                TrxDetailModel trxDetailModel = new TrxDetailModel();
                foreach (var item in trxViewModel.trxDetail)
                {
                    trxDetailModel.NoFaktur     = trxViewModel.NoFaktur;
                    trxDetailModel.KodeBarang   = item.KodeBarang;
                    trxDetailModel.JumlahBarang = item.JumlahBarang;


                    //untuk penyimpanan
                    //menggunakan data context
                    using (DataContext ctx = new DataContext()) {
                        ctx.trxDetailModel.Add(trxDetailModel);
                        ctx.SaveChanges();
                    }
                }


                return(true);
            }
            catch (Exception)
            {
                return(false);
                //throw;
            }


            //return true;
        }