/// <summary> /// Implementation of IPhoneBookRepository.AddContact(contact) which adds contact to database /// </summary> /// <param name="contact">Contact object to be added</param> /// <returns>Unique contact identifier</returns> public int AddContact(Contact contact) { if (contact == null || contact.Id != 0 || !IsContactConsistent(contact)) return 0; using (var db = GetPhoneBookContextInstance()) { contact.Owner = Owner; var contactRecord = new ContactRecord(contact); db.Contacts.Add(contactRecord); db.SaveChanges(); contact.Id = contactRecord.Id; return contact.Id; } }
/// <summary> /// Method checks if repository user is authorized to access ContactRecord retrieved from database /// </summary> /// <param name="contactRecord">ContactRecord retrieved from database</param> /// <returns></returns> public bool IsRecordOwner(ContactRecord contactRecord) { return contactRecord != null && contactRecord.Owner == Owner; }