Esempio n. 1
0
        public IActionResult CreateOrganization(CreateOrganizationModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View());
            }

            OrganizationModel org = new() {
                Name        = model.Name,
                Description = model.Description,
                WorkerIds   = new List <Guid>()
                {
                    model.CreatorId
                }
            };

            bool didCreate = _db.CreateOrganization(org);

            if (didCreate == false)
            {
                return(View()); // TODO: Tell user that the name is taken.
            }

            org = _db.GetOrganization(model.Name); // fetch mongo generated id.

            AssignmentModel assignment = new()
            {
                AssigneeId        = model.CreatorId,
                AssigneeAccess    = UserPosition.ADMIN,
                OrganizationId    = org.Id,
                ProjectIdTreePath = null,
                HoursLogged       = 0
            };

            _db.CreateAssignment(assignment);

            return(RedirectToAction(nameof(AccountController.Home), "Account", assignment));
        }

        [Authorize("Organization_ADMIN_policy")]