public void DeleteAdminProject(int adminProjectId)
        {
            AdminProject adminProject = projectsRepository.GetAdminProject(adminProjectId);

            projectsRepository.RemoveAdminProject(adminProject);
            unitOfWorkManager.Save();
        }
        public AdminProject CreateAdminProject(AdminProject adminProject)
        {
            ctx.AdminProjects.Add(adminProject);
            Project project = adminProject.Project;

            project.AdminProjects.Add(adminProject);
            ctx.SaveChanges();
            return(adminProject);
        }
Ejemplo n.º 3
0
        private static async Task WriteAsync(AdminProject project, Stream stream, CancellationToken cancellationToken)
        {
            var stringWriter = new StringWriter();
            await stringWriter.WriteLineAsync(string.Format("{0},{1},{2},{3},{4},{5},{6}",
                                                            project.Id.ToCsvValue(),
                                                            project.Name.ToCsvValue(),
                                                            project.Created.ToCsvValue(),
                                                            project.UserId.ToCsvValue(),
                                                            project.UserName.ToCsvValue(),
                                                            project.ProductType.ToCsvValue(),
                                                            project.Product.ToCsvValue()));

            byte[] bytes = Encoding.UTF8.GetBytes(stringWriter.ToString());

            await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);

            await stream.FlushAsync(cancellationToken);
        }
        public void CreateProject(Project project, int userId)
        {
            UsersManager usersManager = new UsersManager(unitOfWorkManager);
            LoggedInUser user         = usersManager.GetLoggedInUser(userId);

            project.Platform = GetPlatform(user.Platform.PlatformId);
            DataTypeManager dataTypeManager = new DataTypeManager(unitOfWorkManager);

            project.Location = dataTypeManager.CheckLocation(project.Location);
            //Project createdProject = projectsRepository.CreateProject(project);
            AdminProject adminProject = new AdminProject
            {
                Project = project,
                Admin   = user
            };

            projectsRepository.CreateAdminProject(adminProject);
            unitOfWorkManager.Save();
        }
 public void RemoveAdminProject(AdminProject adminProject)
 {
     ctx.AdminProjects.Remove(adminProject);
     ctx.SaveChanges();
 }
