public ActionResult Create(CountryCreateViewModel model) { List <string> countryNames = _context.Countries.Select(c => c.Name).ToList(); if (countryNames.Contains(model.Name)) { ModelState.AddModelError("", "This country already exists"); } if (!ModelState.IsValid) { ModelState.AddModelError("", "Are you retarded or something?"); return(View(model)); } Country country = new Country { DateCreate = DateTime.Now, Name = model.Name, Priority = model.Priority }; _context.Countries.Add(country); _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(CountryCreateViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var country = _mapper.Map <Country>(model); var isSuccess = _repo.Create(country); if (!isSuccess) { ModelState.AddModelError("", "در ثبت اطلاعات مشکلی بوجود آمده است"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "در ثبت اطلاعات مشکلی بوجود آمده است"); return(View(model)); } }
public static bool SaveCountry(CountryCreateViewModel model) { try { var data = new Country() { Name = model.Name, CurrencyName = model.CurrencyName, CurrencyCode = model.CurrencyCode, Code = model.Code, IsActive = model.IsActive, CreatedBy = model.CreatedBy, CreatedDate = DateTime.UtcNow }; using (var context = new IdeaValidationContext()) { context.Countries.Add(data); context.SaveChanges(); } return(true); } catch (Exception ex) { throw ex; } }
public IActionResult Create(CountryCreateViewModel c) { if (c is null) { throw new System.ArgumentNullException(nameof(c)); } if (ModelState.IsValid) { var langids = _langrepo.GetAll().Where(l => l.Name == "English").ToList(); int englishid = langids[0].LanguageId; if (c.LanguageId == englishid) { Countries cou = new Countries() { Name = c.Name, IsActive = c.IsActive }; int r = _countryrepo.Create(cou); return(RedirectToAction("Index")); } else { CountryLanguages clangs = new CountryLanguages() { Name = c.Name, LanguageId = c.LanguageId, CountryId = c.EnglishCountryID }; int i = _countrylang.Create(clangs); return(RedirectToAction("Index")); } } return(View()); }
public ActionResult Create(CountryCreateViewModel model) { Country country = new Country { DateCreate = DateTime.Now, Name = model.Name, Priority = model.Priority }; _context.Countries.Add(country); _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(CountryCreateViewModel countryModel) { if (ModelState.IsValid) { var operationStatus = _locationService.CountryCreate(countryModel); if (operationStatus == CountryStatusViewModel.Success) { return(RedirectToAction("Index")); } else if (operationStatus == CountryStatusViewModel.Dublication) { ModelState.AddModelError("", "Країна з даним іменем вже існує"); } } return(View(countryModel)); }
private void FillApartmentCountryAndCity(Apartment create, string cityAndCountryName) { string cityName = cityAndCountryName.Substring(0, cityAndCountryName.IndexOf(',')); string countryName = cityAndCountryName.Substring(cityAndCountryName.LastIndexOf(' ')); var country = countryService.GetByName(countryName); if (country == null) { CountryCreateViewModel createCountryVM = new CountryCreateViewModel(); createCountryVM.Name = countryName; country = countryService.Create(createCountryVM); var city = cityService.GetCityInCountry(country.Id, cityName); if (city == null) { CityCreateViewModel createCityVM = new CityCreateViewModel() { Name = cityName, CountryId = country.Id }; city = cityService.Create(createCityVM); create.CityId = city.Id; } } else { var city = cityService.GetCityInCountry(country.Id, cityName); if (city == null) { CityCreateViewModel createCityVM = new CityCreateViewModel() { Name = cityName, CountryId = country.Id }; city = cityService.Create(createCityVM); create.CityId = city.Id; } create.CityId = city.Id; } }
public ActionResult Create(CountryCreateViewModel model) { if (ModelState.IsValid) { Country country = new Country { DateCreate = DateTime.Now, Name = model.Name, Priority = model.Priority }; _context.Countries.Add(country); _context.SaveChanges(); return(RedirectToAction("Index")); } ModelState.AddModelError("", "Дружок(Подружка) не тупи!!!"); return(View(model)); }
public ActionResult Create(CountryCreateViewModel countryVM) { if (ModelState.IsValid) { var create = countryService.Create(countryVM); if (create == null) { ModelState.AddModelError("Name", "Name already exists"); return(View(countryVM)); } return(RedirectToAction("Index")); } return(View(countryVM)); }
public CountryStatusViewModel CountryCreate(CountryCreateViewModel createCountry) { var searchCountry = _countryRepository.GetCountryByName(createCountry.Name); if (searchCountry != null) { return(CountryStatusViewModel.Dublication); } Country country = new Country { Name = createCountry.Name, Priority = createCountry.Priority, DateCreate = DateTime.Now }; _countryRepository.Add(country); _countryRepository.SaveChange(); return(CountryStatusViewModel.Success); }
public CountryViewModel Create(CountryCreateViewModel countryVM) { var country = countryRep.GetByName(countryVM.Name); if (country != null) { return(null); } Country add = new Country(); add.Name = countryVM.Name; countryRep.Create(add); countryRep.SaveChanges(); return(new CountryViewModel() { Id = add.Id, Name = add.Name }); }
public UIElement GetAddElement() { CountryCreateViewModel viewModel = new CountryCreateViewModel(); CountryCreateControl control = new CountryCreateControl(viewModel); viewModel.CountryCreated += (s, e) => { using (ICountryService service = factory.CreateCountryService()) { ServiceMessage serviceMessage = service.Create(e.ContryName); RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message); if (serviceMessage.IsSuccessful) { viewModel.CountryName = String.Empty; Notify(); } } }; return(control); }
public async Task <IActionResult> Create(CountryCreateViewModel model) { if (ModelState.IsValid) { var objcountry = new CountryRegistration { id = model.id, countryname = model.countryname, countrycode = "", isdeleted = false, isactive = false }; await _CountryRegistrationservices.CreateAsync(objcountry); TempData["success"] = "Record Saved successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public ActionResult Create(CountryCreateViewModel model) { if (ModelState.IsValid) { Country isFind = _context.Countries.SingleOrDefault(x => x.Name == model.Name); if (isFind != null) { ModelState.AddModelError("", "Дві країни з однаковою назвою...Знову щось пішло не так)))"); return(View(model)); } Country country = new Country { DateCreate = DateTime.Now, Name = model.Name, Priority = model.Priority }; _context.Countries.Add(country); _context.SaveChanges(); return(RedirectToAction("Index")); } ModelState.AddModelError("", "Дружок не тупи"); return(View(model)); }
public CountryCreateControl(CountryCreateViewModel viewModel) { InitializeComponent(); this.DataContext = viewModel; }
public IActionResult Create() { var model = new CountryCreateViewModel(); return(View(model)); }
public async Task <IActionResult> Add([FromBody] CountryCreateViewModel country) { var id = await _countryCommandFunctionality.AddAsync(Mapper.Map <CountryCreateCommand>(country)); return(ResponseWithData(StatusCodes.Status201Created, id)); }