public IHttpActionResult PostUserAddress(ZipLocationDTO zipLocationDTO) { // Check Authorization header for valid Jwt. string username = _accountControllerLogic.GetUsername(Request.Headers.Authorization.ToString()); if (username != null) { var account = _accountLogic.GetByUsername(username); string email = account.Email; var user = _userProfileLogic.GetSingle(email); // If a zipLocation id was provided if (zipLocationDTO.ZipCodeID >= 0) { // Iterate through all the user's addresses foreach (var address in user.ZipLocations) { // Match the provided id with one of the user's addresses if (address.ZipCodeId == zipLocationDTO.ZipCodeID) { // Update address.Address = zipLocationDTO.Address; address.City = zipLocationDTO.City; address.State = zipLocationDTO.State; address.ZipCode = zipLocationDTO.ZipCode; _zipLocationLogic.Update(address); return(Ok()); } } // If this point is reached it means the id provided does not // pertain to the given user return(BadRequest("No records were updated.")); } // No valid zipLocation id was provided, so a new entry is required else { ZipLocation zipLocation = new ZipLocation { Address = zipLocationDTO.Address, City = zipLocationDTO.City, State = zipLocationDTO.State, ZipCode = zipLocationDTO.ZipCode }; user.ZipLocations.Add(zipLocation); _userProfileLogic.Update(user); return(Ok()); } } // Jwt is either invalid or missing else { return(Unauthorized()); } }
public void Update(ZipLocation zipLocation) { _zipLocationRepository.Update(zipLocation); }
public void Delete(ZipLocation zipLocation) { _zipLocationRepository.Delete(zipLocation); }
public void Create(ZipLocation zipLocation) { _zipLocationRepository.Insert(zipLocation); }