public static Contact CreateDomainContact(this DbContact contact) => new Contact( contact.Id, contact.Name, contact.DateOfBirth, CreateDomainAddress(contact), CreateDomainPhoneNumbers(contact));
public Contact UpdateContact(Contact contact) { DbContact dbContact = _context.Contacts .Include(c => c.PhoneNumbers) .FirstOrDefault(c => c.Id == contact.Id); if (dbContact == default) { throw new ContactNotFoundException(); } UpdateContactProperties(dbContact, contact); _context.Contacts.Update(dbContact); try { _context.SaveChanges(); } catch (DbUpdateException ex) when(ex.InnerException is Npgsql.PostgresException sqlException && sqlException.SqlState == UniqueConstraintException) { throw new ContactAlreadyExistsException(); } return(dbContact.CreateDomainContact()); }
public ActionResult passQuery(DbContact contact) { //generate the query to check the user name or passwod Dbclass instance = new Dbclass(); instance.Addcontact(contact.txtName, "ijok", "@as.com", "asas"); return(View("Cofirmation")); }
private static Address CreateDomainAddress(DbContact contact) => new Address( contact.AddressLine1, contact.AddressLine2, contact.AddressLine3, contact.City, contact.State, contact.Zip, contact.Country );
public Contact GetContact(Guid id) { DbContact contact = _context.Contacts .Include(c => c.PhoneNumbers).FirstOrDefault(c => c.Id == id); if (contact == default) { throw new ContactNotFoundException(); } return(contact.CreateDomainContact()); }
public void DeleteContact(Guid id) { DbContact contact = _context.Contacts .FirstOrDefault(c => c.Id == id); if (contact == default) { throw new ContactNotFoundException(); } _context.Contacts.Remove(contact); _context.SaveChanges(); }
private void UpdateContactProperties(DbContact dbContact, Contact contact) { dbContact.AddressLine1 = contact.Address?.AddressLine1; dbContact.AddressLine2 = contact.Address?.AddressLine2; dbContact.AddressLine3 = contact.Address?.AddressLine3; dbContact.City = contact.Address?.City; dbContact.State = contact.Address?.State; dbContact.Country = contact.Address?.Country; dbContact.Zip = contact.Address?.Zip; dbContact.Name = contact.Name; dbContact.DateOfBirth = contact.DateOfBirth; dbContact.PhoneNumbers = MapPhoneNumbers(contact.PhoneNumbers); }
public override async Task AddContactAsync(string address, bool accepted, string publicKeyAddress) { await Task.Run(() => { var contact = new DbContact() { ChatAddress = address, PublicKeyAddress = publicKeyAddress, Accepted = accepted }; AppBase.Database.Contact.AddObject(contact); }); }
public override void Init(string data = null) { base.Init(data); if (string.IsNullOrEmpty(data)) { return; } var json = JArray.Parse(data); _user = JsonConvert.DeserializeObject <DbUser>(JsonConvert.SerializeObject(json[0])); _contact = JsonConvert.DeserializeObject <DbContact>(JsonConvert.SerializeObject(json[1])); _user.NtruKeyPair = NtruEncryption.Key.CreateAsymmetricKeyPair(_user.Seed.ToLower(), _user.PublicKeyAddress); }
public static DbContact MapToDbContact(this Contact contact) { var dbContact = new DbContact(); dbContact.Id = contact.Id; dbContact.AddressLine1 = contact.Address?.AddressLine1; dbContact.AddressLine2 = contact.Address?.AddressLine2; dbContact.AddressLine3 = contact.Address?.AddressLine3; dbContact.City = contact.Address?.City; dbContact.State = contact.Address?.State; dbContact.Country = contact.Address?.Country; dbContact.Zip = contact.Address?.Zip; dbContact.Name = contact.Name; dbContact.DateOfBirth = contact.DateOfBirth; dbContact.PhoneNumbers = MapPhoneNumbers(contact.PhoneNumbers); return(dbContact); }
public void InsertContact(Contact contact) { DbContact dbContact = _context.Contacts .FirstOrDefault(c => c.Name == contact.Name && c.AddressLine1 == contact.Address.AddressLine1 && c.AddressLine2 == contact.Address.AddressLine2 && c.AddressLine3 == contact.Address.AddressLine3 && c.City == contact.Address.City && c.State == contact.Address.State && c.Zip == contact.Address.Zip && c.Country == contact.Address.Country); if (dbContact != default) { throw new ContactAlreadyExistsException(dbContact.CreateDomainContact()); } _context.Contacts.Add(contact.MapToDbContact()); _context.SaveChanges(); }
/// <summary> /// Get contact by phone /// </summary> /// <param name="phoneNumber"></param> /// <returns>DbContact</returns> public static DbContact GetContactByPhone(string phoneNumber) { dbContext = new ZoiperdbContext(AuthenticateConnectionToDB()); ApplicationLog.WriteEventToLog("Path to ZoiperDB from GetContactByPhone: " + AuthenticateConnectionToDB()); DbContact contact = new DbContact(); try { TblPhoneContact tblContact = dbContext.TblPhoneContact.Where(x => x.Telephone == phoneNumber).FirstOrDefault(); contact = new DbContact(tblContact.ContactName, tblContact.Telephone, tblContact.Organization, tblContact.Url); //return contact; ApplicationLog.WriteEventToLog(string.Format("Name: {0}, Phone: {1}, Organization: {2}, Url: {3}", contact.FullName, contact.Phone, contact.Company, contact.Url)); } catch (Exception ex) { ApplicationLog.WriteEventToLog(ex.ToString()); //LibraryLog.WriteErrorLog(ex.Message); //return contact; } return(contact); }
private void Dial_Click(object sender, RoutedEventArgs e) { if (Model.Isincoming) { //txtCallStatus.Text = Model.callState.ToString(); lblCalleeNumber.Visibility = Visibility.Visible; lblCalleeNumber.Content = $"{Model.SelectedCall.DialInfo.CallerID} -- {Model.SelectedCall.DialInfo.CallerDisplay}"; Answer(); txtCallStatus.Text = Model.callState.ToString(); //InvokeGUIThread(() => { txtCallStatus.Text = ("Call accepted."); }); //TODO : CTI DbContact contact = GetContactByPhone(txtNumber.Text.Trim()); txtCallerName.Text = contact.FullName; Model.Isincoming = false; return; } Dial(CallType.Audio, false); Model.Isincoming = false; }
private static string[] CreateDomainPhoneNumbers(DbContact contact) => contact.PhoneNumbers.Select(p => p.Value).ToArray();
public override async Task <bool> RunAsync() { try { await Task.Delay(TimeSpan.FromSeconds(5)); //Execute a contacts request for the user. var response = await Interactor.ExecuteAsync( new GetContactsRequest { RequestAddress = new Address(_user.RequestAddress), PublicKeyAddress = new Address(_user.PublicKeyAddress), KeyPair = _user.NtruKeyPair }); if (response.Code == ResponseCode.Success) { //Handle contact requests for the user. await Task.Run(() => { if (response.PendingContactRequests == null || response.PendingContactRequests.Count == 0) { return; } foreach (var item in response.PendingContactRequests) { if (item.Rejected) { continue; } var contact = Database.Contact.GetContactByChatAddress(item.ChatAddress); if (contact == null) { //Add the new contact request to the database and show a notification. var request = new DbContact() { Name = item.Name, ImagePath = item.ImagePath, ChatKeyAddress = item.ChatKeyAddress, ChatAddress = item.ChatAddress, ContactAddress = item.ContactAddress, PublicKeyAddress = item.PublicKeyAddress, Accepted = false }; DependencyService.Get <INotification>().Show("New contact request", request.Name); Database.Contact.AddObject(request); } } }); //Update the contacts of the user. await Task.Run(() => { if (response.ApprovedContacts == null || response.ApprovedContacts.Count == 0) { return; } foreach (var item in response.ApprovedContacts) { if (item.Rejected) { continue; } var contact = Database.Contact.GetContactByChatAddress(item.ChatAddress); if (contact != null && contact.ChatKeyAddress == null) { //Update the new contact request to the database and show a notification. contact.Name = item.Name; contact.ImagePath = item.ImagePath; contact.ChatKeyAddress = item.ChatKeyAddress; contact.ChatAddress = item.ChatAddress; contact.ContactAddress = item.ContactAddress; contact.PublicKeyAddress = item.PublicKeyAddress; contact.Accepted = true; DependencyService.Get <INotification>().Show("New contact", contact.Name); Database.Contact.UpdateObject(contact); } } }); return(true); } return(false); } catch (Exception) { //Ignore return(false); } }