示例#1
0
        public void UpdateSubCategoryOfMainCategoryDescriptionSuccess()
        {
            var config     = new HttpConfiguration();
            var request    = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/user/44300");
            var route      = config.Routes.MapHttpRoute("Default", "api/{controller}/UpdateDescription/");
            var controller = new CategoryController
            {
                Request = request,
            };

            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            MainCategoryService.AddMainCategory("unit test", "unit test");
            SubCategoryService.AddSubCategory("unit test", "unit_test");
            SwapDbConnection db        = new SwapDbConnection();
            main_category    test_main = db.main_category.Where(x => x.name == "unit test").FirstOrDefault();
            sub_category     test_sub  = db.sub_category.Where(x => x.name == "unit test").FirstOrDefault();

            CategoryService.AddMainAndSubRelationship(test_main.main_id, test_sub.sub_id, "unit test", "unit test");
            Assert.AreEqual(controller.UpdateSubCategoryOfMainCategoryDescription(new MainAndSubRelationshipDTO()
            {
                main_id = test_main.main_id, sub_id = test_sub.sub_id, descrition = "test"
            }).StatusCode, HttpStatusCode.OK);
            delete_main_category.DeleteMainCategorySuccess();
            delete_sub_category.DeleteSubCategorySuccess();
        }
        protected void AddSubCatagory(object parameter)
        {
            string  sub_category_name;
            TextBox tb = (TextBox)parameter;

            sub_category_name = tb.Text;
            if ((sub_category_name != "") && (SelectedCategory != null))
            {
                List <sub_category> temp_list = SubCategoryServices.GetAllSubCategoryByName(sub_category_name.Trim(), SelectedCategory.id);
                if (temp_list.Count == 0)
                {
                    sub_category ct = new sub_category();
                    ct.id = 0;
                    ct.subcategory_name = sub_category_name;
                    ct.category         = SelectedCategory.id;
                    int temp_SubCategory_id = SubCategoryServices.AddUpdateSubCategory(ct);
                    if (temp_SubCategory_id != 0)
                    {
                        // MessageBox.Show("Category " + sub_category_name + " is Created");
                        InventoryHelper.SuccessAlert("Success", "Category " + sub_category_name + " is Created");
                        BindGrid();
                    }
                }
            }
        }
示例#3
0
 public static Sub_categoryDTO Sub_categoryToDTO(sub_category s)
 {
     return(new Sub_categoryDTO()
     {
         category_id = s.category_id,
         sub_category_id = s.sub_category_id,
         sub_category_name = s.sub_category_name
     });
 }
        public void ChangeActiveSubCategorySuccess()
        {
            var config     = new HttpConfiguration();
            var request    = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/user/44300");
            var route      = config.Routes.MapHttpRoute("Default", "api/{controller}/SubCategory/{id}");
            var controller = new SubCategoryController
            {
                Request = request,
            };

            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            SwapDbConnection db   = new SwapDbConnection();
            sub_category     test = db.sub_category.Where(x => x.name == "unit test").FirstOrDefault();

            Assert.AreEqual(controller.ChangeActiveSubCategory(test.sub_id, true).StatusCode, HttpStatusCode.OK);
        }
示例#5
0
        //Update subcategory
        //Input: sub_id, google_value, name
        //Output: boolean if succeed or not
        public static bool updateSubCategory(string id, string google_value, string name)
        {
            SwapDbConnection db          = new SwapDbConnection();
            sub_category     subCategory = db.sub_category.FirstOrDefault(c => c.sub_id == id);
            int duplicates = db.sub_category.Where(c => c.sub_id != id && (c.name == name || (!string.IsNullOrEmpty(c.google_value) && c.google_value == google_value))).ToList().Count();

            if (subCategory == null || duplicates != 0)
            {
                return(false);
            }
            subCategory.name         = name;
            subCategory.google_value = google_value;
            db.SaveChanges();

            return(true);
        }
示例#6
0
        //add relationship between main and sub
        public static MainAndSubRelationshipDTO AddMainAndSubRelationship(string main_id, string sub_name, string google_value, string descrition = null)
        {
            SwapDbConnection db           = new SwapDbConnection();
            sub_category     subCategory  = db.sub_category.FirstOrDefault(c => c.name == sub_name && c.google_value == google_value);
            main_category    mainCategory = db.main_category.FirstOrDefault(c => c.main_id == main_id);

            if (mainCategory == null)
            {
                throw new InvalidOperationException("there is a no main id as requested");
            }

            r_sub_and_main_category categoryOfMainCategory = db.r_sub_and_main_category.FirstOrDefault(c => c.main_id == main_id && c.sub_category.name == sub_name);

            if (categoryOfMainCategory != null)
            {
                throw new InvalidOperationException("there is an reletinship as this");
            }

            if (subCategory == null)
            {
                subCategory = SubCategoryService.AddSubCategory(sub_name, google_value);
            }

            r_sub_and_main_category r_main_sub_object = new r_sub_and_main_category()
            {
                sub_id        = subCategory.sub_id,
                main_id       = main_id,
                creation_date = DateTime.Now,
                is_active     = false,
                clicked       = 0,
                descrition    = descrition
            };

            db.r_sub_and_main_category.Add(r_main_sub_object);
            db.SaveChanges();
            return(new MainAndSubRelationshipDTO()
            {
                main_id = main_id,
                sub_id = subCategory.sub_id,
                descrition = descrition,
                is_active = false,
                clicked = 0,
                main_name = r_main_sub_object.main_category.name,
                sub_name = sub_name,
                google_value = subCategory.google_value
            });
        }
