public async Task <IActionResult> Edit(string id, [Bind("SubstationId,SubstationTypeId,SubstationName,SnDCode,NominalVoltage,InstalledCapacity,MaximumDemand,PeakLoad,Location,AreaOfSubstation,Latitude,Longitude,YearOfComissioning")] TblSubstation tblSubstation)
        {
            if (id != tblSubstation.SubstationId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tblSubstation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TblSubstationExists(tblSubstation.SubstationId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubstationTypeId"] = new SelectList(_context.LookUpSubstationType, "SubstationTypeId", "SubstationTypeId", tblSubstation.SubstationTypeId);
            ViewData["SnDCode"]          = new SelectList(_context.LookUpSnDInfo, "SnDCode", "SnDCode", tblSubstation.SnDCode);
            return(View(tblSubstation));
        }
        public async Task <IActionResult> Create([Bind("SubstationId,SubstationTypeId,SubstationName,SnDCode,NominalVoltage,InstalledCapacity,MaximumDemand,PeakLoad,Location,AreaOfSubstation,Latitude,Longitude,YearOfComissioning")] TblSubstation tblSubstation)
        {
            //if (tblSubstation.IsEmpty() != "")
            //{
            //    ViewData["Error"] = tblSubstation.IsEmpty();
            //    return Redirect("Create");

            //}

            //try
            //{

            if (ModelState.IsValid)
            {
                _context.Add(tblSubstation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //}
            //catch (Exception e)
            //{
            //    ViewData["Error"]= e;
            //    throw;
            //}

            //ViewData["SubstationTypeId"] = new SelectList(_context.LookUpSubstationType, "SubstationTypeId", "SubstationTypeName", tblSubstation.SubstationTypeId);
            //ViewData["SnDCode"] = new SelectList(_context.LookUpSnDInfo, "SnDCode", "SnDCode", tblSubstation.SnDCode);

            var SubstationTypeInfoes = _context.LookUpSubstationType.Select(agn =>
                                                                            new { Code = agn.SubstationTypeId, Name = agn.SubstationTypeId + " : " + agn.SubstationTypeName });

            ViewData["SubstationTypeId"] = new SelectList(SubstationTypeInfoes, "Code", "Name");


            //ViewData["SnDCode"] = new SelectList(_context.LookUpSnDInfo, "SnDCode", "SnDCode");
            var SnDInfoes = _context.LookUpSnDInfo.Select(agn =>
                                                          new { Code = agn.SnDCode, Name = agn.SnDCode + " : " + agn.SnDName });

            ViewData["SnDCode"] = new SelectList(SnDInfoes, "Code", "Name");
            return(View(tblSubstation));
        }