public bool Add(Country country) { bool result = true; try { context.Countries.Add(country); context.SaveChanges(); } catch (Exception ex) { result = false; } return result; }
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; }
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); }
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); }