public void TestSaveProject()
        {
            var rep = new TimeManagerRepository();

            //Delete all data
            foreach (var pro in rep.GetProjects())
            {
                foreach (var cat in rep.GetProjectCategories(pro))
                {
                    foreach (var te in rep.GetCategoryTasks(cat))
                        rep.DeleteTask(te);

                    rep.DeleteCategory(cat);
                }
                rep.DeleteProject(pro);
            }

            var project = new Project() {Name = "TestProject"};
            rep.SaveProject(project);

            Assert.IsTrue(project.Id != 0, "ProjectId var 0");

            var projects = rep.GetProjects();

            Assert.IsTrue(projects.Count == 1, "Vistuð project voru ekki 1");
            Assert.AreEqual(projects.Single().Name, project.Name, "Vistað nafn stemmdi ekki");
        }
        public void DeleteProject(Project project)
        {
            if (project == null)
                throw new Exception("Project not specified");

            using (var gögn = GetDataContext())
            {
                gögn.Projects.Attach(project);
                gögn.ObjectStateManager.ChangeObjectState(project, EntityState.Deleted);

                gögn.SaveChanges();
            }
        }
        public void TestSaveTaskNew()
        {
            var rep = new TimeManagerRepository();

            var projects = rep.GetProjects();

            //Delete all data
            foreach (var pro in projects)
            {
                foreach (var cat in rep.GetProjectCategories(pro))
                {
                    foreach (var te in rep.GetCategoryTasks(cat))
                        rep.DeleteTask(te);

                    rep.DeleteCategory(cat);
                }
                rep.DeleteProject(pro);
            }

            var projectNew = new Project() {Name = "test project new"};

            var task = new Task();
            task.Description = "test task description new";
            task.Started = DateTime.Now;
            task.Category = new Category() { Name = "test category new", Project = projectNew };

            rep.SaveTask(task);

            projects = rep.GetProjects();
            Assert.IsTrue(projects.Count == 1, "Project voru fleiri en 1");

            var categories = rep.GetProjectCategories(projects.Single());
            Assert.IsTrue(categories.Count == 1, "Categories voru fleiri en 1");

            var tasks = rep.GetCategoryTasks(categories.Single());
            Assert.IsTrue(tasks.Count == 1, "Tasks voru fleiri en 1");

            var task2 = new Task();
            task2.Description = "test task description new 2";
            task2.Started = DateTime.Now;
            task2.Category = new Category() { Name = "test category new 2", Project = projectNew, IdProject = projectNew.Id };

            rep.SaveTask(task2);

            projects = rep.GetProjects();
            Assert.IsTrue(projects.Count == 1, "Project voru fleiri en 1");

            categories = rep.GetProjectCategories(projects.Single());
            Assert.IsTrue(categories.Count == 2, "Categories voru ekki 2");

            var tasks2 = rep.GetCategoryTasks(task2.Category);
            Assert.IsTrue(tasks2.Count == 1, "Tasks voru fleiri en 1");
        }
Ejemplo n.º 4
0
 public ProjectViewModel(Project project)
 {
     Project = project;
 }
        private void Save()
        {
            var task = new Task();

            if (Project == null)
            {
                if (string.IsNullOrEmpty(ProjectName))
                    throw new DataIntegrityException("Please fill in project name");

                Project = new Project() {Name = ProjectName};
            }
            if (Category == null)
            {
                if (string.IsNullOrEmpty(CategoryName))
                    throw new DataIntegrityException("Please fill in category name");

                Category = new Category() {Name = CategoryName};
            }

            Category.Project = Project;
            Category.IdProject = Project.Id;

            task.Category = Category;
            task.IdCategory = Category.Id;
            task.Description = Description ?? string.Empty;
            task.Started = DateTime.Today.Add(Started);

            if (Completed.HasValue)
                task.Completed = DateTime.Today.Add(Completed.Value);

            task.WorkedHours = WorkedHours;

            var repository = DependencyResolver.Resolve<ITimeManagerRepository>();
            repository.SaveTask(task);

            NewTask = task;
        }
Ejemplo n.º 6
0
 public bool Equals(Project other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id;
 }
 public List<Category> GetProjectCategories(Project project)
 {
     using (var gögn = GetDataContext())
     {
         return gögn.Categories.Where(x => x.IdProject == project.Id).ToList();
     }
 }