Exemple #1
0
        public void ConvertFromDBObject(IDBObject obj)
        {
            if (!(obj is DB_Category))
            {
                return;
            }

            DB_Category dbCat = obj as DB_Category;

            this.ID = Guid.Parse(dbCat.ID);
            this.IsMasterCategory = dbCat.IsMasterCategory;
            this.Name             = dbCat.Name;

            DataHelper.AddItem(this);

            if (!string.IsNullOrEmpty(dbCat.ParentCategory))
            {
                DB_Category parentDBCat = new DB_Category();
                parentDBCat.Load(dbCat.ParentCategory);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == parentDBCat.ID);
                if (saveable != null)
                {
                    Category parentCat = DataHelper.LoadedObjects.Where(lo => lo is Category).Cast <Category>().FirstOrDefault(lo => lo.ID.ToString() == parentDBCat.ID);
                    this.ParentCategory = parentCat;
                }
                else
                {
                    Category parentCat = new Category();
                    parentCat.ConvertFromDBObject(parentDBCat);
                    this.ParentCategory = parentCat;
                }
            }
        }
Exemple #2
0
        public void deleteCategory(int CategoryId)
        {
            DB_Category category = uow.Categories.FindById(CategoryId);

            if (category != null)
            {
                uow.Categories.Remove(category);
            }
            uow.Save();
        }
Exemple #3
0
        public void SaveCategory(string name)
        {
            DB_Category categ = new DB_Category
            {
                Name = name
            };

            uow.Categories.Create(categ);
            uow.Save();
        }
Exemple #4
0
        public IDBObject ConvertToDBObject()
        {
            DB_Category dbCat = new DB_Category();

            dbCat.ID = this.ID.ToString();
            dbCat.IsMasterCategory = this.IsMasterCategory;
            dbCat.Name             = this.Name;
            dbCat.ParentCategory   = this.ParentCategory == null ? string.Empty : this.ParentCategory.ID.ToString();

            return(dbCat);
        }
Exemple #5
0
        public void TestCheckTitle()
        {
            Data();
            List <DB_Category> categories = new List <DB_Category>();
            DB_Category        catg1      = new DB_Category();
            DB_Category        catg2      = new DB_Category();

            categories.Add(catg1);
            categories.Add(catg2);

            mockConteiner.Setup(a => a.Categories).Returns(mockCategories.Object);
            mockCategories.Setup(a => a.Get()).Returns(categories);

            NUnit.Framework.Assert.AreEqual(true, CatgO.CheckTitle(null));
        }
        public void RemoveCategory(int id)
        {
            DB_Category category = db.Categories.GetItem(id);

            if (category == null)
            {
                throw new ArgumentNullException();
            }

            db.Categories.Delete(id);
            foreach (DB_Product p in category.Products)
            {
                p.Category = null;
            }
            db.Save();
        }
Exemple #7
0
        public void TestGetCategory()
        {
            Data();
            List <DB_Category> categories = new List <DB_Category>();
            DB_Category        catg1      = new DB_Category();

            categories.Add(catg1);

            mockConteiner.Setup(a => a.Categories).Returns(mockCategories.Object);
            mockCategories.Setup(a => a.Get()).Returns(categories);
            Category result = new Category();

            result = Mapper.Map <DB_Category, Category>(catg1);

            NUnit.Framework.Assert.AreEqual(result.CategoryID, CatgO.GetCategory(0).CategoryID);
        }
Exemple #8
0
        public void TestGetCategories()
        {
            ResetData();
            List <DB_Category> categories = new List <DB_Category>();
            DB_Category        catg1      = new DB_Category();
            DB_Category        catg2      = new DB_Category();

            categories.Add(catg1);
            categories.Add(catg2);

            mockCategories.Setup(a => a.Get()).Returns(categories);
            List <Category> expected = new List <Category>();

            expected = Mapper.Map <List <DB_Category>, List <Category> >(categories);

            var result = CatgO.GetCategories();

            Assert.AreEqual(expected.Capacity, result.Capacity);
        }
Exemple #9
0
        public void TestGetCategories()
        {
            Mapper_Config.Initialize();
            Data();
            List <DB_Category> categories = new List <DB_Category>();
            DB_Category        catg1      = new DB_Category();
            DB_Category        catg2      = new DB_Category();

            categories.Add(catg1);
            categories.Add(catg2);

            mockConteiner.Setup(a => a.Categories).Returns(mockCategories.Object);
            mockCategories.Setup(a => a.Get()).Returns(categories);
            List <Category> result = new List <Category>();

            result = Mapper.Map <List <DB_Category>, List <Category> >(categories);

            NUnit.Framework.Assert.AreEqual(result.Capacity, CatgO.GetAllCategories().Capacity);
        }
Exemple #10
0
        public List <CategoryTools> GetAllCategories()
        {
            DB_Category          dbCateory = new DB_Category();
            List <CategoryTools> lstCat    = null;
            var allcategories = dbCateory.GetallCategory();

            if (allcategories != null)
            {
                lstCat = new List <CategoryTools>();
                foreach (var cat in allcategories)
                {
                    lstCat.Add(new CategoryTools {
                        id = cat.id, name = cat.name_category
                    });
                }
            }

            return(lstCat);
        }
