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

            var projects = rep.GetProjects();
            foreach (var pro in projects)
            {
                foreach(var cat in rep.GetProjectCategories(pro))
                    rep.DeleteCategory(cat);
            }

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

            var project = projects.Single();

            var category = new Category(){Name = "TestCategory"};
            category.IdProject = project.Id;
            category.Project = project;

            rep.SaveCategory(category);

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

            var categories = rep.GetProjectCategories(project);

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

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

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

                gögn.SaveChanges();
            }
        }
        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;
        }
示例#4
0
 public bool Equals(Category other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id && other.IdProject == IdProject;
 }
 public List<Task> GetCategoryTasks(Category category)
 {
     using (var gögn = GetDataContext())
     {
         return gögn.Tasks.Where(x => x.IdCategory == category.Id).ToList();
     }
 }
        public void SaveCategory(Category category)
        {
            if (category == null)
                throw new Exception("New category not specified");

            if (category.IdProject == 0)
            {
                SaveProject(category.Project);
                category.IdProject = category.Project.Id;
            }

            using (var gögn = GetDataContext())
            {
                gögn.Categories.Attach(category);
                gögn.ObjectStateManager.ChangeObjectState(category, EntityState.Added);

                gögn.SaveChanges();
            }
        }
 public CategoryViewModel(Category category)
 {
     Category = category;
 }