Example #1
0
        public ActionResult AddCityForm(City city)
        {
            ErrorModel result = new ErrorModel
            {
                Error = false,
                ErrorText = ""
            };

            if (city.Id_Country != null && city.Name != null)
            {
                city.UploadDate = DateTime.Now;
                if (!cityRepository.Add(city))
                {
                    result.Error = true;
                    result.ErrorText = "Такой город уже существует";
                }

            }
            else
            {
                result.Error = true;
                result.ErrorText = "Ошибка валидации";
            }
            return Json(result);
        }
Example #2
0
 public bool Add(City city)
 {
     bool result = true;
     try
     {
         context.Cities.Add(city);
         context.SaveChanges();
     }
     catch (Exception ex){
         var code = ex.HResult;
         result = false;
     }
     return result;
 }