Esempio n. 1
0
        private void EditProject_Click(object sender, RoutedEventArgs e)
        {
            string   name        = this.name.Text;
            string   description = this.description.Text;
            DateTime deadline    = this.deadline.SelectedDate.ToString() == "" ? DateTime.MinValue : this.deadline.SelectedDate.Value;

            try
            {
                if (InputsReq())
                {
                    project.Name        = name;
                    project.Description = description;
                    project.DueDate     = deadline;

                    if (projectDAO.Update(project))
                    {
                        foreach (User projectUser in projectUsers)
                        {
                            if (userList.Contains(projectUser.Id))
                            {
                                userList.Remove(projectUser.Id);
                            }
                        }

                        foreach (int userID in userList)
                        {
                            projectDAO.AddUserToProject(project.Id, userID);
                        }

                        if (inviteUserToProject != null)
                        {
                            inviteUserToProject.Close();
                        }

                        string content = "";

                        content += name[0];

                        if (name.Length > 1)
                        {
                            content += name[1];
                        }

                        foreach (UIElement element in projectList.Children)
                        {
                            if (element.Uid.Equals(project.Id.ToString()))
                            {
                                ((Button)element).Content = content.ToUpper();
                                break;
                            }
                        }

                        utilities.GetNotifier().ShowSuccess("Projektet blev opdateret!");
                        mainController.Dashboard.UpdatePage();
                        Close();
                    }
                }
                else
                {
                    utilities.GetNotifier().ShowError("Udfyld venligst alle felter!");
                }
            }
            catch (Exception exception)
            {
                utilities.GetNotifier().ShowError(utilities.HandleException(exception));
            }
        }
        private void CreateProject_Click(object sender, RoutedEventArgs e)
        {
            string   name        = this.name.Text;
            string   description = this.description.Text;
            DateTime deadline    = this.deadline.SelectedDate.ToString() == "" ? DateTime.MinValue : this.deadline.SelectedDate.Value;

            try {
                if (InputsReq())
                {
                    if (!name.Equals(""))
                    {
                        Project project = new Project();
                        project.Name           = name;
                        project.Description    = description;
                        project.DueDate        = deadline;
                        project.ProjectOwnerID = user.Id;

                        ProjectDAO projectDAO = new ProjectDAO();

                        int projectID = projectDAO.CreateProject(project);

                        foreach (int userID in userList)
                        {
                            projectDAO.AddUserToProject(projectID, userID);
                        }
                        this.Close();

                        if (inviteUserToProject != null)
                        {
                            inviteUserToProject.Close();
                        }

                        utilities.GetNotifier().ShowSuccess("Projektet blev oprettet!");
                        home.NewProjectElement(projectID, name);

                        if (mainController.Project == null)
                        {
                            mainController.Project = projectDAO.Read(projectID);
                            mainController.ChangeProject();
                        }
                    }
                }
                else
                {
                    if (!NameFieldReq(name))
                    {
                        utilities.GetNotifier().ShowError("Indtast venligst et projektnavn");
                    }
                    else if (!DescripFieldReq(description))
                    {
                        utilities.GetNotifier().ShowError("Indtast venligst en beskrivelse");
                    }
                    else if (!DateFieldReq(deadline))
                    {
                        utilities.GetNotifier().ShowError("Vælg en gyldig deadline");
                    }
                }
            }
            catch (Exception exception)
            {
                utilities.GetNotifier().ShowError(utilities.HandleException(exception));
            }
        }