Ejemplo n.º 1
0
        public override bool Execute(KitosContext context)
        {
            var commonOrg   = context.GetOrganization(TestOrganizations.CommonOrg);
            var globalAdmin = context.GetGlobalAdmin();

            var projectWithName = context.ItProjects.AsNoTracking().FirstOrDefault(x => x.Name == _name);

            if (projectWithName != null)
            {
                Console.Out.WriteLine($"Existing ItProject with name {_name} already exists in the database.");
                return(false);
            }

            var project = ItProjectFactory.Create(_name, commonOrg.Id);

            var entities = new List <IEntity>();

            entities.Add(project);
            entities.Add(project.GoalStatus);
            entities.Add(project.Handover);
            entities.AddRange(project.EconomyYears);
            entities.ForEach(entity =>
            {
                entity.ObjectOwner       = globalAdmin;
                entity.LastChangedByUser = globalAdmin;
                entity.LastChanged       = DateTime.Now;
            });

            context.ItProjects.Add(project);
            context.SaveChanges();

            return(true);
        }
Ejemplo n.º 2
0
        public Result <ItProject, OperationFailure> AddProject(string name, int organizationId)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (name.Length > ItProjectConstraints.MaxNameLength)
            {
                return(OperationFailure.BadInput);
            }
            var project = ItProjectFactory.Create(name, organizationId);

            if (!_authorizationContext.AllowCreate <ItProject>(organizationId, project))
            {
                return(OperationFailure.Forbidden);
            }

            _projectRepository.Insert(project);
            _projectRepository.Save();
            _domainEvents.Raise(new EntityCreatedEvent <ItProject>(project));
            return(project);
        }