public bool Update(CountryModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var itemUpdate = (from tb in cxt.I_Country where tb.Id == model.Id select tb).FirstOrDefault(); itemUpdate.ShortName = model.ShortName; itemUpdate.FullName = model.FullName; itemUpdate.ZipCode = model.ZipCode; itemUpdate.IsActived = model.IsActived; cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Insert(CountryModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { I_Country item = new I_Country(); item.Id = Guid.NewGuid().ToString(); item.ShortName = model.ShortName; item.FullName = model.FullName; item.ZipCode = model.ZipCode; item.IsActived = model.IsActived; cxt.I_Country.Add(item); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public ActionResult DeleteConfirmed(int id) { CountryModels countryModels = db.Countries.Find(id); db.Countries.Remove(countryModels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,CountryName")] CountryModels countryModels) { if (ModelState.IsValid) { db.Entry(countryModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(countryModels)); }
public ActionResult Create([Bind(Include = "ID,CountryName")] CountryModels countryModels) { if (ModelState.IsValid) { db.Countries.Add(countryModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(countryModels)); }
// GET: Country/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CountryModels countryModels = db.Countries.Find(id); if (countryModels == null) { return(HttpNotFound()); } return(View(countryModels)); }
public ActionResult OnEdit(CountryModels country) { if (ModelState.IsValid) { var result = CountryService.Update(country.CloneTo <Country>()); if (result == Result.NotExists) { ModelState.AddModelError("", "Id không tồn tại trên hệ thống."); return(View("Edit", country)); } SetFlashMessage($"Cập nhật Quốc gia '{country.Name}' thành công."); if (country.SaveList) { return(RedirectToAction("Index")); } return(View("Edit", country)); } return(View("Edit", country)); }
public ActionResult OnCreate(CountryModels country) { if (ModelState.IsValid) { var result = CountryService.Insert(country.CloneTo <Country>()); if (result == Result.Exists) { ModelState.AddModelError("", $"Quốc gia {country.Name} đã tồn tại trên hệ thống."); return(View("Create", country)); } SetFlashMessage($"Thêm Quốc gia '{country.Name}' thành công."); if (country.SaveList) { return(RedirectToAction("Index")); } ModelState.Clear(); return(View("Create", country.ResetValue())); } return(View("Create", country)); }