Exemplo n.º 1
0
        public async Task <IActionResult> CreateOrganization([FromBody] OrganizationPostRp organizationRp)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            await _organizationService.CreateOrganization(organizationRp);

            if (_domainManagerService.HasConflicts())
            {
                return(this.Conflict(_domainManagerService.GetConflicts()));
            }

            return(this.Ok(new { OrganizationId = await _domainManagerService.GetResult <Guid>("OrganizationId") }));
        }
        public async Task CreateOrganization(OrganizationPostRp resource)
        {
            string ownerUserId  = _identityService.GetOwnerId();
            string loggedUserId = _identityService.GetUserId();

            User user = await _userRepository.GetUser(loggedUserId);

            Organization existingOrganization = user.FindOrganizationByName(resource.Name);

            if (existingOrganization != null)
            {
                await _domainManagerService.AddConflict($"The organzation name {resource.Name} has already been taken.");

                return;
            }

            Organization newOrganization = user.CreateOrganization(resource.Name, resource.Description, resource.WebSiteUrl, ownerUserId);

            _userRepository.Update(user);

            await _userRepository.SaveChanges();

            await _domainManagerService.AddResult("OrganizationId", newOrganization.OrganizationId);
        }