Exemplo n.º 1
0
        public async Task <string> Execute(int contactId)
        {
            if (contactId <= 0)
            {
                throw new ClientError("Failed to delete contact. Invalid contact id recieved.");
            }



            var targetContact = _eFUoW.ContactsRepo.GetBy(contactId);

            if (targetContact == null)
            {
                throw new ClientError("Failed to delete contact. User not found.");
            }

            try
            {
                await _eFUoW.BeginTransactionAsync();

                _eFUoW.ContactsRepo.Delete(targetContact);

                await _eFUoW.SaveChnages();

                await _eFUoW.SaveTransactionAsync();

                return("Success");
            }
            catch
            {
                await _eFUoW.RollbackTransactionAsync();

                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <string> Execute(Contact contact)
        {
            if (contact == null)
            {
                throw new ClientError("Add contact operation failed. Invalid contact received.");
            }

            if (contact.Id != 0)
            {
                throw new ClientError("Add contact operation failed. Invalid contact received.");
            }


            contact.Trim();

            contact.Validate();


            try
            {
                await _eFUoW.BeginTransactionAsync();

                _eFUoW.ContactsRepo.Insert(contact);

                await _eFUoW.SaveChnages();

                await _eFUoW.SaveTransactionAsync();

                return("Success");
            }
            catch
            {
                await _eFUoW.RollbackTransactionAsync();

                throw;
            }
        }