public async Task <CreateCountryResponse> Handle(CreateCountry request, CancellationToken cancellationToken) { var response = new CreateCountryResponse() { RequestId = request.RequestId, }; if (response.FromResult(await _createCountryValidator.ValidateAsync(request, cancellationToken))) { var country = new DataModels.Country() { Name = request.Country.Name, }; _bookShelfContext.Countries.Add(country); await _bookShelfContext.SaveChangesAsync(cancellationToken); response.Country = new Country() { Id = country.Id, Name = country.Name, }; } return(response); }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountry newCountry) { //TODO: Check if Tran# has been used already try { if (!ModelState.IsValid) { return(Json(new { IsSuccess = false, Message = "" })); } else { var currentUser = _userRepository.GetByIdAsync(_userAppContext.CurrentUserId); newCountry.OwnerAddress = currentUser.WalletAddress.ToLower(); newCountry.CountryOwner = currentUser.NickName; newCountry.UserId = currentUser.Id; newCountry.UserUId = currentUser.UId; var countryCreated = await _countryService.CreateCountry(newCountry); return(Json(new { IsSuccess = countryCreated })); } } catch (Exception e) { return(Json(new { IsSuccess = false, Message = e.Message })); } }
public void CreateCountry_Action_Fails() { // Arrange var countryDto = TestHelper.CountryDto(); GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.CountryService.CreateCountry(countryDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new CreateCountry <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(countryDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public Country Add(CreateCountry CreateCountry) { Country country = new Country(); country.CountryName = CreateCountry.CountryName; return(_countryRepo.Create(country)); }
public IActionResult Create(CreateCountry createCountry) { if (ModelState.IsValid) { _countryService.Add(createCountry); return(RedirectToAction(nameof(Index))); } return(View(createCountry)); }
public Country Add(CreateCountry createCountry) { Country city = new Country(); city.CountryName = createCountry.CountryName; return(_countryRepo.Create(city)); }
/// <summary> /// Create new country /// </summary> public async Task <bool> CreateCountry(CreateCountry newCountry) { try { if (newCountry == null) { throw new ApplicationException("New country is not completed"); } if (newCountry.CountryName == null || newCountry.CountryDescription == null || newCountry.BlockNumber == 0 || newCountry.Theme == null) { throw new ApplicationException("Country detail is not completed"); } var UId = Guid.NewGuid(); var objectId = ObjectId.GenerateNewId().ToString(); var newCountryObj = new Country { UId = UId, Id = objectId, Name = newCountry.CountryName, Description = newCountry.CountryDescription, President = newCountry.CountryOwner, Theme = newCountry.Theme, BlockNumber = newCountry.BlockNumber, EstimatedValue = ((decimal)newCountry.BlockNumber * (decimal)0.0005) + (decimal)(((decimal)newCountry.BlockNumber * (decimal)0.0005) * 20 / 100), CreatedOn = DateTime.UtcNow, CreatedBy = newCountry.UserUId, Population = 256 * newCountry.BlockNumber, CountryIndex = newCountry.CountryIndex, OwnerAddress = newCountry.OwnerAddress, OwnerId = newCountry.UserId, BankBalance = newCountry.BlockNumber * 1000, OriginalValue = ((decimal)newCountry.BlockNumber * (decimal)0.0005), CountryContractUniqueId = newCountry.CountryContractUniqueId, TxTran = newCountry.TxTran, Status = newCountry.Status, TotalBlocks = 9, WelcomeMessage = "Welcome to my country!", }; await _countryRepository.Add(newCountryObj); return(true); } catch (Exception e) { throw new ApplicationException("Create country error" + e.Message); } }
public Country Edit(int id, CreateCountry country) { Country originCountry = FindById(id); if (originCountry == null) { return(null); } originCountry.CountryName = country.CountryName; originCountry = _countryRepo.Update(originCountry); return(originCountry); }
public Country Edit(int id, CreateCountry country) { Country newCountry = FindbyId(id); if (newCountry == null) { return(null); } newCountry.CountryName = country.CountryName; newCountry = _countryRepo.Update(newCountry); return(newCountry); }
public async Task <ActionResult <CreateCountryResponse> > Post( [FromBody] CountryForm Country, CancellationToken cancellationToken ) { var request = new CreateCountry() { RequestId = this.GetRequestId(), Country = Country, }; var response = await _mediator.Send(request, cancellationToken); return(Ok(response)); }
public Country Edit(int id, CreateCountry country) { Country c = FindById(id); if (c == null) { return(null); } c.CountryName = country.CountryName; c = _countryRepo.Update(c); return(c); }
public IApiResult Create(CreateCountry operation) { var result = operation.ExecuteAsync().Result; if (result is ValidationsOutput) { return(new ApiResult <List <ValidationItem> >() { Data = ((ValidationsOutput)result).Errors }); } else { return(new ApiResult <object>() { Status = ApiResult <object> .ApiStatus.Success }); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); //init var cd = app.ApplicationServices.GetService <ICommandDispatcher>(); var qd = app.ApplicationServices.GetService <IQueryDispatcher>(); var createCountries = new CreateCountry[] { new CreateCountry(Guid.NewGuid(), "Rus"), new CreateCountry(Guid.NewGuid(), "Usa"), new CreateCountry(Guid.NewGuid(), "Ger") }.ToList(); createCountries.ForEach(x => cd.Execute(x)); Country[] countries = null; for (int i = 0; i < 10; i++)//todo replace to retry { countries = qd.Execute <FindCountriesBySearchTextQuery, Country[]>(new FindCountriesBySearchTextQuery("", false)); if (countries.Length == 3) { break; } Task.Delay(100).Wait(); } var createProvince = new List <CreateProvince>(); foreach (var country in countries) { for (int i = 0; i < 3; i++) { cd.Execute(new CreateProvince(Guid.Empty, country.Id, country.Name + "-Province-" + i)); } } // }
public async Task <IActionResult> Post(CreateCountry command) => await SendAsync(command.BindId(c => c.Id), resourceId : command.Id, resource : "countries");