public IActionResult CreateProject(CreateProjectModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(new CreateProjectModel())); // todo: tell user why the input is invalid.
            }

            Guid orgId = new(User.ClaimValue(UserClaimsIndex.OrganizationModel));

            ProjectModel proj = new()
            {
                Name             = model.Name,
                Deadline         = model.Deadline,
                Description      = model.Description,
                ParentIdTreePath = model.ParentIdTreePath,
                Priority         = model.Priority,
                Status           = model.Status
            };

            _db.CreateProject(proj, orgId);

            _db.CreateAssignment(new AssignmentModel()
            {
                AssigneeAccess    = UserPosition.ADMIN, // todo: no admins for projects? should the creator be a manager?
                AssigneeId        = new Guid(User.ClaimValue(UserClaimsIndex.Id)),
                OrganizationId    = orgId,
                ProjectIdTreePath = proj.IdTreePath
            });

            return(ProjectHome(proj.IdTreePath));
        }
Exemple #2
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")]