public async Task <IActionResult> Edit(int id, [Bind("LgaId,Name,StateId")] Lga lga) { if (id != lga.LgaId) { return(NotFound()); } if (ModelState.IsValid) { try { _db.Update(lga); await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LgaExists(lga.LgaId)) { return(NotFound()); } else { throw; } } TempData["lga"] = "You have successfully modified " + lga.Name + " Local Government Area!!!"; TempData["notificationType"] = NotificationType.Success.ToString(); return(Json(new { success = true })); } return(RedirectToAction("Index", new { StateId = lga.StateId })); }
// GET: Lgas/Details/5 //public async Task<IActionResult> Details(int? id) //{ // if (id == null) // { // return NotFound(); // } // var lga = await _db.Lgas // .Include(l => l.State) // .SingleOrDefaultAsync(m => m.LgaId == id); // if (lga == null) // { // return NotFound(); // } // return View(lga); //} #endregion #region Lga Create // GET: Lgas/Create public IActionResult Create() { ViewData["statesessionid"] = Convert.ToInt32(_session.GetInt32("statesessionid")); var lga = new Lga(); return(PartialView("Create", lga)); }
public ActionResult Add([Bind(Include = "LgaID,StateID,LgaName")] LgaViewModel lga) { try { var lgaAdd = new Lga { StateID = Convert.ToInt16(lga.StateID.ToString()), LgaID = Convert.ToInt16(lga.LgaID.ToString()), LgaName = lga.LgaName }; var isExist = (from l in db.Lgas.Where(x => x.LgaName == lga.LgaName) select l).FirstOrDefault(); if (isExist == null) { db.Lgas.Add(lgaAdd); db.SaveChanges(); ViewBag.DisplayMessage = "success"; ModelState.AddModelError("", " Saved Successfully!"); LoadDropDownList(); } else { ViewBag.DisplayMessage = "Info"; ModelState.AddModelError("", "LGA Name " + isExist.LgaName + " already exist, Please enter a new Lga!"); LoadDropDownList(); } } catch (Exception ex) { ViewBag.DisplayMessage = "Info"; ModelState.AddModelError("", "Error: " + ex.Message); } return(View(lga)); }
private void SetLgaIfExist(State state, Lga lga) { try { if (state != null && !string.IsNullOrEmpty(state.Id)) { List <Lga> lgas = _da.GetModelsBy <Lga, LGA>(l => l.State_Id == state.Id); if (lga != null && lga.Id > 0) { ViewBag.Lgas = new SelectList(lgas, DropdownUtility.ID, DropdownUtility.NAME, lga.Id); } else { ViewBag.Lgas = DropdownUtility.PopulateModelSelectListHelper(lgas, false); //ViewBag.Lgas = new SelectList(lgas, DropdownUtility.ID, DropdownUtility.NAME); } } else { ViewBag.Lgas = new SelectList(new List <Lga>(), DropdownUtility.ID, DropdownUtility.NAME); if (_viewModel.StateSelectList != null && _viewModel.StateSelectList.Count > 0) { ViewBag.States = new SelectList(_viewModel.StateSelectList, DropdownUtility.VALUE, DropdownUtility.TEXT, ""); } else { ViewBag.States = new SelectList(new List <State>(), DropdownUtility.VALUE, DropdownUtility.NAME); } } } catch (Exception) { throw; } }
// Local Government Area public Guid createLga(Lga lga) { lga.Id = Guid.NewGuid(); context.Lgas.Add(lga); context.SaveChanges(); return(lga.Id); }
private void btnSave_Click(object sender, EventArgs e) { if (IsValidEntry()) { var lga = new Lga(); lga.StateId = CurrentState.Id; lga.LocalGovernmentName = txtLgaName.Text; if (_Service.createLga(lga) != Guid.Empty) { MessageBox.Show("Lga created successfully"); ResetControl(); } } }
public async Task <IActionResult> OnPostAsync(ICollection <IFormFile> files) { if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath)) { _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"); } //string rootpath = _hostingEnvironment.WebRootPath; string uploads = Path.Combine(_hostingEnvironment.WebRootPath, "Uploads"); foreach (var fil in files) { if (fil.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, fil.FileName), FileMode.Create)) { await fil.CopyToAsync(fileStream); } } } string fileName = "NGALGA.xlsx"; string newrootFolder = uploads + "/" + fileName; FileInfo file = new FileInfo(newrootFolder); using (ExcelPackage package = new ExcelPackage(file)) { ExcelWorksheet workSheet = package.Workbook.Worksheets["LGA"]; int totalRows = workSheet.Dimension.Rows; for (int i = 2; i <= totalRows; i++) { var lgalist = new Lga(workSheet.Cells[i, 1].Value.ToString(), int.Parse(workSheet.Cells[i, 2].Value.ToString())); _context.Add(lgalist); } await _context.SaveChangesAsync(); return(RedirectToPage("./Success")); } return(null); }
public string GenerateProvidersubCode(Lga lga) { Provider top = _session.QueryOver <Provider>().Where(x => x.IsDeleted == false && x.Lga.Id == lga.Id).OrderBy(x => x.Id) .Desc .Take(1).SingleOrDefault(); string response = string.Empty; if (top != null) { int newid = top.Id + 1; return(string.Format("LAN-{0}-{1}", lga.Code, newid)); } else { int newid = 1; return(string.Format("LAN-{0}-{1}", lga.Code, newid)); } }
public async Task <IActionResult> Create([Bind("LgaId,Name,StateId")] Lga lga) { if (ModelState.IsValid) { var allLgas = _db.Lgas.ToList(); if (allLgas.Any(l => l.Name == lga.Name)) { TempData["lga"] = "You cannot add " + lga.Name + " local government area because it already exist!!!"; TempData["notificationType"] = NotificationType.Error.ToString(); return(RedirectToAction("Index", new { StateId = lga.StateId })); } await _db.AddAsync(lga); await _db.SaveChangesAsync(); TempData["lga"] = "You have successfully added " + lga.Name + " as a new Local Government Area!!!"; TempData["notificationType"] = NotificationType.Success.ToString(); return(Json(new { success = true })); } return(View("Index", new { StateId = lga.StateId })); }
public List<Lga> getLga() { List<Lga> list = new List<Lga>(); new Lga(); SqlConnection connection = new SqlConnection(this.Connect()); string cmdText = "SELECT * FROM lga"; SqlCommand command = new SqlCommand(cmdText, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { Lga item = new Lga { ID = Convert.ToInt64(reader["ID"]).ToString(), name = reader["name"].ToString(), stateID = reader["stateID"].ToString() }; list.Add(item); } reader.Close(); return list; }