public bool AddProject(string title, string description, string projectFolder, Library.User projectAdministratorUser)
        {
            User adminUser = dbUser.FindUserById(projectAdministratorUser.Id);
            if (adminUser == null)
            {
                return false;
            }

            Project project = new Project(title, description, projectFolder, adminUser);
            try
            {
                var option = new TransactionOptions();
                option.IsolationLevel = IsolationLevel.ReadCommitted;

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
                {
                    dbContext.Projects.InsertOnSubmit(project);
                    dbContext.ProjectUsers.InsertOnSubmit(new ProjectUsers { Project = project, User = project.ProjectAdministrators.FirstOrDefault(), UserType = UserType.Administrator });
                    dbContext.SubmitChanges();
                    if (true) //TODO check if the data added to db were sucessfull / valid.
                        scope.Complete();
                }
                return true;
            }
            catch (Exception e)
            {
                throw new Exception("Project not added to db " + e);
            }
        }
        private void button_CreateProject_Click(object sender, EventArgs e)
        {
            ResetVisibility();
            activeProject = null;
            UpdateProjects(false);
            //Edit visibility
            label_ProjektId.Visible = true;
            label_Title.Visible = true;
            label_Description.Visible = true;
            textBox_ProjektId.Visible = true;
            textBox_Title.Visible = true;
            textBox_Description.Visible = true;
            button_Save.Visible = true;
            button_FindUser.Visible = true;
            label_ProjectAdmin.Visible = true;
            listView_ProjectAdmin.Visible = true;
            //label_MembersProject settings
            label_MembersProject.Visible = true;
            label_MembersProject.Text = "Opret Projekt";
            label_Directory.Visible = true;
            textbox_Directory.Visible = true;

            User[] users = userService.FindAllUsers();
            listView_ProjectAdmin.Items.Clear();
            foreach (User user in users)
            {
                string id = user.Id.ToString();
                string name = user.Username;
                string email = user.Email;
                string[] row = { id, name, email };
                ListViewItem lwi = new ListViewItem(row);
                listView_ProjectAdmin.Items.Add(lwi);
            }
        }
 public UploadDialog(Project project)
 {
     InitializeComponent();
     this.tTFileName.SetToolTip(lblFileName, "Change file name if needed to project");
     this.tTFileName.SetToolTip(txtFileName, "Change file name if needed to project");
     this.Project = project;
 }
 private void GenerateProduction(Library.Project f, string destinationDirectory)
 {
     ConfigDirectories.AddProductionFolder(f.Title, "", destinationDirectory);
     foreach (Page p in f.Pages)
     {
         OutputHTML html = p.GenerateProduction();
         ConfigDirectories.AddProductionFolder(f.Title, p.Folder, destinationDirectory);
         FileStream fs = new FileStream(Path.Combine(destinationDirectory,
                                                     ConfigDirectories.RemoveLeadSlash(p.Folder),
                                                     ConfigDirectories.RemoveLeadSlash(p.Name)),
                                        FileMode.Create);
         StreamWriter sw = new StreamWriter(fs);
         sw.WriteLine(html.HTML.ToString());
         sw.Close();
         sw.Dispose();
         fs.Close();
         fs.Dispose();
     }
     foreach (Library.File s in f.Files)
     {
         ConfigDirectories.AddProductionFile(f.Title,
                                             Path.Combine(s.Folder, s.FileName),
                                             Path.Combine(ConfigDirectories.GetBuildFolder(f.Title), s.Folder, s.FileName), destinationDirectory);
     }
 }
        public int AddFile(string fileName, string fileDesc, int projectid)
        {
            Project project = new Library.Project();
            project.Id = projectid;
            File file = new File(fileName, fileDesc, project);
            User owner = new Library.User(1);
            try
            {
                file.FileLock = 1;
                file.FileLockTime = DateTime.Now;
                file.VersionNr = 1;
                var option = new TransactionOptions();
                option.IsolationLevel = IsolationLevel.ReadCommitted;

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
                {
                    bool f = dbFile.AddFIle(file);
                    FileVersion fv = new FileVersion(file.Id.ToString(), file, file.VersionNr, owner);

                    bool version = dbFileVersion.AddFileVersion(fv);

                    if (version && f)
                        scope.Complete();
                }
                return file.Id;
            }
            catch (Exception e)
            {
                throw new Exception("File not added to DB " + e);
            }
        }
 public File(string title, string description, Project project)
 {
     Title = title;
     Description = description;
     VersionNr = 1;
     FileLock = 0;
     FileLockTime = DateTime.Now;
     //   SubFiles = new List<FileVersion>();
     Project = project.Id;
 }
 public MultiUpload(Project project)
 {
     InitializeComponent();
     this.Project = project;
     openFileDialog1.Multiselect = true;
     dataGridView1.MultiSelect = false;
     dataGridView1.EditMode = DataGridViewEditMode.EditOnKeystroke;
     dataGridView1.ReadOnly = false;
     btnUpload.Enabled = false;
 }
 public File(int id, string title, string description, int verionNr, int fileLock, DateTime fileLockTime, Project project)
 {
     Id = id;
     Title = title;
     Description = description;
     VersionNr = verionNr;
     FileLock = fileLock;
     FileLockTime = fileLockTime;
     // SubFiles = new List<FileVersion>();
     Project = project.Id;
 }
        private void btnRefreshFiles_Click(object sender, EventArgs e)
        {
            if (listView_Projects.SelectedItems.Count == 1)
            {

                try
                {
                    lwFiles.Items.Clear();
                    Project activeProject = projectClient.GetProject(Convert.ToInt32(listView_Projects.SelectedItems[0].Text));
                    List<Library.File> files = activeProject.ProjectFiles;
                    foreach (Library.File file in files)
                    {
                        string[] row = { file.Id.ToString(), file.Title, file.Description };
                        ListViewItem lwi = new ListViewItem(row);
                        lwFiles.Items.Add(lwi);
                    }
                    lblFIles.Text = activeProject.Title;
                    project = activeProject;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Fejl: " + ex.Message);
                }
            }
        }
        private void listView_Projects_ItemActivate(object sender, EventArgs e)
        {
            if (listView_Projects.SelectedItems.Count == 1)
            {

                try
                {
                    lwFiles.Items.Clear();
                    Project activeProject = projectClient.GetProject(Convert.ToInt32(listView_Projects.SelectedItems[0].Text));
                    List<Library.File> files = activeProject.ProjectFiles;
                    foreach (Library.File file in files)
                    {
                        string[] row = { file.Id.ToString(), file.Title, file.Description };
                        ListViewItem lwi = new ListViewItem(row);
                        lwFiles.Items.Add(lwi);
                    }
                    lblFIles.Text = activeProject.Title;
                    project = activeProject;
                    btnUpload.Visible = true;
                    btnRefreshFiles.Visible = true;
                    btnMulti.Visible = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Fejl: " + ex.Message);
                }

                //try
                //{
                //    List<File> files = fileClient.GetAllFilesForProject(activeProject.Id).ToList();
                //    foreach (File f in files)
                //    {
                //        string[] row = { f.Id.ToString(), f.Title, f.Description };
                //        var lwi = new ListViewItem(row);
                //        lwFiles.Items.Add(lwi);
                //    }
                //}
                //catch (Exception exception)
                //{
                //    MessageBox.Show("Fejl: " + exception);
                //}

            }
            else
            {
                MessageBox.Show("Select a project");
            }
        }
 /// <summary>
 /// Removes the individual person in the given Project.
 /// There's no check whether the user or project exists or not.
 /// So checks should be made prior to executing this method.
 /// </summary>
 /// <param name="project">The project to remove the user from</param>
 /// <param name="user">THe user to be removed from the given project</param>
 /// <returns></returns>
 private bool RemovePersonFromProject(Project project, User user)
 {
     var t = from d in dbContext.ProjectUsers
             where project.Equals(d.Project) && user.Equals(d.User)
             select d;
     dbContext.ProjectUsers.DeleteOnSubmit(t.ToList().FirstOrDefault());
     try
     {
         dbContext.SubmitChanges();
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine("Something went wrong, when deleting the user id: " + user.Id + ", from the project id: " + project.Id + " Error Message: \n" + e);
         return false;
     }
 }
 private void listView_Projects_ItemActivate(object sender, EventArgs e)
 {
     string projectnumber = listView_Projects.SelectedItems[0].Text;
     activeProject = projectService.GetProject(Convert.ToInt32(projectnumber));
     UpdateProjects(false);
 }
        private void button_Save_Click(object sender, EventArgs e)
        {
            bool accepted;
            if (activeProject != null)
            {
                if (listView_Projects.SelectedItems.Count == 1)
                {
                    DialogResult dialogResult = MessageBox.Show("Er du sikker på at du vil gemme disse ændringer?", "Gem ændringer for projekt", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        if (textBox_Title.Text.Equals(""))
                        {
                            MessageBox.Show("Titel kan ikke være tom!");
                            accepted = false;
                        }
                        else if (textBox_Description.Text.Equals(""))
                        {
                            MessageBox.Show("Beskrivelse kan ikke være tom");
                            accepted = false;
                        }
                        else
                        {
                            accepted = true;
                        }

                        if (accepted)
                        {
                            int projectId = Convert.ToInt32(textBox_ProjektId.Text);
                            //TODO Uncomment when ready after project users have been modified
                            //Project project = new Project(projectId, textBox_Title.Text, textBox_Description.Text);
                            Project project = new Project
                            {
                                Description = textBox_Description.Text,
                                Title = textBox_Title.Text
                            };
                            bool success = projectService.UpdateProject(projectId, textBox_Title.Text, textBox_Description.Text, textbox_Directory.Text);
                            if (success)
                                MessageBox.Show("Success");
                            else
                                MessageBox.Show("Fail");
                        }
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        MessageBox.Show("Du valgte nej");
                    }
                }
            }
            else if (activeProject == null)
            {
                string title = textBox_Title.Text;
                string desc = textBox_Description.Text;
                string directory = textbox_Directory.Text;

                ProjectReturnType returnType = projectService.AddProject(title, desc, directory, projectAdmin);

                if (returnType == ProjectReturnType.Success)
                    MessageBox.Show("Projekt oprettet!");
                else if (returnType == ProjectReturnType.TitleMissing)
                    MessageBox.Show("Titel mangler!");
                else if (returnType == ProjectReturnType.DescriptionMissing)
                    MessageBox.Show("Beskrivelse mangler!");
                else if (returnType == ProjectReturnType.ProjectAdministratorUserMissing)
                    MessageBox.Show("Projekt Administrator mangler!");
            }
        }