public IActionResult Index(CreateCountry createCountry) { if (ModelState.IsValid) { _countryService.Add(createCountry); return(RedirectToAction(nameof(Index))); } return(View(_countryService.All())); }
public IActionResult Create(CountryForm form) { if (_sessionManager.User is not null) { try { if (ModelState.IsValid) { Country c = new Country { Ctry = form.Ctry, ISO = form.ISO, IsEU = form.IsEU }; _countryService.Add(c); return(RedirectToAction("index")); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); //ViewBag.Error = ex.Message; } return(View()); } else { return(RedirectToAction("Login", "Auth")); } }
public IActionResult Create([FromForm] CountryCreateModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { try { AuditedEntityMapper <CountryCreateModel> .FillCreateAuditedEntityFields(entity, currentUser); bool statusResult = _countryService.Add(entity); if (statusResult) { return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT)); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(RedirectToAction(nameof(Index)).WithError(ex.Message)); } } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE)); }
public ActionResult <CountryViewModel> Post(CountryViewModel countryViewModel) { var country = _mapper.Map <CountryDto>(countryViewModel); _countryService.Add(country); return(Ok(countryViewModel)); }
private async Task <Country> CreateTestCountry(ServiceFactory serviceFactory) { ICountryService countryService = serviceFactory.CreateCountryService(); Guid countryId = await countryService.Add(new AddCountry { Name = "Test Country", Abbreviation = "Test Abbreviation" }); return(await countryService.GetById(countryId)); }
public void Add(Country ctry) { if (ctry is null) { throw new NullReferenceException($"Country Data empty ({where}) (ADD)"); } _globalService.Add(ctry.ToGlobal()); }
public ActionResult Create(CreateCountryViewModel createCountryViewModel) { if (ModelState.IsValid) { _countrysService.Add(createCountryViewModel); return(RedirectToAction(nameof(Index))); } return(View(createCountryViewModel)); }
public async Task <IActionResult> Create([FromForm] Country country) { try { country.NoticeTranslate = JsonSerializer.Deserialize <ICollection <NoticeTranslate> >(country.Notices); if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Messages = new Message[] { new Message { Lang_id = 1, MessageLang = "Model state isn't valid!" }, new Message { Lang_id = 2, MessageLang = "Состояние модели недействительно!" }, new Message { Lang_id = 3, MessageLang = "Model vəziyyəti etibarsızdır!" } } })); } ValidateModel res = country.Photo.PhotoValidate(); if (!res.Success) { return(StatusCode(StatusCodes.Status500InternalServerError, res.Response)); } ValidateModel res2 = country.FlagPhoto.PhotoValidate(); if (!res2.Success) { return(StatusCode(StatusCodes.Status500InternalServerError, res.Response)); } string folder = Path.Combine("Site", "images", "countries"); string fileName = await country.Photo.SaveImage(_env.WebRootPath, folder); country.Image = fileName; fileName = await country.FlagPhoto.SaveImage(_env.WebRootPath, folder); country.BgImage = fileName; _countryContext.Add(country); foreach (NoticeTranslate item in country.NoticeTranslate) { item.CountryId = country.Id; _noticeContext.Add(item); } return(Ok()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <IActionResult> AddCountry([FromBody] CountryDTO country) { if (ModelState.IsValid) { country = await _countryService.Add(country); return(Ok(country)); } return(BadRequest(ModelState)); }
public void AddTest() { var count = _memoryDbContext.Countries.Count(); var countryCreateModel = Builder <CountryCreateModel> .CreateNew().With(c => c.Path = "uniquePath").Build(); _countryService.Add(countryCreateModel); Assert.AreEqual(_memoryDbContext.Countries.Count(), count + 1); }
public IActionResult Add(Country country) { var result = _countryService.Add(country); if (result.Success) { return(Ok()); } return(BadRequest()); }
protected void btnAdd_Click(object sender, EventArgs e) { countryService.Add(new Country() { Id = Int32.Parse(tbxId.Text), Name = tbxCountry.Text, Capital = tbxCapital.Text }); GV_Refresh(); }
public virtual ActionResult Create(CountryEditModel model) { if (!ModelState.IsValid) { return(View(model)); } var id = _countries.Add(model); return(RedirectToAction(MVC.Country.Edit(id))); }
public async Task <IActionResult> Add([FromBody] CountryDTO country) { var outputHandler = await _service.Add(country); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Created("", outputHandler.Message)); }
public async Task <IActionResult> Add(Country country) { var result = await _countryService.Add(country); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult Create(CreateCountryViewModel createCountry) { if (ModelState.IsValid) { _countryService.Add(createCountry); //I'm not sure solving return(RedirectToAction(nameof(Index))); } else { return(View(createCountry)); } }
public JavaScriptResult Create(CountryViewModel countryvm) { try { _countryService.Add(Mapper.Map <Country>(countryvm)); return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"."}')")); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }
public ActionResult Add(CountryModel country) { if (ModelState.IsValid) { var countryDTO = _countryMaper.MapBack(country); _countryService.Add(countryDTO); return(RedirectToAction("List")); } else { return(View()); } }
public void CanAdd() { testContext.RunInTestEnvironment(async(serviceFactory) => { //Arrange ICountryService countryService = serviceFactory.CreateCountryService(); //Act Guid id = await countryService.Add(new AddCountry { Name = "Test Country", Abbreviation = "Test Abbreviation" }); //Assert Assert.NotEqual(id, Guid.Empty); }); }
public IActionResult Post([FromBody] CreateEditViewModel model) { DataClaim.GetClaim(Request); var country = new Country(); if (model is null) { return(BadRequest("Country is null.")); } if (!ModelState.IsValid) { return(BadRequest()); } _mapper.Map(model, country); _countryProvider.Add(country); return(Ok(country)); }
public IActionResult Create(CountryModel country) { if (ModelState.IsValid) { var result = _countryService.Add(country); if (result.Status == ResultStatus.Success) { return(RedirectToAction(nameof(Index))); } if (result.Status == ResultStatus.Error) { ModelState.AddModelError("", result.Message); return(View(country)); } throw new Exception(result.Message); } return(View(country)); }
public ActionResult CreateCountry(CreateCountryViewModel ctyVM) { if (ModelState.IsValid) { Country country = _countryService.Add(ctyVM); if (country == null) { ModelState.AddModelError("msg", "Database Problem"); return(View(ctyVM)); } return(RedirectToAction(nameof(ShowCountry))); } else { return(View(ctyVM)); } }
public void CanGetByAbbreviation() { testContext.RunInTestEnvironment(async(serviceFactory) => { //Arrange ICountryService countryService = serviceFactory.CreateCountryService(); Guid id = await countryService.Add(new AddCountry { Name = "Test Country", Abbreviation = "Test Abbreviation" }); Assert.NotEqual(id, Guid.Empty); //Act IEnumerable <Country> countries = await countryService.GetByAbbreviation("Test Abbreviation"); //Assert Assert.NotNull(countries); Assert.Single(countries); }); }
public ActionResult Add(Country country) { if (string.IsNullOrEmpty(country.Name)) { return(Content("error! countryName is required!")); } int count = CountryService.LoadEntities(c => c.Name.Equals(country.Name)).Count(); if (count > 0) { //已有此记录,不处理 return(Content("ok")); } else { CountryService.Add(country); return(Content("ok")); } }
public void CanDelete() { testContext.RunInTestEnvironment(async(serviceFactory) => { //Arrange ICountryService countryService = serviceFactory.CreateCountryService(); Guid id = await countryService.Add(new AddCountry { Name = "Test Country", Abbreviation = "Test Abbreviation" }); Assert.NotEqual(id, Guid.Empty); Country country = await countryService.GetById(id); Assert.NotNull(country); //Act await countryService.Delete(id); //Assert country = await countryService.GetById(id); Assert.Null(country); }); }
public async Task <ActionResult> Post([FromBody] Country country) { logger.LogInformation($"Call CountryController.Post"); try { if (!country.Validate(country)) { return(new BadRequestObjectResult(ModelState)); } else { await _countryService.Add(country); return(new OkResult()); } } catch (Exception ex) { throw ex; } }
public IActionResult Add([FromBody] CountryForm ctry) { try { if (ctry is null) { throw new ArgumentNullException("Country Object Empty (ADD)"); } Country ctryo = new Country() { ISO = ctry.ISO, Ctry = ctry.Ctry, IsEU = ctry.IsEU }; _clientService.Add(ctryo); return(ApiControllerHelper.SendOk(this, new ApiResult <Country>(HttpStatusCode.OK, null, ctryo), true)); } catch (Exception ex) { return(ApiControllerHelper.SendError(this, ex)); } }
public IActionResult Create(Country country) { try { if (country == null) { _logger.LogError("Create operation failed on Countries table"); return(BadRequest("Invalid data submited")); } else { _logger.LogInformation("Create request successfull on Countries table"); _countryService.Add(country); return(Ok($"Record successfully added {country}")); } } catch (Exception ex) { //_logger.LogError("Create operation failed on Countries table", ex); return(BadRequest($"There was an error trying nto process the request {ex}")); } }
public void CanUpdate() { testContext.RunInTestEnvironment(async(serviceFactory) => { //Arrange ICountryService countryService = serviceFactory.CreateCountryService(); Guid id = await countryService.Add(new AddCountry { Name = "Test Country", Abbreviation = "Test Abbreviation" }); Assert.NotEqual(id, Guid.Empty); //Act await countryService.Update(new UpdateCountry { Id = id, Name = "Test Country Edit", Abbreviation = "Test Abbreviation Edit" }); //Assert Country country = await countryService.GetById(id); Assert.Equal("Test Country Edit", country.Name); Assert.Equal("Test Abbreviation Edit", country.Abbreviation); }); }
public void Post([FromBody] Country country) { logger.LogInformation("Add Country: {country.Code}", country.Code); countryService.Add(country); }