コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public async Task <long> longCountAsync() => await FakeDataBase.getInstance().Contacts.ToAsyncEnumerable <Contact>().LongCount <Contact>();
コード例 #7
0
 public async Task <Contact> retrieveContactAsync(int id) => await FakeDataBase.getInstance().Contacts.ToAsyncEnumerable().SingleOrDefault(m => m.Id == id);
コード例 #8
0
 public Task <IEnumerable <Contact> > retrieveAllContactsAsync() => Task <long> .Run(() => FakeDataBase.getInstance().Contacts.AsEnumerable <Contact>());
コード例 #9
0
 public async Task <long> longCountAsync() => await FakeDataBase.getInstance().Skills.ToAsyncEnumerable <Skill>().LongCount <Skill>();
コード例 #10
0
 public async Task <Skill> retrieveSkillAsync(int id) => await FakeDataBase.getInstance().Skills.ToAsyncEnumerable().SingleOrDefault(m => m.Id == id);
コード例 #11
0
 public Task <IEnumerable <Skill> > retrieveAllSkillsAsync() => Task <long> .Run(() => FakeDataBase.getInstance().Skills.AsEnumerable <Skill>());