Пример #1
0
        public void CreateOrganization(CreateOrganizationViewModel orgViewModel)
        {
            Organization organization = new Organization()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = orgViewModel.OrganizationName
            };
            Employee employee = new Employee()
            {
                Id             = Guid.NewGuid().ToString(),
                FirstName      = orgViewModel.CeoFirstName,
                LastName       = orgViewModel.CeoLastName,
                Email          = orgViewModel.Email,
                Password       = orgViewModel.Password,
                DoB            = orgViewModel.DoB,
                OrganizationId = organization.Id
            };

            OrganizationRepository organizationRepository = new OrganizationRepository();
            EmployeeRepository     employeeRepository     = new EmployeeRepository();

            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    organizationRepository.Add(organization);
                    employeeRepository.Add(employee);
                    transactionScope.Complete();
                }
                catch
                {
                    throw new Exception("Transaction failed");
                }
            }
        }
Пример #2
0
        public async Task <InvokeResult> CreateNewOrganizationAsync(CreateOrganizationViewModel organizationViewModel, EntityHeader user)
        {
            var result = new InvokeResult();

            ValidationCheck(organizationViewModel, Core.Validation.Actions.Create);

            //HACK: Very, small chance, but it does exist...two entries could be added at exact same time and check would fail...need to make progress, can live with risk for now.
            if (await _organizationRepo.QueryNamespaceInUseAsync(organizationViewModel.Namespace))
            {
                result.Errors.Add(new ErrorMessage(UserAdminResources.Organization_NamespaceInUse.Replace(Tokens.NAMESPACE, organizationViewModel.Namespace)));
                return(result);
            }

            var organization = new Organization();

            organization.SetId();
            organization.SetCreationUpdatedFields(user);
            organizationViewModel.MapToOrganization(organization);
            organization.Status           = UserAdminResources.Organization_Status_Active;
            organization.TechnicalContact = user;
            organization.AdminContact     = user;
            organization.BillingContact   = user;

            /* Create the Organization in Storage */
            await _organizationRepo.AddOrganizationAsync(organization);

            var currentUser = await _appUserRepo.FindByIdAsync(user.Id);

            var addUserResult = await AddUserToOrgAsync(currentUser.ToEntityHeader(), organization.ToEntityHeader(), currentUser.ToEntityHeader(), true, true);

            if (!addUserResult.Successful)
            {
                return(addUserResult);
            }

            if (currentUser.Organizations == null)
            {
                currentUser.Organizations = new List <EntityHeader>();
            }

            /* add the organization ot the newly created user */
            currentUser.Organizations.Add(organization.ToEntityHeader());

            //In this case we are creating a new org for first time through, make sure they have all the correct privelages.
            if (EntityHeader.IsNullOrEmpty(currentUser.CurrentOrganization))
            {
                currentUser.IsOrgAdmin          = true;
                currentUser.IsAppBuilder        = true;
                currentUser.CurrentOrganization = organization.ToEntityHeader();
            }

            /* Final update of the user */
            await _appUserRepo.UpdateAsync(currentUser);

            await _orgInitializer.Init(organization.ToEntityHeader(), currentUser.ToEntityHeader(), organizationViewModel.CreateGettingsStartedData);

            await LogEntityActionAsync(organization.Id, typeof(Organization).Name, "Created Organization", organization.ToEntityHeader(), user);

            return(result);
        }
        public void AddShouldMapCorrectly()
        {
            CreateOrganizationViewModel model = new CreateOrganizationViewModel();

            string url = "/Organizations/Create";

            this.routeCollection.ShouldMap(url).To<OrganizationsController>(c => c.Create(model));
        }
Пример #4
0
        public async Task <InvokeResult> CreateOrgAsync([FromBody] CreateOrganizationViewModel orgVM)
        {
            var org = await _orgManager.CreateNewOrganizationAsync(orgVM, UserEntityHeader);

            await _signInManager.SignInAsync(await this.GetCurrentUserAsync());

            return(org);
        }
Пример #5
0
        public ActionResult Create()
        {
            using (var db = ApplicationDbContext.Create())
            {
                EnsureOrganizationCreationIsAllowed(db);

                var model = new CreateOrganizationViewModel();
                return(View(model));
            }
        }
Пример #6
0
        public async Task <IActionResult> Create(CreateOrganizationViewModel organizationModel)
        {
            if (ModelState.IsValid)
            {
                await organizationService.CreateAsync(organizationModel);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(organizationModel));
        }
        public ActionResult Create(CreateOrganizationViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            Organization organization = this.organizations.Create(model.Name, this.User.Identity.GetUserId(), DateTime.Now);

            this.SetTempDataSuccessMessage(string.Format("Organization {0} successfully created!", organization.Name));

            return this.RedirectToAction("Details", new { id = organization.Id });
        }
