public void DeleteTask(Task task)
        {
            if (task == null)
                throw new Exception("Category not specified");

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

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

            var projects = rep.GetProjects();

            foreach (var pro in projects)
            {
                foreach (var cat in rep.GetProjectCategories(pro))
                {
                    foreach (var te in rep.GetCategoryTasks(cat))
                        rep.DeleteTask(te);
                }
            }

            Assert.IsTrue(projects.Count == 1, "Ekki er hægt að keyra próf á task nema það sé eitt og aðeins eitt project");

            var project = projects.Single();

            var categories = rep.GetProjectCategories(project);

            Assert.IsTrue(categories.Count == 1, "Ekki er hægt að keyra próf á task nema það sé eitt og aðeins eitt project og undir því eins eitt category");

            var category = categories.Single();

            var task = new Task() { Description = "TestDescription" };
            task.IdCategory = category.Id;
            task.Category = category;
            task.Started = DateTime.Now;

            rep.SaveTask(task);

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

            projects = rep.GetProjects();
            categories = rep.GetProjectCategories(project);
            Assert.IsTrue(projects.Count == 1, "Vistuð project voru ekki 1");
            Assert.IsTrue(categories.Count == 1, "Vistuð category voru ekki 1");

            var tasks = rep.GetCategoryTasks(categories.Single());

            Assert.IsTrue(tasks.Count == 1, "Vistuð tösk voru ekki 1");

            Assert.AreEqual(tasks.Single().Description, task.Description, "Vistað task description stemmdi ekki");

            var task2 = new Task() { Description = "TestDescription", Started = DateTime.Now };
            task2.Category = new Category() {Name = "TestCategory2", IdProject = project.Id, Project = project};

            rep.SaveTask(task2);

            projects = rep.GetProjects();
            categories = rep.GetProjectCategories(project);

            Assert.IsTrue(projects.Count == 1, "Vistuð project voru ekki 1");
            Assert.IsTrue(categories.Count == 2, "Vistuð category voru ekki 2");
        }
        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");
        }
        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;
        }
        public void SaveTask(Task task)
        {
            if (task.IdCategory == 0)
            {
                SaveCategory(task.Category);
                task.IdCategory = task.Category.Id;
            }

            using (var gögn = GetDataContext())
            {
                if (task.Id == 0)
                {
                    gögn.Tasks.Attach(task);
                    gögn.ObjectStateManager.ChangeObjectState(task, EntityState.Added);
                }
                else
                {
                    gögn.Tasks.Attach(task);
                    gögn.ObjectStateManager.ChangeObjectState(task, EntityState.Modified);
                }

                gögn.SaveChanges();
            }
        }
Esempio n. 6
0
        public TaskViewModel(Task task)
        {
            Task = task;

            _repository = DependencyResolver.Resolve<ITimeManagerRepository>();
        }