예제 #1
0
        public async Task <IActionResult> postDeleteAccount([FromForm] string password)
        {
            if (!isLoggedIn)
            {
                return(Json(new { status = "error", error = "Je bent niet ingelogd. Log opnieuw in a.u.b." }));
            }

            using (var context = new OverstagContext())
            {
                var account = context.Accounts.Include(f => f.Auths).Include(g => g.Invoices).Include(h => h.Payments).Include(i => i.Subscriptions).Include(j => j.Votes).Include(x => x.Transactions).First(k => k.Id == currentUser.Id);

                if (!Encryption.PBKDF2.Verify(account.Password, password))
                {
                    return(Json(new { status = "error", error = "Wachtwoord is onjuist" }));
                }

                if (account.Invoices.Count(f => !f.Paid) > 0)
                {
                    return(Json(new { status = "error", error = "Er staan nog onbetaalde facturen open." }));
                }

                if (account.Subscriptions.Count(f => !f.Paid) > 0)
                {
                    return(Json(new { status = "error", error = "Er staan nog activiteiten open." }));
                }

                try
                {
                    //All data is removed thanks to cascade and the includes
                    //Remove mollie integration
                    try
                    {
                        if (!string.IsNullOrEmpty(account.MollieID))
                        {
                            CustomerClient customerClient = new CustomerClient(Core.General.Credentials.mollieApiToken);
                            await customerClient.DeleteCustomerAsync(account.MollieID);
                        }
                    }
                    catch (Exception e)
                    {
                        return(Json(new { status = "warning", warning = "Mollie integratie verwijderen mislukt", debuginfo = e.ToString() }));
                    }

                    //Remove account
                    context.Accounts.Remove(account);
                    await context.SaveChangesAsync();

                    return(Json(new { status = "success" }));
                }
                catch (Exception e)
                {
                    return(Json(new { status = "error", error = "Er is een interne fout opgetreden", debuginfo = e.ToString() }));
                }
            }
        }
예제 #2
0
        public async Task CanDeleteCustomer()
        {
            // If: We retrieve the customer list
            ListResponse <CustomerResponse> response = await CustomerClient.GetCustomerListAsync();

            if (response.Items.Count == 0)
            {
                Assert.Inconclusive("No customers found. Unable to test deleting customers");
            }

            // When: We delete one of the customers in the list
            string customerIdToDelete = response.Items.First().Id;
            await CustomerClient.DeleteCustomerAsync(customerIdToDelete);

            // Then: Make sure its deleted
            AggregateException aggregateException = Assert.ThrowsException <AggregateException>(() => CustomerClient.GetCustomerAsync(customerIdToDelete).Wait());
            MollieApiException mollieApiException = aggregateException.InnerExceptions.FirstOrDefault(x => x.GetType() == typeof(MollieApiException)) as MollieApiException;

            Assert.AreEqual((int)HttpStatusCode.Gone, mollieApiException.Details.Status);
        }
        public async Task CanDeleteCustomer()
        {
            // If: We retrieve the customer list
            var response = await CustomerClient.GetCustomerListAsync();

            if (response.Items.Count == 0)
            {
                Assert.Empty(response.Items);  //No customers found. Unable to test deleting customers
                return;
            }

            // When: We delete one of the customers in the list
            var customerIdToDelete = response.Items.First().Id;
            await CustomerClient.DeleteCustomerAsync(customerIdToDelete);

            // Then: Make sure its deleted
            var mollieApiException = await Assert.ThrowsAsync <MollieApiException>(() => CustomerClient.GetCustomerAsync(customerIdToDelete));

            Assert.Equal((int)HttpStatusCode.Gone, mollieApiException.Details.Status);
        }
예제 #4
0
        public async Task <ResponseBase <bool> > DeleteCustomer(long id)
        {
            var response = new ResponseBase <bool>();
            var service  = new CustomerClient();

            try
            {
                var callback = await service.DeleteCustomerAsync(id);

                response.Code    = callback.Code;
                response.Data    = callback.Data;
                response.Message = callback.Message;
            }
            catch (Exception ex)
            {
                response.Code    = StatusCode.ServiceUnavailable;
                response.Message = $"Ups! no se pudo crear el usuario: {ex.Message}";
            }

            service.Close();
            return(response);
        }