Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            CountryModels countryModels = db.Countries.Find(id);

            db.Countries.Remove(countryModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
 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));
 }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "ID,CountryName")] CountryModels countryModels)
        {
            if (ModelState.IsValid)
            {
                db.Countries.Add(countryModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(countryModels));
        }
Beispiel #6
0
        // 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));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
 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));
 }