Exemple #1
0
        public async Task <IActionResult> Create([FromBody] CreateOrganizationModel createOrganizatinModel)
        {
            if (string.IsNullOrEmpty(createOrganizatinModel.Name))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("name")));
            }
            if (string.IsNullOrEmpty(createOrganizatinModel.Description))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("description")));
            }
            if (string.IsNullOrEmpty(createOrganizatinModel.UrlKey))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("urlKey")));
            }

            var org = new Organization
            {
                Name        = createOrganizatinModel.Name,
                Description = createOrganizatinModel.Description,
                UrlKey      = createOrganizatinModel.UrlKey,
                OrgType     = 1
            };

            var created = await OrganizationService.Create(org);

            if (created == null)
            {
                return(BadRequest());
            }

            return(Ok(created));
        }
Exemple #2
0
        public async Task <IActionResult> AddMember(string urlKey, [FromBody] AddOrganizationMemberModel model)
        {
            if (model.AccountId.Equals(Guid.Empty))
            {
                return(BadRequest());
            }

            var organization = await OrganizationService.GetByUrlKeyAsync(urlKey);

            if (organization == null)
            {
                return(BadRequest(BistroFiftyTwoError.Invalid("organization", urlKey)));
            }

            var member = await OrganizationService.GetMember(organization.ID, model.AccountId);

            if (member != null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict));
            }

            var createdBy = await SecurityService.GetCurrentUserName();

            var newMember = new OrganizationMember
            {
                OrganizationId   = organization.ID,
                AccountId        = model.AccountId,
                AccessLevel      = 1,
                CreatedBy        = createdBy,
                MembershipStatus = 1,
                ModifiedBy       = createdBy
            };

            await OrganizationService.AddMember(newMember);

            return(Ok());
        }
Exemple #3
0
        public async Task <IActionResult> CreateAccount([FromBody] CreateAccountModel createAccount)
        {
            //nts if this should go to a fluent validation thing...
            if (string.IsNullOrEmpty(createAccount.Email))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("email")));
            }
            if (string.IsNullOrEmpty(createAccount.FullName))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("fullname")));
            }
            if (string.IsNullOrEmpty(createAccount.Login))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("login")));
            }
            if (string.IsNullOrEmpty(createAccount.Password))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("password")));
            }

            var inviteCode = default(Guid);

            if (!Guid.TryParse(createAccount.InvitationCode, out inviteCode))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("invitationCode")));
            }

            // for now do the stupid, just hard code the inivite code.
            if (inviteCode != Guid.Parse(Configuration["InvitationCode"]))
            {
                return(BadRequest(BistroFiftyTwoError.Invalid("invitationCode", createAccount.InvitationCode)));
            }

            var newUserAccount = new UserAccount
            {
                Email           = createAccount.Email,
                Fullname        = createAccount.FullName,
                UserLogin       = createAccount.Login,
                AccountPassword = createAccount.Password
            };

            var existingAccount = await UserAccountService.GetByLogin(newUserAccount.UserLogin);

            if (existingAccount != null)
            {
                return(BadRequest(new BistroFiftyTwoError
                {
                    FieldName = "login",
                    ErrorType = "duplicate",
                    Description = $"{createAccount.Login} is already taken.  Please choose another login name"
                }));
            }

            var userAccount = await UserAccountService.Create(newUserAccount);

            await RoleService.GrantDefaultRoles(userAccount.ID);

            var securedAccount = new SecuredUserAccount
            {
                Email      = userAccount.Email,
                Fullname   = userAccount.Fullname,
                ID         = userAccount.ID,
                IsDisabled = userAccount.IsDisabled,
                IsLocked   = userAccount.IsLocked,
                UserLogin  = userAccount.UserLogin
            };

            return(Created($"api/accounts/{userAccount.ID}", securedAccount));
        }