protected virtual async Task Update(CreateOrEditAddressDto input) { /// This has been updated to filter on TenantId because this data /// entity does not implement IMayHaveTenant or IMustHaveTenant... /// /// This is to enable users to read this data entity across /// Tenants under specific circumstances... /// /// For those cases, a new AppService method should be produced /// var address = await _addressRepository.FirstOrDefaultAsync((int)input.Id); if (AbpSession.TenantId != null) { if (address.TenantId == AbpSession.TenantId) { ObjectMapper.Map(input, address); } else { //TODO: RAISE A SECURITY EXCEPTION } } else // this should only be the case if a HOST user is logged in { ObjectMapper.Map(input, address); } }
public async Task <IActionResult> Create([FromBody] CreateOrEditAddressDto dto) { var address = await _addressesService.Create(await _usersService.GetCurrentUserAsync(), dto.FirstName, dto.Lastname, dto.Country, dto.City, dto.StreetAddress, dto.ZipCode); return(StatusCodeAndDtoWrapper.BuildSuccess(AddressDto.Build(address))); }
protected virtual async Task Create(CreateOrEditAddressDto input) { var address = ObjectMapper.Map <Address>(input); if (AbpSession.TenantId != null) { address.TenantId = (int?)AbpSession.TenantId; } await _addressRepository.InsertAsync(address); }
/// <summary> /// A megadott azonosítójú lakcím szerkesztése, ha a lakcím az aktuális felhasználójoz tartozik. /// </summary> /// <param name="addressId">A cím azonosítója.</param> /// <param name="address">A lakcím módosítandó adatai.</param> /// <returns>A módosított cím adatai.</returns> public async Task <AddressWithIdDto> EditUserAddress(int addressId, CreateOrEditAddressDto address) { string userId = httpContext.GetCurrentUserId(); string addressUserId = await userRepository.GetUserAddressUserId(addressId); if (userId == addressUserId) { return(await userRepository.EditUserAddress(addressId, address)); } throw new ProblemDetailsException(StatusCodes.Status400BadRequest, "A megadott azonosítóval rendelkező lakcím szerkesztéséhez nincs jogosultságod."); }
/// <summary> /// A megadott azonosítójú lakcím szerkesztése. /// Ha a megadott lakcím nem található, akkor kivételt dobunk. /// </summary> /// <param name="addressId">A cím azonosítója.</param> /// <param name="address">A lakcím módosítandó adatai.</param> /// <returns>A módosított cím adatai.</returns> public async Task <AddressWithIdDto> EditUserAddress(int addressId, CreateOrEditAddressDto address) { var dbUserAddress = (await dbContext.UserAddresses .SingleOrDefaultAsync(ua => ua.Id == addressId)) .CheckIfUserAddressNull(); dbUserAddress.Address.ZipCode = address.ZipCode; dbUserAddress.Address.City = address.City; dbUserAddress.Address.Street = address.Street; dbUserAddress.Address.PhoneNumber = address.PhoneNumber; await dbContext.SaveChangesAsync(); return(await dbContext.Entry(dbUserAddress).ToAddressWithIdDto()); }
public async Task CreateOrEdit(CreateOrEditAddressDto input) { input.CustomerId = (input.CustomerId == 0) ? (int?)null : input.CustomerId; input.VendorId = (input.VendorId == 0) ? (int?)null : input.VendorId; input.AssetOwnerId = (input.AssetOwnerId == 0) ? (int?)null : input.AssetOwnerId; if (input.Id == null) { await Create(input); } else { await Update(input); } }
public async Task <IActionResult> OnGetAsync(int addressId) { try { var addressWithId = await userManager.GetUserAddress(addressId); UserAddressId = addressId; UserAddress = new CreateOrEditAddressDto { ZipCode = addressWithId.ZipCode, City = addressWithId.City, Street = addressWithId.Street, PhoneNumber = addressWithId.PhoneNumber }; } catch (Exception) { ModelState.AddModelError("Error", "Hiba történt a lakcím betöltése során, kérem próbálja újra."); } return(Page()); }
/// <summary> /// Lakcím felvétele a megadott azonosítójú felhasználóhoz. /// Ha a megadott felhasználó nem található, akkor kivételt dobunk. /// </summary> /// <param name="userId">A felhasználó azonosítója.</param> /// <param name="address">A létrehozandó lakcím adatai.</param> /// <returns>A létrehozott cím adatai.</returns> public async Task <AddressWithIdDto> CreatetUserAddress(string userId, CreateOrEditAddressDto address) { var dbUser = (await dbContext.Users .SingleOrDefaultAsync(u => u.Id == userId)) .CheckIfUserNull(); var dbUserAddress = new UserAddress { Address = new AddressOwned { ZipCode = address.ZipCode, City = address.City, Street = address.Street, PhoneNumber = address.PhoneNumber }, User = dbUser }; await dbContext.UserAddresses.AddAsync(dbUserAddress); await dbContext.SaveChangesAsync(); return(await dbContext.Entry(dbUserAddress).ToAddressWithIdDto()); }
public async Task <ActionResult <AddressWithIdDto> > GetUserAddress([FromBody] CreateOrEditAddressDto address) { var createdAddress = await userManager.CreateUserAddress(address); return(CreatedAtAction(nameof(GetUserAddress), new { id = createdAddress.Id }, createdAddress)); }
/// <summary> /// Lakcím létrehozása az aktuális felhasználóhoz. /// </summary> /// <param name="address">A létrehozandó lakcím adatai.</param> /// <returns>A létrehozott lakcím.</returns> public async Task <AddressWithIdDto> CreateUserAddress(CreateOrEditAddressDto address) { string userId = httpContext.GetCurrentUserId(); return(await userRepository.CreatetUserAddress(userId, address)); }