Пример #8
0
        public async Task <ActionResult> Create(CreateOrganizationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = ApplicationDbContext.Create())
            {
                EnsureOrganizationCreationIsAllowed(db);

                if (model.HostName.StartsWith("http://"))
                {
                    model.HostName = model.HostName.Substring("http://".Length);
                }
                if (model.HostName.StartsWith("https://"))
                {
                    model.HostName = model.HostName.Substring("https://".Length);
                }


                // Create the organization.
                var org = new Organization()
                {
                    Id       = Guid.NewGuid(),
                    Name     = model.OrganizationName,
                    Hostname = model.HostName,
                    AgencyID = "int.example"
                };

                db.Organizations.Add(org);


                // Create the user.
                var thisUser = db.Users.Where(x => x.UserName == User.Identity.Name)
                               .FirstOrDefault();
                thisUser.Organizations.Add(org);

                // Make the creating user an administrator, with all rights.
                db.Permissions.Add(CreatePermission(thisUser, org, Right.CanAssignRights));
                db.Permissions.Add(CreatePermission(thisUser, org, Right.CanAssignCurator));
                db.Permissions.Add(CreatePermission(thisUser, org, Right.CanViewAllCatalogRecords));
                db.Permissions.Add(CreatePermission(thisUser, org, Right.CanEditOrganization));
                db.Permissions.Add(CreatePermission(thisUser, org, Right.CanApprove));

                db.SaveChanges();

                return(RedirectToAction("Details", new { id = org.Id }));
            }
        }
        public async Task <CreateOrganizationViewModel> CreateAsync(CreateOrganizationViewModel organizationModel)
        {
            var organization = new Organization {
                Name = organizationModel.Name
            };

            await organizationRepository.AddAsync(organization);

            await dataContext.SaveChangesAsync();

            return(new CreateOrganizationViewModel {
                Name = organizationModel.Name
            });
        }
        public async Task <InvokeResult> CreateOrgAsync([FromBody] CreateOrganizationViewModel orgVM)
        {
            var org = await _orgManager.CreateNewOrganizationAsync(orgVM, UserEntityHeader);

            var currentUser = await this.GetCurrentUserAsync();

            if (currentUser == null)
            {
                throw new RecordNotFoundException("AppUser", UserEntityHeader.Id + $"{UserEntityHeader.Id}");
            }

            if (currentUser.OwnerOrganization == null)
            {
                await _signInManager.RefreshUserLoginAsync(currentUser);
            }

//            await _signInManager.SignInAsync(currentUser);
            return(org);
        }
Пример #11
0
        public async Task <IActionResult> Create(CreateOrganizationViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var organization = new BLLOrganizationDTO
                {
                    Name = vm.Name
                };

                var result = await _bll.OrganizationsService.AddOrganizationAsync(organization);

                if (result == false)
                {
                    return(BadRequest("Something went wrong while adding the organization"));
                }
                return(RedirectToAction("Index", "Dashboard"));
            }

            return(BadRequest("Model invalid"));
        }
Пример #12
0
        public async Task <IActionResult> Create(CreateOrganizationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Create"));
            }

            return(await _organizationService.CreateAsync(viewModel.Name, UserId)
                   .ExecuteAsync(
                       onSuccess: async() =>
            {
                var organization = await _organizationService.GetAsync(viewModel.Name, UserId);
                Notify(FlashNotificationType.Success, "Organization has been created.");
                return RedirectToAction("Details", new { id = organization.Id });
            },
                       onFailure: ex =>
            {
                Notify(FlashNotificationType.Error, ex.Message);
                return RedirectToAction("Create");
            }));
        }
Пример #13
0
        public async Task CreateNewOrganizationAsync(CreateOrganizationViewModel organizationViewModel, EntityHeader user)
        {
            ValidationCheck(organizationViewModel, Core.Validation.Actions.Create);

            //HACK: Very, small chance, but it does exist...two entries could be added at exact same time and check would fail...need to make progress, can live with rish for now.
            if (await _organizationRepo.QueryNamespaceInUseAsync(organizationViewModel.Namespace))
            {
                throw new ValidationException(Resources.UserManagementResources.Organization_CantCreate, false,
                                              UserManagementResources.Organization_NamespaceInUse.Replace(Tokens.NAMESPACE, organizationViewModel.Namespace));
            }

            var organization = new Organization();

            organization.SetId();
            organization.SetCreationUpdatedFields(user);
            organizationViewModel.MapToOrganization(organization);
            organization.Status           = UserManagementResources.Organization_Status_Active;
            organization.TechnicalContact = user;
            organization.AdminContact     = user;
            organization.BillingContact   = user;

            var location = new OrganizationLocation();

            location.SetId();
            organizationViewModel.MapToOrganizationLocation(location);
            location.SetCreationUpdatedFields(user);
            location.AdminContact     = user;
            location.TechnicalContact = user;
            location.Organization     = organization.ToEntityHeader();

            organization.PrimaryLocation = location.ToEntityHeader();

            if (organization.Locations == null)
            {
                organization.Locations = new List <EntityHeader>();
            }
            organization.Locations.Add(location.ToEntityHeader());

            var currentUser = await _appUserRepo.FindByIdAsync(user.Id);

            var locationUser = new LocationAccount(organization.Id, location.Id, user.Id)
            {
                Email            = currentUser.Email,
                OrganizationName = organization.Name,
                AccountName      = currentUser.Name,
                ProfileImageUrl  = currentUser.ProfileImageUrl.ImageUrl,
                LocationName     = location.Name
            };

            locationUser.SetCreationUpdatedFields(user);

            await _organizationRepo.AddOrganizationAsync(organization);

            await AddAccountToOrgAsync(currentUser.ToEntityHeader(), organization.ToEntityHeader(), currentUser.ToEntityHeader());

            await _locationRepo.AddLocationAsync(location);

            await _locationAccountRepo.AddAccountToLocationAsync(locationUser);

            if (EntityHeader.IsNullOrEmpty(currentUser.CurrentOrganization))
            {
                currentUser.CurrentOrganization = organization.ToEntityHeader();
            }
            if (currentUser.Organizations == null)
            {
                currentUser.Organizations = new List <EntityHeader>();
            }

            currentUser.Organizations.Add(organization.ToEntityHeader());

            await _appUserRepo.UpdateAsync(currentUser);
        }
        public ActionResult Create()
        {
            CreateOrganizationViewModel model = new CreateOrganizationViewModel();

            return this.View(model);
        }