Esempio n. 1
0
        internal void saveCategory(ParentCategory category)
        {
            using (SqlConnection sqlConnection = new SqlConnection(BPM_DB_Connectionstring))
            {
                using (SqlCommand command = new SqlCommand("sp_SaveParentCategory", sqlConnection))
                {
                    try
                    {
                        sqlConnection.Open();
                        command.CommandType = CommandType.StoredProcedure;
                        if (category.Id == null)
                        {
                            command.Parameters.AddWithValue("@Id", DBNull.Value);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@Id", category.Id);
                        }

                        command.Parameters.AddWithValue("@Name", category.Name);
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        private void BindData()
        {
            Category category = CategoryManager.GetCategoryByID(this.CategoryID);

            if (category != null)
            {
                this.txtName.Text              = category.Name;
                this.txtDescription.Value      = category.Description;
                this.txtSmallDescription.Value = category.SmallDescription;
                CommonHelper.SelectListItem(this.ddlTemplate, category.TemplateID);
                ParentCategory.SelectedCategoryId = category.ParentCategoryID;

                Picture categoryPicture = category.Picture;
                this.btnRemoveCategoryImage.Visible = categoryPicture != null;
                string pictureUrl = PictureManager.GetPictureUrl(categoryPicture, 100);
                this.iCategoryPicture.Visible  = true;
                this.iCategoryPicture.ImageUrl = pictureUrl;

                this.txtPriceRanges.Text   = category.PriceRanges;
                this.cbPublished.Checked   = category.Published;
                this.txtDisplayOrder.Value = category.DisplayOrder;
                this.ParentCategory.BindData();
            }
            else
            {
                this.btnRemoveCategoryImage.Visible = false;
                this.iCategoryPicture.Visible       = false;

                ParentCategory.SelectedCategoryId = this.ParentCategoryID;
                ParentCategory.BindData();
            }
        }
Esempio n. 3
0
        public static ParentCategory saveProduct(ParentCategory newCategory)
        {
            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand("sp_SaveParentCategory", sqlConnection))
                {
                    try
                    {
                        sqlConnection.Open();
                        command.CommandType = CommandType.StoredProcedure;
                        if (newCategory.Id == null)
                        {
                            command.Parameters.AddWithValue("@Id", DBNull.Value);
                        }
                        else
                        {
                            command.Parameters.AddWithValue("@Id", newCategory.Id);
                        }
                        command.Parameters.AddWithValue("@ParentCategoryName", newCategory.Name);

                        command.ExecuteNonQuery();

                        return(newCategory);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        public void GetChildCategoryByIdShouldReturnChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetChildCategoryById_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };

            dbContext.ChildCategories.AddRange(new List <ChildCategory>
            {
                new ChildCategory {
                    Id = 1, Name = "Cables", ParentCategory = parentCategory
                },
                new ChildCategory {
                    Id = 2, Name = "Monitors", ParentCategory = parentCategory
                }
            });
            dbContext.SaveChanges();

            var childCategoriesService = new ChildCategoriesService(dbContext);
            var childCategory          = childCategoriesService.GetChildCategoryById(1);

            Assert.Equal("Cables", childCategory.Name);
        }
        public void AddReviewShouldAddReview(int rating, int expected)
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"AddReviews_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };
            var childCategory = new ChildCategory {
                Name = "Cables", ParentCategory = parentCategory
            };

            dbContext.ChildCategories.Add(childCategory);
            dbContext.SaveChanges();

            var product = new Product {
                Name = "USB ", ChildCategory = childCategory
            };

            dbContext.Products.Add(product);
            dbContext.SaveChanges();

            productService.AddReview(rating, product.Id);

            Assert.Equal(expected, product.Reviews.Count());
        }
Esempio n. 6
0
        public ActionResult ParentCategoriesList2()
        {
            ParentCategory model = new ParentCategory();
            var            query = _pageRepository.GetParentCategoriesList2();

            return(PartialView("_ParentCategories"));
        }
Esempio n. 7
0
        public IActionResult AddCategory(AddCategoryModel model)
        {
            if (ModelState.IsValid)
            {
                ParentCategory parentCateogory = unitOfWork.ParentCategories.Get(model.ParentCategoryId);

                if (parentCateogory != null)
                {
                    Category category = new Category()
                    {
                        CategoryName      = model.CategoryName,
                        ParentCategory    = parentCateogory,
                        ProductCategories = new List <ProductCategory>()
                    };
                    unitOfWork.Categories.Add(category);
                    unitOfWork.SaveChanges();
                    var data = new string[] { category.CategoryId.ToString(), category.CategoryName, category.ParentCategory.ParentCategoryName };
                    //var data = JsonConvert.SerializeObject(category);
                    return(Ok(data));
                }
                else
                {
                    ModelState.AddModelError("", "ParentCategory was not found!");
                }
            }
            return(BadRequest());
        }
Esempio n. 8
0
        public void CanDeleteValidParentCategories()
        {
            // Arrange - create a parentCategory
            ParentCategory parentCategory = new ParentCategory {
                ParentCategoryId = 2, Name = "Test"
            };

            // Arrange - create a local mock repository
            var localMock = new Mock <IProductRepository>();

            localMock.Setup(m => m.ParentCategories).Returns(new ParentCategory[]
            {
                new ParentCategory {
                    ParentCategoryId = 1, Name = "PC1"
                },
                parentCategory,
                new ParentCategory {
                    ParentCategoryId = 3, Name = "PC3"
                }
            }.AsQueryable());

            // Arrange - create a controller
            var controller = new AdminController(localMock.Object);

            // Action - delete the parentCategory
            controller.DeleteParentCategory(parentCategory.ParentCategoryId);

            // assert - ensure that the repository delete method was called with the correct ParentCategory
            localMock.Verify(m => m.DeleteParentCategory(parentCategory));
        }
 public void UpdateCategory(ParentCategory category)
 {
     using (var context = new Context())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Esempio n. 10
0
 public AudioMixerGroup GetAudioMixerGroup()
 {
     if (AudioMixerGroup != null)
     {
         return(AudioMixerGroup);
     }
     return(ParentCategory != null?ParentCategory.GetAudioMixerGroup() : null);
 }
 public void SaveCategory(ParentCategory category)
 {
     using (var context = new Context())
     {
         context.ParentCategories.Add(category);
         context.SaveChanges();
     }
 }
Esempio n. 12
0
 public GameObject GetAudioObjectPrefab()
 {
     if (AudioObjectPrefab != null)
     {
         return(AudioObjectPrefab);
     }
     return(ParentCategory != null?ParentCategory.GetAudioObjectPrefab() : AudioController.AudioObjectPrefab);
 }
Esempio n. 13
0
        public ActionResult DeleteConfirmed(string id)
        {
            ParentCategory parentCategory = db.ParentCategories.Find(id);

            db.ParentCategories.Remove(parentCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        public void MoveTo(CategoryConfiguration category)
        {
            if (ParentCategory != null)
            {
                ParentCategory.Remove(this);
            }

            ParentCategory.Add(this);
        }
        public string GetCategoryIdPath()
        {
            if (ParentCategory != null)
            {
                return(ParentCategory.GetCategoryIdPath() + "/" + Category.Id);
            }

            return(Category.Id);
        }
Esempio n. 16
0
 public ActionResult Create(ParentCategory category)
 {
     if (ModelState.IsValid)
     {
         category.Save();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Esempio n. 17
0
        public ActionResult DeleteParentCategory(ParentCategory cp)
        {
            db.Products.RemoveRange(db.Products.Where(x => x.P_Cat_Id == cp.Id));
            db.ChildCategories.RemoveRange(db.ChildCategories.Where(x => x.P_Cat_Id == cp.Id));
            db.ParentCategories.Remove(db.ParentCategories.Find(cp.Id));

            db.SaveChanges();
            TempData["msg"] = "دسته اصلی با موفقیت حذف شد";
            return(RedirectToAction("ManagmentCategoryView", "Category", new { id = -1 }));
        }
Esempio n. 18
0
 public ActionResult Edit([Bind(Include = "ParentCatPath,NameParentCat,Position,Status")] ParentCategory parentCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(parentCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(parentCategory));
 }
Esempio n. 19
0
        public void AddMainCategory(string name, string imageUrl)
        {
            var category = new ParentCategory()
            {
                Name     = name,
                ImageUrl = imageUrl
            };

            this.db.ParentCategories.Add(category);
            this.db.SaveChanges();
        }
Esempio n. 20
0
        public ActionResult UpdateParentCategory(ParentCategory obj)
        {
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }
            _parent.Update(obj);

            Session["Message"] = "Data Updated Successfully..................!!!!!!!";
            return(RedirectToAction("ParentCategory", "ParentCategory"));
        }
        public void GetProductsFilterShouldFilterProducts(string test, int expected, string searchString, int?childCategoryId)
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"{test}_GetProductsFilter_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };
            var childCategories = new List <ChildCategory>
            {
                new ChildCategory {
                    Name = "Cables", ParentCategory = parentCategory
                },
                new ChildCategory {
                    Name = "Monitors", ParentCategory = parentCategory
                }
            };

            dbContext.ChildCategories.AddRange(childCategories);
            dbContext.SaveChanges();

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB Cable", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Adapter Cable", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Monitor LG", ChildCategory = childCategories.Last()
                },
            });
            dbContext.SaveChanges();

            if (childCategoryId.HasValue && childCategoryId.Value == 1)
            {
                childCategoryId = childCategories.First().Id;
            }

            var products = productService.GetProductsFilter(searchString, childCategoryId);

            Assert.Equal(expected, products.Count());
        }
Esempio n. 22
0
        public ActionResult Create([Bind(Include = "ParentCatPath,NameParentCat,Position,Status")] ParentCategory parentCategory)
        {
            if (ModelState.IsValid)
            {
                db.ParentCategories.Add(parentCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(parentCategory));
        }
Esempio n. 23
0
 public void ChangePositionValue([Bind(Include = "ParentCatPath,Position")] ParentCategory parentCategory)
 {
     if (parentCategory.Position > 0)
     {
         int tempPosition = parentCategory.Position;
         parentCategory                 = db.ParentCategories.Where(s => s.ParentCatPath == parentCategory.ParentCatPath).FirstOrDefault();
         parentCategory.Position        = tempPosition;
         db.Entry(parentCategory).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 24
0
 public ActionResult CreateCategory(ParentCategory newCategory)
 {
     try
     {
         newCategory.SaveCategory();
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("CreateCategory"));
     }
 }
Esempio n. 25
0
        public IActionResult AddParentCategory(ParentCategory entity)
        {
            if (ModelState.IsValid)
            {
                entity.Categories = new List <Category>();
                unitOfWork.ParentCategories.Add(entity);
                unitOfWork.SaveChanges();

                return(Ok(entity));
            }
            return(BadRequest());
        }
Esempio n. 26
0
        public ActionResult DeleteParentCategory(int id)
        {
            ParentCategory parentCategory =
                _productRepository.ParentCategories.FirstOrDefault(p => p.ParentCategoryId == id);
            if (parentCategory != null)
            {
                _productRepository.DeleteParentCategory(parentCategory);
                TempData["message"] = string.Format("Parent-Category {0} was deleted", parentCategory.Name);
            }

            return RedirectToAction("Index");
        }
        public bool Create(ParentCategoryServiceModel parentCategoryServiceModel)
        {
            ParentCategory parentCategory = new ParentCategory
            {
                Name = parentCategoryServiceModel.Name
            };

            context.ParentCategories.Add(parentCategory);
            int result = context.SaveChanges();

            return(result > 0);
        }
Esempio n. 28
0
 public ActionResult CreateParentCategory(ParentCategory pcat)
 {
     if (pcat.ParentName != null || pcat.ParentName != "")
     {
         var addParent = db.insertParentCategory(pcat.ParentName);
         return(RedirectToAction("ParentList"));
     }
     else
     {
         return(View());
     }
 }
Esempio n. 29
0
        private static void InsertParentCategory()
        {
            var parentCategory = new ParentCategory {
                Name = "Jedzenie", Description = "Pieniądze wydane na jedzenie, napoje"
            };

            using (var context = new ItemContext())
            {
                context.ParentCategories.Add(parentCategory);
                context.SaveChanges();
            }
        }
Esempio n. 30
0
        public ActionResult CreateParentCategory(ParentCategory obj)
        {
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }
            _parent.Insert(obj);

            Session["Message"] = "Data Added Successfully..................!!!!!!!";
            //Response.Write("<script> alert('') </script>");
            return(RedirectToAction("ParentCategory", "ParentCategory"));
        }