コード例 #1
0
        private async Task <Result> UpdateContacts(List <Contact> contacts, BankAccount currentAccount, BankAccount updatedAccount)
        {
            Result result = null;

            foreach (var contact in contacts)
            {
                if (currentAccount.ContactIds.Contains(contact.Id))
                {
                    result = await _contactsService.UpdateContact(contact);

                    currentAccount.ContactIds.Remove(contact.Id);
                }
                else
                {
                    result = await _contactsService.CreateContact(contact);
                }

                if (!result.Success)
                {
                    return(result);
                }

                updatedAccount.ContactIds.Add(contact.Id);
            }

            foreach (int contactId in currentAccount.ContactIds)
            {
                await _contactsService.DeleteContact(contactId);
            }

            return(Result.Ok());
        }
コード例 #2
0
        public ActionResult <DeleteContactResponse> DeleteContact(string id)
        {
            var result = _contactsService.DeleteContact(id);

            return(new DeleteContactResponse
            {
                Success = result
            });
        }
コード例 #3
0
        public async Task <IActionResult> DeleteContact([FromRoute] long id, CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _contactsService.DeleteContact(id, ct);

            return(Ok());
        }
コード例 #4
0
ファイル: ChatHub.cs プロジェクト: SpenserDavis/ScrubsData
        public async Task DeleteContact(int contact)
        {
            int userId = _auth.GetCurrentUserId();

            try
            {
                _contactsService.DeleteContact(userId, contact);
                await Clients.User($"{userId}").SendAsync("DeleteContact", contact);
            }
            catch (Exception ex)
            {
                await Clients.User($"{userId}").SendAsync("DeleteContact", null, ex);
            }
        }
コード例 #5
0
        public async Task <IActionResult> DeleteContact(string id)
        {
            try
            {
                await _service.DeleteContact(id);

                return(Ok("Contact Deleted."));
            }
            catch (Exception ex)
            {
                _logger.LogError($"An exception occurred while deleting the contact: {ex.Message}");
            }
            return(BadRequest("Failed to delete the contact."));
        }
コード例 #6
0
        public void DeleteContact_Should_Remove_Contact_From_Database_But_Keep_Person()
        {
            WhatsAppContact contactOnDb = new WhatsAppContact {
                Person = new Person {
                    Name = "name"
                }, Name = "home", WhatsAppNumber = "0000-0000"
            };

            _contactRepository.Add(contactOnDb);

            _contactsService.DeleteContact(contactOnDb);

            IEnumerable <Contact> contactsOnDb = _contactRepository.RetrieveAll();
            IEnumerable <Person>  personOnDb   = _personRepository.RetrieveAll();

            contactsOnDb.Should().BeEmpty();
            personOnDb.Should().HaveCount(1);
        }
コード例 #7
0
        public void Delete(int personID, int contactID)
        {
            Contact contactToDelete = _contactsService.GetContactByID(contactID);

            _contactsService.DeleteContact(contactToDelete);
        }
コード例 #8
0
        public void ProcessInput(int input)
        {
            switch (input)
            {
            case 1:
            {
                PrintMessage(Constants.NameMessage);
                string name = Console.ReadLine();
                PrintMessage(Constants.LastNameMessage);
                string        lastName = Console.ReadLine();
                List <string> phones   = GetPhoneList();
                PrintMessage(Constants.AddressMessage);
                string address = Console.ReadLine();
                if (address.Equals(string.Empty))
                {
                    address = " ";
                }

                if (name.Equals(string.Empty) || lastName.Equals(string.Empty))
                {
                    PrintMessage(Constants.InvalidParameterMessage);
                    break;
                }


                try
                {
                    _contactsService.CreateContact(name, lastName, phones, address);
                }
                catch
                {
                    Console.WriteLine(Constants.InvalidParameterMessage);
                }

                string data = _contactsService.GetContactsData();
                _databaseService.UpdateFile(data);

                break;
            }

            case 2:
            {
                PrintMessage(Constants.UpdateMessage);
                int     contactId = int.Parse(Console.ReadLine());
                Contact contact   = _contactsService.GetContactById(contactId);
                if (contact == null)
                {
                    PrintMessage(Constants.IdNotFoundMessage);
                    break;
                }

                PrintMessage(Constants.NameMessage);
                string name = Console.ReadLine();

                PrintMessage(Constants.LastNameMessage);
                string lastName = Console.ReadLine();

                if (name.Equals(string.Empty) || lastName.Equals(string.Empty))
                {
                    PrintMessage(Constants.InvalidParameterMessage);
                    break;
                }

                List <string> phones = GetPhoneList();

                PrintMessage(Constants.AddressMessage);
                string address = Console.ReadLine();

                _contactsService.UpdateContact(contact, name, lastName, phones, address);
                string data = _contactsService.GetContactsData();
                _databaseService.UpdateFile(data);

                break;
            }

            case 3:
            {
                PrintMessage(Constants.DeleteMessage);
                int     contactId = int.Parse(Console.ReadLine());
                Contact contact   = _contactsService.GetContactById(contactId);
                if (contact == null)
                {
                    PrintMessage(Constants.IdNotFoundMessage);
                    break;
                }

                _contactsService.DeleteContact(contact);

                string data = _contactsService.GetContactsData();
                _databaseService.UpdateFile(data);
                break;
            }

            case 4:
            {
                List <Contact> contacts = _contactsService.ContactList;
                PrintAllContacts(contacts);
                break;
            }
            }
        }