Exemple #11
0
        public void SaveSubcategory(string SubcategoryName, string CategoryName)
        {
            DB_Category categ = null;
            IEnumerable <DB_Category> categories = uow.Categories.Get();

            foreach (DB_Category c in categories)
            {
                if (c.Name == CategoryName)
                {
                    categ = c;
                }
            }

            DB_Subcategory subcateg = new DB_Subcategory {
                Name = SubcategoryName, Category = categ
            };

            uow.Subcategories.Create(subcateg);
            uow.Save();
        }
Exemple #12
0
        public void ConvertFromDBObject(IDBObject obj)
        {
            if (!(obj is DB_Entry))
            {
                return;
            }

            DB_Entry ent = obj as DB_Entry;

            this.Date    = DateTime.Parse(ent.Date);
            this.ID      = Guid.Parse(ent.ID);
            this.Inflow  = ent.Inflow;
            this.Outflow = ent.Outflow;

            DataHelper.AddItem(this);

            if (!string.IsNullOrEmpty(ent.Account))
            {
                DB_Account dbAcc = new DB_Account();
                dbAcc.Load(ent.Account);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == dbAcc.ID);
                if (saveable != null)
                {
                    Account acc = DataHelper.LoadedObjects.Where(lo => lo is Account).Cast <Account>().FirstOrDefault(lo => lo.ID.ToString() == dbAcc.ID);
                    this.Account = acc;
                }
                else
                {
                    Account acc = new Account();
                    acc.ConvertFromDBObject(dbAcc);
                    this.Account = acc;
                }
            }

            if (!string.IsNullOrEmpty(ent.Category))
            {
                DB_Category dbCat = new DB_Category();
                dbCat.Load(ent.Category);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == dbCat.ID);
                if (saveable != null)
                {
                    Category cat = DataHelper.LoadedObjects.Where(lo => lo is Category).Cast <Category>().FirstOrDefault(lo => lo.ID.ToString() == dbCat.ID);
                    this.Category = cat;
                }
                else
                {
                    Category cat = new Category();
                    cat.ConvertFromDBObject(dbCat);
                    this.Category = cat;
                }
            }

            if (!string.IsNullOrEmpty(ent.Payee))
            {
                DB_Payee dbPay = new DB_Payee();
                dbPay.Load(ent.Payee);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == dbPay.ID);
                if (saveable != null)
                {
                    Payee pay = DataHelper.LoadedObjects.Where(lo => lo is Payee).Cast <Payee>().FirstOrDefault(lo => lo.ID.ToString() == dbPay.ID);
                    this.Payee = pay;
                }
                else
                {
                    Payee pay = new Payee();
                    pay.ConvertFromDBObject(dbPay);
                    this.Payee = pay;
                }
            }
        }
Exemple #13
0
        public static List <IDBObject> Convert <T>(DataSet ds)
        {
            List <IDBObject> objects = new List <IDBObject>();

            if (typeof(T).FullName == typeof(DB_Account).FullName)
            {
                foreach (DataRow row in ds.Tables["Account"].Rows)
                {
                    DB_Account acc = new DB_Account();
                    acc.ID          = row["ID"].ToString();
                    acc.IsActive    = bool.Parse(row["IsActive"].ToString());
                    acc.IsOffBudget = bool.Parse(row["IsOffBudget"].ToString());
                    acc.Name        = row["Name"].ToString();
                    acc.Note        = row["Note"].ToString();
                    acc.Type        = row["Type"].ToString();

                    objects.Add(acc);
                }
            }
            else if (typeof(T).FullName == typeof(DB_Entry).FullName)
            {
                foreach (DataRow row in ds.Tables["Entry"].Rows)
                {
                    DB_Entry ent = new DB_Entry();
                    ent.Account  = row["Account"].ToString();
                    ent.Category = row["Category"].ToString();
                    ent.Date     = row["Date"].ToString();
                    ent.ID       = row["ID"].ToString();
                    ent.Inflow   = decimal.Parse(row["Inflow"].ToString());
                    ent.Outflow  = decimal.Parse(row["Outflow"].ToString());
                    ent.Payee    = row["Payee"].ToString();

                    objects.Add(ent);
                }
            }
            else if (typeof(T).FullName == typeof(DB_Category).FullName)
            {
                foreach (DataRow row in ds.Tables["Category"].Rows)
                {
                    DB_Category cat = new DB_Category();
                    cat.ID = row["ID"].ToString();
                    cat.IsMasterCategory = bool.Parse(row["IsMasterCategory"].ToString());
                    cat.Name             = row["Name"].ToString();
                    cat.ParentCategory   = row["ParentCategory"].ToString();

                    objects.Add(cat);
                }
            }
            else if (typeof(T).FullName == typeof(DB_Payee).FullName)
            {
                foreach (DataRow row in ds.Tables["Payee"].Rows)
                {
                    DB_Payee pay = new DB_Payee();
                    pay.ID       = row["ID"].ToString();
                    pay.IsActive = bool.Parse(row["IsActive"].ToString());
                    pay.Name     = row["Name"].ToString();

                    objects.Add(pay);
                }
            }

            return(objects);
        }