public List <ModelCountryState> Linkage(RegionDto dto) { var aa = GetState(); List <ModelCountryState> modelCountryState = new List <ModelCountryState>(); foreach (var item in aa) { var bb = GetCity(item); List <Citys> City = new List <Citys>(); foreach (var item2 in bb) { List <string> Region = new List <string>(); var cc = GetRegion(new RegionDto { CityDto = item, Name = item2.Name }); foreach (var item3 in cc) { Region.Add(item3.Name); } City.Add(new Citys { Name = item2.Name, Area = Region }); } modelCountryState.Add(new ModelCountryState { City = City, Name = item.Name }); } return(modelCountryState); }
public IActionResult AddARegion([FromBody] RegionDto regionDto) { if (regionDto == null) { return(BadRequest(ModelState)); } if (_npRepo.RegionExists(regionDto.Name)) { ModelState.AddModelError("", "Region already exists."); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var ContactInfoObj = _mapper.Map<CreateEmployeeDto, ContactInfo>(createEmployeeDto); var regionObj = _mapper.Map <RegionDto, Region>(regionDto); // employeePIObj.ContactInfo = ContactInfoObj; if (!_npRepo.CreateRegion(regionObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {regionObj.Name}"); return(StatusCode(500, ModelState)); } return(Ok()); }
public IHttpActionResult CreateAdminRegion(RegionDto region) { if (!ModelState.IsValid) { return(BadRequest(Messages.ProcessingError)); } try { if (User.Identity.IsAuthenticated) { var destination = Mapper.Map <RegionDto, Region>(region); destination.CreatedAt = DateTime.Now; destination.RegionCode = destination.RegionCode.ToUpper(); destination.RegionName = destination.RegionName.ToUpper(); destination.AppUserId = User.Identity.GetUserId(); _uow.Region.Add(destination); _uow.Complete(); region.RegionId = destination.RegionId; } else { return(BadRequest(Messages.AuthenticationRequired)); } } catch (Exception ex) { return(BadRequest(Messages.EntityCreationError(EntityName))); } return(Ok(Messages.EntityCreationSuccess(EntityName))); }
public virtual int Add(RegionDto vm) { int count = 0; Region m = new Region() { Id = this.GetIdentity <Region>(), Name = vm.Name, Level = vm.Level, ParentId = vm.ParentId, IsDelete = false }; using (var db = this.GetContext()) { using (db.BeginTransaction(IsolationLevel.ReadCommitted)) { db.AddCommitCallback((num) => { this.regionChildCache.Remove(m.ParentId); }); db.Region.Add(m); count = db.SaveChanges(); this.regionLevelRepository.Add(m.Id, m.Level, m.ParentId, db); db.Commit(); } } return(count); }
public async Task UpdateRegion() { // Initialize the database _applicationDatabaseContext.Regions.Add(_region); await _applicationDatabaseContext.SaveChangesAsync(); var databaseSizeBeforeUpdate = _applicationDatabaseContext.Regions.Count(); // Update the region var updatedRegion = await _applicationDatabaseContext.Regions.SingleOrDefaultAsync(it => it.Id == _region.Id); // Disconnect from session so that the updates on updatedRegion are not directly saved in db //TODO detach updatedRegion.RegionName = UpdatedRegionName; RegionDto updatedRegionDto = _mapper.Map <RegionDto>(_region); var response = await _client.PutAsync("/api/regions", TestUtil.ToJsonContent(updatedRegionDto)); response.StatusCode.Should().Be(HttpStatusCode.OK); // Validate the Region in the database var regionList = _applicationDatabaseContext.Regions.ToList(); regionList.Count().Should().Be(databaseSizeBeforeUpdate); var testRegion = regionList[regionList.Count - 1]; testRegion.RegionName.Should().Be(UpdatedRegionName); }
public async Task Should_Create() { // Arrange var createDto = new RegionCreateDto { Name = "Hawaii" }; var expectedDto = new RegionDto { Name = createDto.Name, CreatedBy = _staff.DisplayName, CreatedAt = FakeDateTime.UtcNow, ModifiedAt = null, ModifiedBy = null, }; // Act HttpResponseMessage responseMessage = await _authenticatedServer .CreateClient() .AuthenticateWith(_staff) .PostAsync(ApiEndpoints.RegionsController.Post(), BuildStringContent(createDto)); // Assert responseMessage.StatusCode.Should().Be(HttpStatusCode.Created); RegionDto result = await DeserializeResponseMessageAsync <RegionDto>(responseMessage); result.Should().BeEquivalentTo(expectedDto, opt => opt .Excluding(dto => dto.Id)); result.Id.Should().NotBeEmpty(); responseMessage.Headers.Location.AbsolutePath.Should().Be($"/{ApiEndpoints.RegionsController.Get(result.Id)}"); }
public virtual RegionDto Get(string id) { RegionDto vm = this.regionCache.Get(id); if (vm == null) { using (var db = this.GetContext()) { var query = from q in db.Region where q.Id == id && q.IsDelete == false select new RegionDto { Id = q.Id, Name = q.Name, Level = q.Level, ParentId = q.ParentId }; vm = query.FirstOrDefault(); } if (vm != null) { this.regionCache.Set(id, vm); } } return(vm); }
public async Task <IActionResult> New([FromBody] RegionDto regionDto) { var errorMsg = _regionService.Validate(regionDto); if (errorMsg != null) { return(BadRequest(errorMsg)); } var newRegion = _regionService.CreateNew(regionDto); // Add country relation var countryValMsg = _regionService.AddCountryR(newRegion, regionDto); if (countryValMsg != null) { return(BadRequest(countryValMsg)); } var saved = await _regionService.SaveEf(); if (!saved) { return(BadRequest()); } return(Ok(Mapper.Map <Region, RegionDto>(newRegion))); }
public async Task <bool> SaveRegion(RegionDto dto) { throw new NotImplementedException(); using (Context db = new Context()) { void ChangeEntityStateForChilds(Region ef) { db.Entry(ef).State = EntityState.Added; foreach (Region r in ef.ChildRegs) { ChangeEntityStateForChilds(r); } } Region region = await GetRegionWithChilds(dto.Name); if (region != null) { throw new Exception("Region with same name already exists"); } region = regionMapper.Cast(dto); if (region.ChildRegs != null && region.ChildRegs.Count > 0) { ChangeEntityStateForChilds(region); } await db.SaveChangesAsync(); return(true); } }
public virtual bool Add(RegionDto vm) { bool result = false; if (vm == null) { throw new ApiParamNullException(nameof(vm)); } if (string.IsNullOrEmpty(vm.Name)) { throw new ApiParamNullException(nameof(vm.Name)); } if (!string.IsNullOrEmpty(vm.ParentId)) { var pm = this.regionRepository.Get(vm.ParentId); if (pm == null) { throw new ApiParamException(nameof(vm.ParentId)); } vm.Level = pm.Level + 1; } else { vm.ParentId = null; vm.Level = 1; } var count = this.regionRepository.Add(vm); result = true; return(result); }
public void Update(Guid id, [FromBody] RegionDto region) { var t = _uow.Regions.Get(id); t.Name = region.Name; var result = _uow.SaveChanges(); }
public async Task AddCountryToDb(CountryViewModel countryViewModel) { using var scope = _serviceProvider.CreateScope(); var countryRepository = scope.ServiceProvider.GetRequiredService <ICountryRepository>(); var cityRepository = scope.ServiceProvider.GetRequiredService <ICityRepository>(); var regionRepository = scope.ServiceProvider.GetRequiredService <IRegionRepository>(); if (countryViewModel != null) { var city = new CityDto { CityName = countryViewModel.CapitalName }; // map to dto var cityId = await cityRepository.AddCityToDbIfNotExist(city); city = await cityRepository.GetCityById(cityId); var region = new RegionDto { RegionName = countryViewModel.Region }; var regionId = await regionRepository.AddRegionToDbIfNotExist(region); region = await regionRepository.GetRegionById(regionId); var country = ConvertCountryViewModelToDto(countryViewModel, city, region); await countryRepository.AddCountryToDbIfNotExistAsync(country); } }
public async Task <IActionResult> UpdateRegion([FromBody] RegionDto regionDto) { _log.LogDebug($"REST request to update Region : {regionDto}"); if (regionDto.Id == 0) { throw new BadRequestAlertException("Invalid Id", EntityName, "idnull"); } //TODO catch //DbUpdateConcurrencyException into problem Region region = _mapper.Map <Region>(regionDto); region.UserId = region.User.Id; region.User = null; _applicationDatabaseContext.Update(region); /* Force the reference navigation property to be in "modified" state. * This allows to modify it with a null value (the field is nullable). * This takes into consideration the case of removing the association between the two instances. */ _applicationDatabaseContext.Entry(region).Reference(region0 => region0.User).IsModified = true; await _applicationDatabaseContext.SaveChangesAsync(); return(Ok(region) .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, region.Id.ToString()))); }
public async Task UpdateRegion() { // Initialize the database await _regionRepository.CreateOrUpdateAsync(_region); await _regionRepository.SaveChangesAsync(); var databaseSizeBeforeUpdate = await _regionRepository.CountAsync(); // Update the region var updatedRegion = await _regionRepository.QueryHelper().GetOneAsync(it => it.Id == _region.Id); // Disconnect from session so that the updates on updatedRegion are not directly saved in db //TODO detach updatedRegion.RegionName = UpdatedRegionName; RegionDto updatedRegionDto = _mapper.Map <RegionDto>(_region); var response = await _client.PutAsync("/api/regions", TestUtil.ToJsonContent(updatedRegionDto)); response.StatusCode.Should().Be(HttpStatusCode.OK); // Validate the Region in the database var regionList = await _regionRepository.GetAllAsync(); regionList.Count().Should().Be(databaseSizeBeforeUpdate); var testRegion = regionList.Last(); testRegion.RegionName.Should().Be(UpdatedRegionName); }
public async Task <MatchDto> GetMatchAsync(RegionDto regionDto, long matchId) { Region region = Mapper.Map <Region>(regionDto); Match match = await _riotApi.Match.GetMatchAsync(region, matchId); return(Mapper.Map <MatchDto>(match)); }
public JsonResult Update(RegionDto regionDto) { //var updateRegion = _regionService.Update(_mapper.Map<Region>(regionDto)); var result = _apiClient.Update(regionDto); _logger.LogInformation($"Updated Region Name: {result?.Name}"); return(Json(result)); }
private TblRegion createEntity(RegionDto regionDto) { return(new TblRegion() { IdRegion = regionDto.IdRegion, NombreRegion = regionDto.NombreRegion }); }
public object Create(RegionDto dto) { var entity = Mapper.Map <Region>(dto); context.Add(entity); context.SaveChanges(); return(entity.RegionId); }
private static Region MapTo(this RegionDto dto) { return(new() { RegionID = dto.RegionID, RegionDescription = dto.RegionDescription }); }
public async Task <MatchListDto> GetRecentMatchListAsync(RegionDto regionDto, string summonerName) { Region region = Mapper.Map <Region>(regionDto); Summoner summoner = await _riotApi.Summoner.GetSummonerByNameAsync(region, summonerName); MatchList matchList = await _riotApi.Match.GetMatchListAsync(region, summoner.AccountId); return(Mapper.Map <MatchListDto>(matchList)); }
public async Task <IActionResult> GetRegion([FromRoute] long id) { _log.LogDebug($"REST request to get Region : {id}"); var result = await _regionService.FindOne(id); RegionDto regionDto = _mapper.Map <RegionDto>(result); return(ActionResultUtil.WrapOrNotFound(regionDto)); }
//update Region public async Task UpdateRegion(RegionDto input) { // here aoutomapping can be done; var Region = _regionRepository.FirstOrDefault(input.Id); Region.Name = input.Name; await _regionRepository.UpdateAsync(Region); }
private async Task UpdateAsync(RegionDto input) { if (input.Id != null) { var region = await _regionRepository.FirstOrDefaultAsync((int)input.Id); ObjectMapper.Map(input, region); } }
public async Task <JsonResult> Create(RegionDto regionDto) { //var newRegion = await _regionService.AddAsync(_mapper.Map<Region>(regionDto)); var result = await _apiClient.AddAsync(regionDto); var resultJson = JsonConvert.SerializeObject(result); _logger.LogInformation($"Added Region: {resultJson}"); return(Json(resultJson)); }
public void Mapping_RegionToRegionDto_IsValid() { var from = new RegionDto() { Id = 1, Name = "abc" }; var to = mapper.Map <RegionDto, Region>(from); Assert.IsTrue(to.Id == 1 && to.Name == "abc"); }
private ProjectDto Map(Project project) { if (project == null) { return(null); } var projectDto = new ProjectDto(); projectDto.Id = project.Id; projectDto.Name = project.Name; projectDto.DXCServices = project.DXCServices; projectDto.Facts = project.Facts; projectDto.DXCSolution = project.DXCSolution; projectDto.Betriebsleistung = project.Betriebsleistung; if (project.Customer != null) { var dc = new CustomerDto(); dc.Id = project.Customer.Id; dc.Name = project.Customer.Name; projectDto.Customer = dc; } if (project.Industry != null) { var di = new IndustryDto(); di.Id = project.Industry.Id; di.Name = project.Industry.Name; projectDto.Industry = di; } foreach (Region r in project.Regions) { var dr = new RegionDto(); dr.Id = r.Id; dr.Name = r.Name; dr.KeyNamePath = r.KeyNamePath; projectDto.Regions.Add(dr); } foreach (Offering o in project.Offerings) { var doff = new OfferingDto(); doff.Id = o.Id; doff.Name = o.Name; doff.KeyNamePath = o.KeyNamePath; projectDto.Offerings.Add(doff); } foreach (Skill s in project.Skills) { var ds = new SkillDto(); ds.Id = s.Id; ds.Name = s.Name; projectDto.Skills.Add(ds); } return(projectDto); }
//delete Region public async Task DeleteRegionAsync(RegionDto input) { var Region = _regionRepository.FirstOrDefault(input.Id); if (Region == null) { throw new UserFriendlyException("Region not Found!"); } await _regionRepository.DeleteAsync(Region); }
public async Task GetChild(RegionDto td, string Id, string GroupId) { var ret = await _rr.Find(a => a.ParentId == Id && a.GroupId == GroupId).ToListAsync(); foreach (var item in ret) { var dto = _mapper.Map <RegionDto>(item); td.Child.Add(dto); await GetChild(dto, item.Id, GroupId); } }
public void CanCreateDtoWithEntity() { Region region = new Region("Eastern"); region.SetAssignedIdTo(1); RegionDto regionDto = RegionDto.Create(region); regionDto.Id.ShouldEqual(1); regionDto.Description.ShouldEqual("Eastern"); }
public async Task CreateOrUpdateRegion(RegionDto input) { if (input.Id == null) { await CreateAsync(input); } else { await UpdateAsync(input); } }