Beispiel #1
0
 public bool Add(Country country)
 {
     bool result = true;
     try
     {
         context.Countries.Add(country);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         result = false;
     }
     return result;
 }
Beispiel #2
0
 public bool Update(Country country)
 {
     bool result = true;
     try
     {
         context.Countries.Where(x => x.Id == country.Id).First().Name = country.Name;
         context.Countries.Where(x => x.Id == country.Id).First().UploadDate = DateTime.Now;
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         result = false;
     }
     return result;
 }
Beispiel #3
0
        public ActionResult AddCountryForm(Country country)
        {
            ErrorModel result = new ErrorModel
            {
                Error = false,
                ErrorText = ""
            };

            if (country.Name != null)
            {
                country.UploadDate = DateTime.Now;
                if (!countryRepository.Add(country))
                {
                    result.Error = true;
                    result.ErrorText = "Такая страна уже существует";
                }
            }
            else
            {
                result.Error = true;
                result.ErrorText = "Ошибка валидации";
            }
            return Json(result);
        }
Beispiel #4
0
        public ActionResult RedactCountry(Country country)
        {
            ErrorModel result = new ErrorModel
            {
                Error = false,
                ErrorText = country.Name + "&" + DateTime.Now
            };

            if (country.Name != null)
            {
                country.UploadDate = DateTime.Now;
                if (!countryRepository.Update(country))
                {
                    result.Error = true;
                    result.ErrorText = "Произошла ошибка";
                }
            }
            else
            {
                result.Error = true;
                result.ErrorText = "Название страны не может быть пустым";
            }
            return Json(result);
        }