Ejemplo n.º 6
0
        private static void Seed(CityOfIdeasDbContext ctx)
        {
            var previousBehaviour = ctx.ChangeTracker.QueryTrackingBehavior;

            // Stel gedrag 'tracked-entities' in
            ctx.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;

            Address address = new Address {
                City = "testCity", Street = "testStreet", HouseNr = "1", ZipCode = "0000"
            };
            Location location = new Location {
                Address = address, LocationName = "test1"
            };
            Position position = new Position {
                Altitude = 0.0, Longitude = 0.0
            };


            Platform platform = new Platform
            {
                PlatformName = "test1",
                Address      = address
            };

            Project project = new Project
            {
                ProjectName = "test1",
                StartDate   = DateTime.Today,
                EndDate     = DateTime.Today.AddYears(1),
                Platform    = platform,
                Objective   = "test1",
                Description = "test1",
                Status      = "Phase1",
                Location    = location
            };
            Project project2 = new Project
            {
                ProjectName = "test2",
                StartDate   = DateTime.Today,
                EndDate     = DateTime.Today.AddYears(1),
                Platform    = platform,
                Objective   = "test2",
                Description = "test2",
                Status      = "Phase2",
                Location    = location
            };
            Phase phase = new Phase
            {
                PhaseNr     = 1,
                PhaseName   = "phasetest1",
                Description = "phasedescriptiontest1",
                StartDate   = DateTime.Today,
                EndDate     = DateTime.Today.AddMonths(1),
                Project     = project
            };
            Ideation ideation = new Ideation
            {
                CentralQuestion = "ideationtest1",
                InputIdeation   = true,
                Phase           = phase
            };


            Person person = new Person
            {
                Email     = "*****@*****.**",
                Platform  = platform,
                Password  = "******",
                RoleType  = RoleType.LOGGEDINUSER,
                ZipCode   = "0000",
                Verified  = false,
                LastName  = "testPerson1",
                FirstName = "testPerson1",
                BirthDate = new DateTime(1000, 1, 1)
            };
            Organisation organisation = new Organisation
            {
                Email            = "*****@*****.**",
                Platform         = platform,
                Password         = "******",
                RoleType         = RoleType.LOGGEDINUSER,
                ZipCode          = "0000",
                Verified         = true,
                OrganisationName = "testOrganisation1",
            };
            Person admin = new Person
            {
                Email     = "*****@*****.**",
                Platform  = platform,
                Password  = "******",
                RoleType  = RoleType.ADMIN,
                ZipCode   = "0000",
                Verified  = false,
                LastName  = "testAdmin1",
                FirstName = "testAdmin1",
                BirthDate = new DateTime(1000, 1, 1)
            };

            Idea idea = new Idea
            {
                Title        = "testIdea1",
                Ideation     = ideation,
                LoggedInUser = person
            };
            Idea idea2 = new Idea
            {
                Title        = "testIdea2",
                Ideation     = ideation,
                LoggedInUser = organisation,
            };
            Reaction reaction = new Reaction
            {
                Idea         = idea,
                ReactionText = "reactionTest1",
                LoggedInUser = person
            };
            Vote vote = new Vote
            {
                VoteType  = VoteType.VOTE,
                User      = person,
                Confirmed = true,
                Idea      = idea
            };
            Like like = new Like
            {
                Reaction     = reaction,
                LoggedInUser = person
            };

            #region Survey

            Survey survey = new Survey
            {
                Title = "SurveyTest",
                Phase = phase
            };
            Question openQuestion = new Question
            {
                QuestionNr   = 1,
                Survey       = survey,
                QuestionType = QuestionType.OPEN,
                QuestionText = "Wat is het belangrijkste voor dit plein?"
            };

            Question radioQuestion = new Question
            {
                QuestionNr   = 2,
                Survey       = survey,
                QuestionType = QuestionType.RADIO,
                QuestionText = "Voor wie is het plein het belangrijkste?"
            };

            Question checkQuestion = new Question
            {
                QuestionNr   = 3,
                Survey       = survey,
                QuestionType = QuestionType.CHECK,
                QuestionText = "Wat zou je graag willen doen op dit plein?"
            };

            Question dropQuestion = new Question
            {
                QuestionNr   = 4,
                Survey       = survey,
                QuestionType = QuestionType.DROP,
                QuestionText = "Hoe belangrijk is dit plein voor jou?"
            };

            Question emailQuestion = new Question
            {
                QuestionNr   = 5,
                Survey       = survey,
                QuestionType = QuestionType.EMAIL,
                QuestionText = "Geef je email om je stem te bevestigen!"
            };

            Answer open = new Answer
            {
                TotalTimesChosen = 0,
                Question         = openQuestion,
                AnswerText       = ""
            };

            Answer radio1 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = radioQuestion,
                AnswerText       = "Jongeren"
            };

            Answer radio2 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = radioQuestion,
                AnswerText       = "Volwassenen"
            };

            Answer radio3 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = radioQuestion,
                AnswerText       = "Ouderen"
            };

            Answer radio4 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = radioQuestion,
                AnswerText       = "Iedereen"
            };

            Answer check1 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = checkQuestion,
                AnswerText       = "Sporten"
            };

            Answer check2 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = checkQuestion,
                AnswerText       = "Spelen"
            };

            Answer check3 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = checkQuestion,
                AnswerText       = "Ontspannen"
            };

            Answer check4 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = checkQuestion,
                AnswerText       = "Geen mening"
            };

            Answer drop1 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = dropQuestion,
                AnswerText       = "Niet belangrijk"
            };

            Answer drop2 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = dropQuestion,
                AnswerText       = "Beetje belangrijk"
            };

            Answer drop3 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = dropQuestion,
                AnswerText       = "Vrij belangrijk"
            };

            Answer drop4 = new Answer
            {
                TotalTimesChosen = 0,
                Question         = dropQuestion,
                AnswerText       = "Heel belangrijk"
            };

            Answer email = new Answer
            {
                TotalTimesChosen = 0,
                Question         = emailQuestion,
                AnswerText       = ""
            };


            #endregion

            AdminProject adminProject = new AdminProject
            {
                Admin   = admin,
                Project = project
            };
            AdminProject adminProject2 = new AdminProject
            {
                Admin   = admin,
                Project = project2
            };
            admin.AdminProjects = new List <AdminProject>()
            {
                adminProject, adminProject2
            };
            platform.Users = new List <User>()
            {
                person, organisation, admin
            };
            reaction.Likes = new List <Like>()
            {
                like
            };
            idea.Reactions = new List <Reaction>()
            {
                reaction
            };
            idea.Votes = new List <Vote>()
            {
                vote
            };
            //ctx.Answers.Add(answer);
            openQuestion.Answers = new List <Answer>()
            {
                open
            };
            radioQuestion.Answers = new List <Answer>()
            {
                radio1, radio2, radio3, radio4
            };
            checkQuestion.Answers = new List <Answer>()
            {
                check1, check2, check3, check4
            };
            dropQuestion.Answers = new List <Answer>()
            {
                drop1, drop2, drop3, drop4
            };
            emailQuestion.Answers = new List <Answer>()
            {
                email
            };
            //ctx.Questions.Add(question);
            survey.Questions = new List <Question>()
            {
                openQuestion, radioQuestion, checkQuestion, dropQuestion, emailQuestion
            };
            //ctx.Surveys.Add(survey);
            phase.Surveys = new List <Survey>()
            {
                survey
            };
            //ctx.Ideas.Add(idea);
            ideation.Ideas = new List <Idea>()
            {
                idea, idea2
            };
            //ctx.Ideations.Add(ideation);
            phase.Ideations = new List <Ideation>()
            {
                ideation
            };
            //ctx.Phases.Add(phase);
            project.Phases = new List <Phase>()
            {
                phase
            };
            //ctx.Projects.AddRange(project,project2);
            platform.Projects = new List <Project>()
            {
                project, project2
            };
            ctx.Platforms.Add(platform);



            //platform.Projects.Add(project2);



            ctx.SaveChanges();
            Console.WriteLine("seed");

            foreach (var entry in ctx.ChangeTracker.Entries().ToList())
            {
                entry.State = EntityState.Detached;
            }

            // Herstel gedrag 'ChangTracker.QueryTrackingBehavior'
            ctx.ChangeTracker.QueryTrackingBehavior = previousBehaviour;
        }