public void AddContactForOrganization(int organizationId, int contactId) { var organization = _dataService.Organizations.FirstOrDefault(o => o.OrganizationId == organizationId); if (organization == null) { return; } var person = _dataService.Persons.FirstOrDefault(p => p.Id == contactId); if (person == null) { return; } var contacts = _dataService.Contacts.Where(c => c.Organization.OrganizationId == organizationId && c.Person.Id == contactId); if (contacts.Count() > 0) { return; } _dataService.AddContact(new Contact() { Organization = organization, Person = person, Title = "title" }); }
private async Task ExecuteSaveCommand() { MyContact contactToBeAdded = new MyContact { Name = Name.Value, Mobile = Mobile.Value, Landline = Landline.Value, ProfilePic = ProfilePic.Value, IsFavourite = IsFavorite.Value.Equals(UIConstants.UnFavorite), }; int addResult; try { addResult = await dataService.AddContact(contactToBeAdded); } catch (Exception ex) { await RootPage.DisplayAlert("Error adding contact", ex.Message, "Hmmmm"); addResult = -1; } if (addResult == 1) { await GoToContactList(); } else if (addResult != -1) { await RootPage.DisplayAlert("Contacts", "Error adding contact", "Hmmmm"); } }