Exemplo n.º 1
0
        public Models.OrganizationResponse Initialize(Models.OrganizationRequest value)
        {
            Models.OrganizationResponse response = new Models.OrganizationResponse();

            bool existingOrganization;
            Guid organization;
            Guid group;
            Guid user;
            Guid securityToken;
            Guid userIdGuid;

            try
            {
                //Test to see if an Organization of the same name already exists
                if (existingOrganization = TestForExistingOrganization(value))
                {
                    //Log Failure
                    response.Status        = "error";
                    response.Message       = "organization already exists";
                    response.Id            = errorGuid;
                    response.SecurityToken = errorGuid;
                    return(response);
                }
                else
                {
                    //Create a new User Id UUID
                    userIdGuid = Guid.NewGuid();

                    //Create a new Organization
                    if ((organization = CreateOrganization(value, userIdGuid)) != errorGuid)
                    {
                        if ((group = CreateGroup(organization, userIdGuid)) != errorGuid)
                        {
                            //Create a User with Creator Role priveleges within the new Organization
                            if ((user = CreateUser(value, organization, userIdGuid, out securityToken)) != errorGuid)
                            {
                                //Log Success
                                response.Status        = "success";
                                response.Message       = "initialization succeeded";
                                response.Id            = user;
                                response.SecurityToken = securityToken;
                                return(response);
                            }
                            else
                            {
                                //Log Failure
                                response.Status        = "error";
                                response.Message       = "user was not created";
                                response.Id            = errorGuid;
                                response.SecurityToken = errorGuid;
                                return(response);
                            }
                        }
                        else
                        {
                            //Log Failure
                            response.Status        = "error";
                            response.Message       = "group was not created";
                            response.Id            = errorGuid;
                            response.SecurityToken = errorGuid;
                            return(response);
                        }
                    }
                    else
                    {
                        //Log Failure
                        response.Status        = "error";
                        response.Message       = "organization was not created";
                        response.Id            = errorGuid;
                        response.SecurityToken = errorGuid;
                        return(response);
                    }
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                _logger.LogError(ex, "initialization failed");

                response.Status  = "error";
                response.Message = "initialization failed";
                response.Id      = errorGuid;
                return(response);
            }
        }
        public Models.OrganizationResponse Initialize(Models.OrganizationRequest value)
        {
            Models.OrganizationResponse response = new Models.OrganizationResponse();

            bool existingOrganization;
            long organization;
            long thingGroup;
            long user;
            long securityToken = 0;

            try
            {
                //Ensure user agreed to the terms and policies before creating a new Organization
                if (value.AgreeToTermsAndPolicies != 0)
                {
                    //Test to see if an Organization of the same name already exists
                    if (existingOrganization = TestForExistingOrganization(value))
                    {
                        //Log Failure
                        response.Status        = "error";
                        response.Message       = "organization already exists";
                        response.Id            = 0;
                        response.SecurityToken = 0;
                        return(response);
                    }
                    else
                    {
                        //Create a new Organization
                        if ((organization = CreateOrganization(value)) != 0)
                        {
                            if ((thingGroup = CreateThingGroup(organization)) != 0)
                            {
                                //Create a User with Creator Role priveleges within the new Organization
                                if ((user = CreateUser(value, organization, out securityToken)) != 0)
                                {
                                    //Log Success
                                    response.Status        = "success";
                                    response.Message       = "initialization succeeded";
                                    response.Id            = user;
                                    response.SecurityToken = securityToken;
                                    return(response);
                                }
                                else
                                {
                                    //Log Failure
                                    response.Status        = "error";
                                    response.Message       = "user was not created";
                                    response.Id            = 0;
                                    response.SecurityToken = 0;
                                    return(response);
                                }
                            }
                            else
                            {
                                //Log Failure
                                response.Status        = "error";
                                response.Message       = "thing group was not created";
                                response.Id            = 0;
                                response.SecurityToken = 0;
                                return(response);
                            }
                        }
                        else
                        {
                            //Log Failure
                            response.Status        = "error";
                            response.Message       = "organization was not created";
                            response.Id            = 0;
                            response.SecurityToken = 0;
                            return(response);
                        }
                    }
                }
                else
                {
                    //Log Failure
                    response.Status        = "error";
                    response.Message       = "user did not agree to terms and policies";
                    response.Id            = 0;
                    response.SecurityToken = 0;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                //Log Exception
                //_logger.LogError(ex, "initialization failed");

                response.Status  = "error";
                response.Message = "initialization failed";
                response.Id      = 0;
                return(response);
            }
        }