public async Task <IActionResult> AddOrEdit(int id, [Bind("KomPolaId,PolaId,KompId")] KomponenPola komponenPola)
        {
            if (ModelState.IsValid)
            {
                if (id == 0)
                {
                    try
                    {
                        _context.Add(komponenPola);
                        await _context.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("CustomError", ex.Message);
                    }
                }
                else if (id == komponenPola.KomPolaId)
                {
                    try
                    {
                        _context.Update(komponenPola);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!KomponenPolaExists(komponenPola.KomPolaId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                var modalAjax = await _context.TblKomponenPola.Include(k => k.Komponen).Include(k => k.Pola)
                                .Where(k => k.PolaId == komponenPola.PolaId).ToListAsync();

                return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "RAB/_TblKomponenPola", modalAjax) }));
            }
            ViewData["KompId"] = new SelectList(_context.TblPola, "PolaId", "Nama", komponenPola.KompId);
            //ViewData["PolaId"] = new SelectList(_context.TblPola, "PolaId", "Nama", komponenPola.PolaId);
            //return View(komponenPola);
            return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", komponenPola) }));
        }
예제 #2
0
 public async Task <IActionResult> AddOrEdit(int id, [Bind("PolaId,TtkId,Sumbu,SumbuId,Nama,Jarak,PosAbs,PosReal")] Titik grid)
 {
     if (ModelState.IsValid)
     {
         if (id == 0)
         {
             _context.Add(grid);
             await _context.SaveChangesAsync();
         }
         else if (id == grid.TtkId)
         {
             try
             {
                 // datang dari Edit
                 _context.Update(grid);
                 await _context.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!TitikExists(grid.TtkId))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         // mendapatkan string view tanpa perlu ke methode yang bersangkutan
         var modalAjax = _context.TblTitik.Include(g => g.Pola)
                         .Where(g => g.PolaId == grid.PolaId)
                         .OrderBy(o => o.Sumbu).ThenBy(o => o.SumbuId)
                         .ToList();
         return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "RAB/_TblTitik", modalAjax) }));
     }
     // mendapatkan string view tanpa perlu ke methode yang bersangkutan
     //jika  gagal
     return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", grid) }));
 }
예제 #3
0
        public async Task <IActionResult> AddOrEdit(int id, [Bind("PolaId,Nama,Status,SatuanPenyusun,Posisi3D")] Pola pola)
        {
            if (ModelState.IsValid)
            {
                if (pola.PolaId == 0)
                {
                    try
                    {
                        _context.Add(pola);
                        await _context.SaveChangesAsync();
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (id == pola.PolaId)
                {
                    try
                    {
                        _context.Update(pola);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!PolaExists(pola.PolaId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "RAB/_TblPola", _context.TblPola.ToList()) }));
            }

            return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", pola) }));
        }
예제 #4
0
        public async Task <IActionResult> AddOrEdit(int id, [Bind("KompKoorId,KoorId,KompId,PosAtasId,PosBawahId")] KomponenKoordinat komponenKoor)
        {
            var sesPola = SPola.GetSesi(this);
            var permintaanDariGambar = sesPola.DariGambar;
            var koor = _context.TblKoordinat.Include(k => k.TitikX).Include(k => k.TitikY) //.ThenInclude(k => k.Pola)
                       .Where(k => k.KoordId == komponenKoor.KoorId).Single();
            int polaId = koor.TitikX.PolaId;

            if (ModelState.IsValid)
            {
                if (komponenKoor.KompKoorId == 0)
                {
                    try
                    {
                        _context.Add(komponenKoor);
                        await _context.SaveChangesAsync();
                    }
                    catch { }
                }
                else if (id == komponenKoor.KompKoorId)
                {
                    try
                    {
                        _context.Update(komponenKoor);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!KomponenKoordinatExists(komponenKoor.KompKoorId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                if (permintaanDariGambar)
                {
                    // kembali ke index gambar
                    return(RedirectToAction("KompGaris", "Gambar"));
                }
                else
                {
                    return(RedirectToAction(nameof(Index), new { polaId = polaId, koorId = komponenKoor.KoorId }));
                }
            }


            ViewBag.KoorNama = koor.Nama;
            var lstKomp4Select = _context.TblKomponenPola.Where(k => k.PolaId == polaId && (int)k.Komponen.Posisi3D == (int)EPosisi3D.Kolom)
                                 .Select(k => new { k.KomPolaId, k.Komponen.Nama }).ToList();
            var lstPosZ = _context.TblTitik.Where(t => t.PolaId == polaId && t.Sumbu == ESumbu.Z)
                          .OrderByDescending(t => t.Jarak)
                          .Select(t => new { t.TtkId, t.Nama }).ToList();

            ViewData["KompId"]     = new SelectList(lstKomp4Select, "KomPolId", "Nama", komponenKoor.KompId);
            ViewData["PosAtasId"]  = new SelectList(lstPosZ, "TtkId", "Nama", komponenKoor.PosAtasId);
            ViewData["PosBawahId"] = new SelectList(lstPosZ, "TtkId", "Nama", komponenKoor.PosBawahId);
            return(View(komponenKoor));
        }
예제 #5
0
        public async Task <IActionResult> AddOrEdit(int id, [Bind("KompGrsId,GarisId,KompPolaId,PosRelatifDiZ,PosZId,PosRelatif,PosRelX,PosRelY,OffsetKeKanan")] KomponenGaris komponenGaris)
        {
            var sesPola = SPola.GetSesi(this);
            var permintaanDariGambar = sesPola.DariGambar;

            if (ModelState.IsValid)
            {
                if (komponenGaris.KompGrsId == 0)
                {
                    try
                    {
                        _context.Add(komponenGaris);
                        await _context.SaveChangesAsync();
                    }
                    catch { }
                }
                else if (id == komponenGaris.KompGrsId)
                {
                    try
                    {
                        _context.Update(komponenGaris);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!KomponenGarisExists(komponenGaris.KompGrsId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                if (permintaanDariGambar)
                {
                    // kembali ke index gambar
                    return(RedirectToAction("KompGaris", "Gambar"));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }


            var grs = _context.TblGaris
                      .Include(g => g.KoordAwal)
                      .Include(g => g.KoordAkhir)
                      .Include(g => g.KoordAwal.TitikX)
                      .Include(g => g.KoordAwal.TitikY)
                      .Include(g => g.KoordAkhir.TitikX)
                      .Include(g => g.KoordAkhir.TitikY)
                      .Where(g => g.GarisId == id)   //.ToList();
                      .Single();
            int polaId = grs.KoordAwal.TitikX.Pola.PolaId;

            ViewBag.GarisNama = grs.Nama + " (" + grs.Arah + ")";
            var lstKomp4Select = _context.TblKomponenPola.Where(k => k.PolaId == polaId)
                                 .Select(k => new { k.KomPolaId, k.Komponen.Nama }).ToList();
            var lstPosZ = _context.TblTitik.Where(t => t.PolaId == polaId && t.Sumbu == ESumbu.Z)
                          .Select(t => new { t.TtkId, t.Nama }).ToList();

            ViewData["KompPolaId"] = new SelectList(lstKomp4Select, "KomPolaId", "Nama", komponenGaris.KompPolaId);
            ViewData["PosZId"]     = new SelectList(lstPosZ, "TtkId", "Nama", komponenGaris.PosZId);

            if (permintaanDariGambar)
            {
                //kembali ke action gambar garis di gambar
                return(RedirectToAction("KompGaris", "Gambar"));
            }

            return(View(komponenGaris));
        }