public async Task deleteSkillAsync(int skillId) { Skill skillFromRepository = await retrieveSkillAsync(skillId); if (skillFromRepository == null) { throw new NotFoundBusinessEntityException($"The skill {skillId} doesn't exist."); } FakeDataBase.getInstance().Skills.Remove(await retrieveSkillAsync(skillId)); }
public async Task deleteContactAsync(int id) { Contact contactToDelete = await retrieveContactAsync(id); if (contactToDelete == null) { throw new NotFoundBusinessEntityException($"The contact {id} doesn't exist."); } FakeDataBase.getInstance().Contacts.Remove(await retrieveContactAsync(id)); }
public async Task <Skill> createSkillAsync(Skill skill) { Skill skillFromRepository = await retrieveSkillAsync(skill.Id); if (skillFromRepository != null) { throw new BusinnessDomainException($"The contact {skill.Id} already exists"); } FakeDataBase.getInstance().Skills.Add( new Skill { Id = skill.Id, Name = skill.Name, Level = skill.Level } ); return(await retrieveSkillAsync(skill.Id)); }
public async Task <Contact> createContactAsync(Contact contact) { Contact contactFromRepository = await retrieveContactAsync(contact.Id); if (contactFromRepository != null) { throw new BusinnessDomainException($"The contact {contact.Id} already exists"); } FakeDataBase.getInstance().Contacts.Add( new Contact { Id = contact.Id, FirstName = contact?.FirstName, LastName = contact?.LastName, Address = contact?.Address, Email = contact?.Email } ); return(await retrieveContactAsync(contact.Id)); }
public Contact removeSkillFromContact(int skillId, int contactId) { Skill skill = FakeDataBase.getInstance().Skills.FirstOrDefault <Skill>(s => s.Id == skillId); if (skill == null) { throw new BusinnessDomainException($"The skill {skillId} does not exist"); } Contact contact = FakeDataBase.getInstance().Contacts.FirstOrDefault <Contact>(c => c.Id == contactId); if (contact == null) { throw new BusinnessDomainException($"The contact {contactId} does not exist"); } if (contact.Skills.Contains(skill)) { contact.Skills.Remove(skill); } return(contact); }
public async Task <long> longCountAsync() => await FakeDataBase.getInstance().Contacts.ToAsyncEnumerable <Contact>().LongCount <Contact>();
public async Task <Contact> retrieveContactAsync(int id) => await FakeDataBase.getInstance().Contacts.ToAsyncEnumerable().SingleOrDefault(m => m.Id == id);
public Task <IEnumerable <Contact> > retrieveAllContactsAsync() => Task <long> .Run(() => FakeDataBase.getInstance().Contacts.AsEnumerable <Contact>());
public async Task <long> longCountAsync() => await FakeDataBase.getInstance().Skills.ToAsyncEnumerable <Skill>().LongCount <Skill>();
public async Task <Skill> retrieveSkillAsync(int id) => await FakeDataBase.getInstance().Skills.ToAsyncEnumerable().SingleOrDefault(m => m.Id == id);
public Task <IEnumerable <Skill> > retrieveAllSkillsAsync() => Task <long> .Run(() => FakeDataBase.getInstance().Skills.AsEnumerable <Skill>());