public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } _logger.LogInformation(LoggingEvents.GetItem, "Get Address {ID}", id); var address = await _addressService.GetAddress(id.Value); if (address == null) { _logger.LogInformation(LoggingEvents.GetItemNotFound, "Get Address {ID} NOT FOUND", id); return(NotFound()); } Address = new AddressInputDto { Id = address.Id, City = address.City, ZipCode = address.ZipCode, StreetAddress = address.StreetAddress }; return(Page()); }
public async Task CreateAddress(AddressInputDto addressDto) { Address address = new Address { Name = addressDto.Name, City = addressDto.City, ZipCode = addressDto.ZipCode.Value, StreetAddress = addressDto.StreetAddress, Latitude = addressDto.Latitude, Longitude = addressDto.Longitude, IsInUse = addressDto.IsInUse }; _dbContext.Addresses.Add(address); await _dbContext.SaveChangesAsync(); }
public async Task EditAddress(AddressInputDto addressDto) { var address = await _dbContext.Addresses .Where(a => a.Id == addressDto.Id) .SingleOrDefaultAsync(); address.Name = addressDto.Name; address.City = addressDto.City; address.ZipCode = addressDto.ZipCode.Value; address.StreetAddress = addressDto.StreetAddress; address.Latitude = addressDto.Latitude; address.Longitude = addressDto.Longitude; address.IsInUse = addressDto.IsInUse; _dbContext.Attach(address).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); }