public async Task <IHttpActionResult> PostPublicAddresses(PublicAddresses publicAddresses) { var uow = new UnitOfWork <PublicAddresses>(db); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } uow.Repository.Create(publicAddresses); uow.Commit(); PublicAddressDetailDto dto = uow.Repository.ReadAll() .Include(p => p.People) .Select(p => new PublicAddressDetailDto { Id = p.Id, AddressType = p.AddressType, City = p.City, HouseNumber = p.HouseNumber, StreetName = p.StreetName, ZipCode = p.ZipCode, People = (from ppl in p.People select ppl.LastName + ", " + ppl.FirstName) }).SingleOrDefault(p => p.Id == publicAddresses.Id); return(CreatedAtRoute("DefaultApi", new { id = publicAddresses.Id }, dto)); }
public async Task <IHttpActionResult> GetPublicAddresses(int id) { var uow = new UnitOfWork <PublicAddresses>(db); PublicAddresses addr = uow.Repository.Read(id); if (addr == null) { return(NotFound()); } var addr2 = uow.Repository.ReadAll() .Include(p => p.People) .Select(p => new PublicAddressDetailDto() { Id = p.Id, AddressType = p.AddressType, City = p.City, HouseNumber = p.HouseNumber, StreetName = p.StreetName, ZipCode = p.ZipCode, People = (from ppl in p.People select ppl.LastName + ", " + ppl.FirstName) }).SingleOrDefault(p => p.Id == id); return(Ok(addr2)); }
public void LoadFromJson(string json) { JObject data = JObject.Parse(json); if (data["version"].Value <string>() != Version) { throw new FormatException(String.Format("Invalid wallet version: {0}", data["version"].Value <ulong>())); } KeyHashes = data["key_hashes"].Value <ulong>(); IV = Base58.DecodeWithChecksum(data["encrypted"]["iv"].Value <string>()); Salt = Base58.DecodeWithChecksum(data["encrypted"]["salt"].Value <string>()); if (data["watch_addresses"] != null) { foreach (JToken key in data["watch_addresses"]) { WatchAddresses.Add(key["addr"].Value <string>(), key["label"] != null ? key["label"].Value <string>() : null); } } if (data["public_addresses"] != null) { foreach (JToken key in data["public_addresses"]) { PublicAddresses.Add(key["addr"].Value <string>(), key["label"] != null ? key["label"].Value <string>() : null); } } EncryptedData = Base58.DecodeWithChecksum(data["encrypted"]["data"].Value <string>()); }
public async Task RemoveAddressAsync(Address address) { if (IsLocked) { throw new LockedException(); } if (Addresses.Contains(address)) { if (PrivateKeys.Contains(address)) { await privateKeyLock.WaitAsync(); try { PrivateKeys.Remove(address); } finally { privateKeyLock.Release(); } } if (PublicAddresses.Contains(address)) { PublicAddresses.Remove(address); } await SaveAsync(); } else { throw new OperationException(String.Format("Your wallet doesn't contain the address {0}", address)); } }
public async Task SetLabelAsync(Address address, string label, bool isPublic = true) { if (IsLocked) { throw new LockedException(); } await privateKeyLock.WaitAsync(); try { bool wasUpdated = false; if (PrivateAddresses.Contains(address)) { PrivateKeys[address].Label = label; wasUpdated = true; } if (isPublic && PublicAddresses.Contains(address)) { PublicAddresses[address].Label = label; wasUpdated = true; } if (!wasUpdated) { throw new OperationException(String.Format("Could not find address '{0}' in your wallet", address)); } } finally { privateKeyLock.Release(); } SaveAsync(); }
public async Task ImportReadOnlyAddressAsync(AddressDetails addressDetails) { if (IsLocked) { throw new LockedException(); } PublicAddresses.Add(addressDetails); await SaveAsync(); }
public async Task <IHttpActionResult> PutPublicAddresses(int id, PublicAddresses publicAddresses) { var uow = new UnitOfWork <PublicAddresses>(db); var addr = uow.Repository.Read(id); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != publicAddresses.Id || addr == null) { return(BadRequest()); } if (publicAddresses.People != null) { //Persons are to be added to the public address addr.People.Clear(); var repo = new UnitOfWork <People>(db); foreach (var person in publicAddresses.People) { var ppl = repo.Repository.ReadAll().FirstOrDefault(e => person.Id == e.Id); if (ppl != null) { //Person with ID already exists in DB, add to address addr.People.Add(ppl); } else { //Person does not exist, add to DB and address repo.Repository.Create(person); addr.People.Add(person); } } repo.Commit(); } addr.AddressType = publicAddresses.AddressType; addr.City = publicAddresses.City; addr.HouseNumber = publicAddresses.HouseNumber; addr.StreetName = publicAddresses.StreetName; addr.ZipCode = publicAddresses.ZipCode; uow.Commit(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task HideAddressAsync(Address address) { if (IsLocked) { throw new LockedException(); } if (PrivateKeys.Contains(address) && PublicAddresses.Contains(address)) { PublicAddresses.Remove(address); await SaveAsync(); } else { // TODO: Tailor this message for both the key not being present and the address already being private throw new OperationException(String.Format("Address '{0}' isnt public", address)); } }