Exemplo n.º 1
0
        public void DeleteOrganisation()
        {
            Repository.DeleteOrganisation(NewOrganisation.OrganisationName);
            Organisation deletedOrganisation = Repository.FindOrganisationByName(NewOrganisation.OrganisationName);

            Assert.Null(deletedOrganisation);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteOrganisation(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "Organisation/DeleteOrganisation")] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function(DeleteOrganisation) processed a request.");

            try
            {
                // Validate JWT
                var accessTokenResult = _tokenProvider.ValidateToken(req);
                if (accessTokenResult.Status != AccessTokenStatus.Valid)
                {
                    return(new UnauthorizedResult());
                }

                string requestBody            = await new StreamReader(req.Body).ReadToEndAsync();
                var    userAccountCreateModel = JsonConvert.DeserializeObject <UserAccountCreateModel>(requestBody);

                // Validate Email/Password
                var loginManager = new LoginManager();
                var loginResult  = loginManager.AttemptLogin(userAccountCreateModel.EmailAddress, userAccountCreateModel.Password);
                if (loginResult.Status != LoginStatus.Success)
                {
                    return(new BadRequestObjectResult(loginResult.FailureReason));
                }

                Guid userAccountId  = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "UserAccount").Value);
                Guid organisationId = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "Organisation").Value);

                // Make sure this UserAccount is the Organisation Owner
                var organisationMembershipRepository = new OrganisationMembershipRepository();
                var organisationMembership           = organisationMembershipRepository.GetOrganisationMembership(userAccountId, organisationId);

                if (organisationMembership.UserType == UserType.OrganisationOwner)
                {
                    var  organisationRepo = new OrganisationRepository();
                    bool deleted          = organisationRepo.DeleteOrganisation(organisationId);

                    return(new OkObjectResult(deleted));
                }
                else
                {
                    return(new UnauthorizedResult());
                }
            }
            catch (Exception exception)
            {
                return(new BadRequestObjectResult(exception.Message));
            }
        }