示例#7
0
        public void GetMainAndSubRelationshipTest()
        {
            var config     = new HttpConfiguration();
            var request    = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/user/44300");
            var route      = config.Routes.MapHttpRoute("Default", "api/{controller}/GetMainAndSubRelationship/{main_id}/{sub_id}");
            var controller = new CategoryController
            {
                Request = request,
            };

            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            SwapDbConnection db        = new SwapDbConnection();
            main_category    test_main = db.main_category.Where(x => x.name == "unit test").FirstOrDefault();
            sub_category     test_sub  = db.sub_category.Where(x => x.name == "unit test").FirstOrDefault();

            Assert.AreEqual(controller.GetMainAndSubRelationship(test_main.main_id).StatusCode, HttpStatusCode.OK);
        }
 public static Sub_categoryDTO AddSubCategory(Sub_categoryDTO subCategory)
 {
     using (Entities e = new Entities())
     {
         category category = e.categories.FirstOrDefault(c => c.category_id == subCategory.category_id);
         if (category == null)
         {
             throw new Exception("category id is not exists");
         }
         sub_category sc = e.sub_category.Where(s => s.category_id == category.category_id && s.category.teacher_id == category.teacher_id && s.sub_category_name == subCategory.sub_category_name).FirstOrDefault();
         if (sc != null)
         {
             throw new Exception("sub category name is exists");
         }
         var added = e.sub_category.Add(Sub_categoryCasting.Sub_categoryToDAL(subCategory));
         e.SaveChanges();
         return(Sub_categoryCasting.Sub_categoryToDTO(added));
     }
 }
        protected void UpdateSubCatagory(object parameter)
        {
            int     Sub_category_id = 0;
            TextBox tb = (TextBox)parameter;

            int.TryParse(tb.Text, out Sub_category_id);
            if ((Sub_category_id > 0) && (SelectedCategory != null))
            {
                SubCategoryEntity   ob_sub_Category = _lstSubCategory.Where(s => s.id == Sub_category_id).FirstOrDefault();
                List <sub_category> temp_list       = SubCategoryServices.GetAllSubCategoryByName(ob_sub_Category.sub_category_name.Trim(), SelectedCategory.id);
                if (temp_list.Count == 0 || temp_list.Count == 1)
                {
                    if (temp_list.Count == 1)
                    {
                        sub_category temp = temp_list.FirstOrDefault();
                        if (temp.id != ob_sub_Category.id)
                        {
                            BindGrid();
                            //RaisedPropertyChanged("Category");
                            //MessageBox.Show("SubCategory Name alredy Exist.");
                            InventoryHelper.SimpleAlert("Warning", "SubCategory Name alredy Exist.");
                            return;
                        }
                    }
                    sub_category temp_ob_sub_Category = SubCategoryServices.GetSubCategory(ob_sub_Category.id);
                    temp_ob_sub_Category.subcategory_name = ob_sub_Category.sub_category_name;
                    int temp_sub_Category_id = SubCategoryServices.AddUpdateSubCategory(temp_ob_sub_Category);
                    if (temp_sub_Category_id == ob_sub_Category.id)
                    {
                        //MessageBox.Show("Sub-Category " + ob_sub_Category.sub_category_name + " is Updated");
                        InventoryHelper.SuccessAlert("Success", "Sub-Category " + ob_sub_Category.sub_category_name + " is Updated");
                        BindGrid();
                        //RaisedPropertyChanged("Category");
                    }
                }
                else
                {
                    // MessageBox.Show("Category Name already Exist");
                    InventoryHelper.SimpleAlert("Warning", "Category Name already Exist");
                }
            }
        }
示例#10
0
        //add sub category
        public static sub_category AddSubCategory(string value, string google_value)
        {
            SwapDbConnection db = new SwapDbConnection();

            if (db.sub_category.FirstOrDefault(c => c.name == value && c.google_value == google_value) != null)
            {
                return(null);
            }

            sub_category sub_object = new sub_category()
            {
                sub_id        = IdService.generateID("sub_id"),
                creation_date = DateTime.Now,
                is_active     = false,
                name          = value,
                google_value  = google_value,
            };

            db.sub_category.Add(sub_object);
            db.SaveChanges();
            return(sub_object);
        }
示例#11
0
 public static int AddUpdateSubCategory(sub_category ob)
 {
     return(SubCategoryProvider.AddUpdateSubCategory(ob));
 }