Esempio n. 1
0
        public ActionResult GetAllChildcategories()
        {
            ChildCategory objchild = new ChildCategory();
            var           result   = objchild.GetAllChild();

            return(PartialView("_ManageChildCategories", result));
        }
Esempio n. 2
0
        protected async Task Select(CatDisplay catDisplay, Category selCategory, ChildCategory childCategory = null)
        {
            Debug.Write("Select " + catDisplay?.Title ?? "null");
            if (selCategory == null)
            {
                Debug.Write("Category is null");
            }
            if (lastSelect != null)
            {
                lastSelect.Image = lastImageState;
            }
            lastSelect = catDisplay;

            lastImageState = catDisplay?.Image ?? CatSelectImage.none;

            LastSelectedCategory = selCategory;
            if (selCategory != null)
            {
                LastSelectedCategory.SelectedChildCategory = childCategory;
            }
            catDisplay.Image = CatSelectImage.selected;

            var navigationParams = new NavigationParameters();

            navigationParams.Add("SelectedCategory", selCategory);
            await _navigationService.GoBackAsync(navigationParams);
        }
        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());
        }
        public async Task <IActionResult> CreateChildCategory(string name, IFormFile file)
        {
            Guid          Id       = Guid.NewGuid();
            ChildCategory category = new ChildCategory()
            {
                ChildCategoryId = Guid.NewGuid(), Name = name, ImageId = Id
            };
            Image image2 = null;

            if (file != null)
            {
                byte[] imageData1 = null;
                using (var binaryReader = new BinaryReader(file.OpenReadStream()))
                {
                    imageData1 = binaryReader.ReadBytes((int)file.Length);
                }
                image2 = new Image()
                {
                    Name    = file.FileName,
                    ByteImg = imageData1,
                    ImageId = Id
                };
            }
            await _context.Images.AddAsync(image2);

            await _context.ChildCategories.AddAsync(category);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Main", "Admin"));
        }
 public ActionResult DeleteChildCategory(ChildCategory ch)
 {
     db.Products.RemoveRange(db.Products.Where(x => x.C_Cat_Id == ch.Id));
     db.ChildCategories.Remove(db.ChildCategories.Find(ch.Id));
     db.SaveChanges();
     TempData["msg"] = "اطلاعات با موفقیت آپدیت شد";
     return(RedirectToAction("ManagmentCategoryView", "Category", new { id = -1 }));
 }
Esempio n. 6
0
        public ActionResult DeleteChildCategory(int id)
        {
            ChildCategory objchild = new ChildCategory();

            objchild.DeleteSubCategory(id);
            var result = objchild.GetAllChild();

            return(PartialView("_ManageChildCategories", result));
        }
 public ChildCategory CreateCategory(ChildCategory category)
 {
     if (!ModelState.IsValid)
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
     _context.ChildCategorys.Add(category);
     _context.SaveChanges();
     return(category);
 }
        public async Task <IActionResult> UpdateChildCat(ChildCategory childCat)
        {
            ChildCategory category = await _context.ChildCategories.FindAsync(Guid.Parse(childCat.Id));

            category.Name = childCat.Name;
            _context.ChildCategories.Update(category);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Main", "Admin"));
        }
        public ActionResult UpdateChildCategory(ChildCategory ch)
        {
            var d = db.ChildCategories.Find(ch.Id);

            d.Name = ch.Name;
            db.SaveChanges();


            TempData["msg"] = "اطلاعات با موفقیت آپدیت شد";
            return(RedirectToAction("ManagmentCategoryView", "Category", new { id = -1 }));
        }
        public async Task <IActionResult> DeleteChild(string Id)
        {
            ChildCategory cat = await _context.ChildCategories.FindAsync(Guid.Parse(Id));

            if (cat != null)
            {
                _context.ChildCategories.Remove(cat);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction("Main", "Admin"));
        }
Esempio n. 11
0
        public ChildCategory CreateChildCategory(string name, int categoryId, string imageUrl)
        {
            var childCategory = new ChildCategory
            {
                Name             = name,
                ParentCategoryId = categoryId,
                ImageUrl         = imageUrl
            };

            this.db.ChildCategories.Add(childCategory);
            this.db.SaveChanges();

            return(childCategory);
        }
        public ActionResult ChildCategory(int SubCategoryId, int CategoryId)
        {
            var results = objIronWork.GetCategorybyId(CategoryId);

            ViewBag.LogoImage = results.LogoPath;
            SubCategory obj  = new SubCategory();
            var         data = obj.Getsubcategory(SubCategoryId);

            ViewBag.SubcategoryName = data.SubCategory_Name;
            ChildCategory objchild = new ChildCategory();
            var           result   = objchild.ChildImages(SubCategoryId);

            return(View(result));
        }
Esempio n. 13
0
        public ChildCategory CreateChildCategory(string name, string description, int parentId)
        {
            var childCategoty = new ChildCategory
            {
                Name             = name,
                Description      = description,
                ParentCategoryId = parentId
            };

            this.db.ChildCategories.Add(childCategoty);
            this.db.SaveChanges();

            return(childCategoty);
        }
        public void AddImageUrlsShouldAddImageUrls()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddImageUrls_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 productName = "USB";

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = productName, ChildCategory = childCategory
                },
                new Product {
                    Name = "Cable", ChildCategory = childCategory
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategory
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategory
                },
            });
            dbContext.SaveChanges();

            var productId = dbContext.Products.FirstOrDefault(x => x.Name == productName).Id;
            var imageUrls = new List <string> {
                "wwwroot/image1", "wwwroot/image2", "wwwroot/image3"
            };

            productService.AddImageUrls(productId, imageUrls);

            var product = dbContext.Products.FirstOrDefault(x => x.Id == productId);

            Assert.Equal(3, product.Images.Count);
        }
Esempio n. 15
0
        public ActionResult UpdateParentCategory(ChildCategory p)
        {
            var found = db.ParentCategories.Find(p.Id);

            if (found.Id != null)
            {
                db.Sp_UpdateParentCategory(found.Id, p.Name);
            }
            db.SaveChanges();
            TempData["msg"] = "اطلاعات با موفقیت آپدیت شد";



            return(RedirectToAction("ManagmentCategoryView", "Category", new { id = -1 }));
        }
Esempio n. 16
0
        public ActionResult SaveCategory(ChildCategory childCategory)
        {
            if (childCategory.Id == 0)
            {
                _context.ChildCategorys.Add(childCategory);
            }

            else
            {
                var categoryInDb = _context.ChildCategorys.Single(c => c.Id == childCategory.Id);
                categoryInDb.Name             = childCategory.Name;
                categoryInDb.ParentCategoryId = childCategory.ParentCategoryId;
            }
            _context.SaveChanges();
            return(RedirectToAction("CategoryDetails", "Category"));
        }
Esempio n. 17
0
        public bool Create(ProductServiceModel productServiceModel)
        {
            ChildCategory childCategoryFromDb = this.context.ChildCategories.FirstOrDefault(c => c.Id == productServiceModel.ChildCategoryId);

            if (childCategoryFromDb == null)
            {
                return(false);
            }

            Product product = AutoMapper.Mapper.Map <Product>(productServiceModel);

            product.ChildCategory = childCategoryFromDb;

            context.Products.Add(product);
            int result = context.SaveChanges();

            return(result > 0);
        }
        public void UpdateCategory(int id, ChildCategory category)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var categoryInDb = _context.ChildCategorys.SingleOrDefault(m => m.Id == id);

            if (categoryInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            categoryInDb.Name             = category.Name;
            categoryInDb.ParentCategoryId = category.ParentCategoryId;


            _context.SaveChanges();
        }
        public void GetProductsByCategoryShouldReturnProductsByCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetProductsByCategory_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();

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB", ChildCategory = childCategory
                },
                new Product {
                    Name = "Cable", ChildCategory = childCategory
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategory
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategory
                },
            });
            dbContext.SaveChanges();

            var products = productService.GetProductsByCategory(childCategory.Id);

            var invalidChildCategoryId = 123;
            var productsByInvalidId    = productService.GetProductsByCategory(invalidChildCategoryId);

            Assert.Equal(4, products.Count());
            Assert.Empty(productsByInvalidId);
        }
        public void GetHideProductByIdShouldReturnOnlyHideProduct()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetHideProductById_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 products = new List <Product>
            {
                new Product {
                    Id = 1, Name = "USB", ChildCategory = childCategory, Hide = true
                },
                new Product {
                    Id = 2, Name = "Cable", ChildCategory = childCategory, Hide = false
                },
                new Product {
                    Id = 3, Name = "Keyboard", ChildCategory = childCategory, Hide = false
                },
                new Product {
                    Id = 4, Name = "Computer", ChildCategory = childCategory, Hide = false
                },
            };

            dbContext.Products.AddRange(products);
            dbContext.SaveChanges();

            var firstProduct = productService.GetHideProductById(products.First().Id);
            var lastProduct  = productService.GetHideProductById(products.Last().Id);

            Assert.Equal(firstProduct.Name, products.First().Name);
            Assert.Null(lastProduct);
        }
        public void GetProductByIdShouldReturnProduct()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetProductById_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 productName = "USB";

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = productName, ChildCategory = childCategory
                },
                new Product {
                    Name = "Cable", ChildCategory = childCategory
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategory
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategory
                },
            });
            dbContext.SaveChanges();

            var productId = dbContext.Products.FirstOrDefault(x => x.Name == productName).Id;
            var product   = productService.GetProductById(productId);

            Assert.Equal(productName, product.Name);
        }
        public async Task <IActionResult> UpdateCat(CatAddModel model)
        {
            Category category = _context.Categories.Include(x => x.ChildCategories).FirstOrDefault(x => x.CategoryId == Guid.Parse(model.Id));

            category.Name = model.Name;
            List <ChildCategory> Childs = new List <ChildCategory>();

            foreach (var x in model.ChildCategoryId)
            {
                ChildCategory Category = await _context.ChildCategories.FindAsync(Guid.Parse(x));

                Childs.Add(Category);
            }

            category.ChildCategories = Childs;
            _context.Categories.Update(category);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Main", "Admin"));
        }
        public void GetHideProductsShouldReturnAllHideProducts()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetHideProducts_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();

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB", ChildCategory = childCategory, Hide = true
                },
                new Product {
                    Name = "Cable", ChildCategory = childCategory, Hide = true
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategory
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategory
                },
            });
            dbContext.SaveChanges();

            var products = productService.GetHideProducts();

            Assert.Equal(2, products.Count());
            Assert.DoesNotContain(products, x => x.Hide == false);
        }
        public void GetImagesShouldReturnImageUrls()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetImages_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,
                Images        = new List <Image>
                {
                    new Image {
                        ImageUrl = "wwwroot/image1"
                    },
                    new Image {
                        ImageUrl = "wwwroot/image2"
                    }
                }
            };

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

            var productImagesCount = productService.GetImages(product.Id).Count();

            Assert.Equal(2, productImagesCount);
        }
        public void GetProductsBySearchShouldReturnGetProductsBySearch(string searchString, int expected)
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"{searchString}_GetProductsBySearch_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();

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

            var products = productService.GetProductsBySearch(searchString);

            Assert.Equal(expected, products.Count());
        }
        public bool Create(ChildCategoryServiceModel childCategoryServiceModel)
        {
            var isParentCategoryExists = this.parentCategoriesService.IsHaveParentCategory(childCategoryServiceModel.ParentCategoryId);

            if (!isParentCategoryExists)
            {
                return(false);
            }


            ChildCategory childCategory = new ChildCategory
            {
                Name             = childCategoryServiceModel.Name,
                ParentCategoryId = childCategoryServiceModel.ParentCategoryId
            };

            this.context.ChildCategories.Add(childCategory);
            int result = this.context.SaveChanges();


            return(result > 0);
        }
        public async Task <IActionResult> CreateCategory(CatAddModel model)
        {
            Guid     Id       = new Guid();
            Category category = new Category()
            {
                CategoryId = Id, Name = model.Name
            };
            List <ChildCategory> Childs = new List <ChildCategory>();

            foreach (var x in model.ChildCategoryId)
            {
                ChildCategory Category = await _context.ChildCategories.FindAsync(Guid.Parse(x));

                Category.CategoryId = Id;
                Childs.Add(Category);
            }
            category.ChildCategories = Childs;
            await _context.Categories.AddAsync(category);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Main", "Admin"));
        }
Esempio n. 28
0
 public ChildElementAttribute(int order, ChildCategory childCategory)
     : this(order, childCategory, typeof(Element))
 {
 }
Esempio n. 29
0
 public ChildElementAttribute(int order, ChildCategory childCategory, Type childType)
 {
     this.Order = order;
     this.ChildCategory = childCategory;
     this.ChildType = childType;
 }
Esempio n. 30
0
 public ChildElementAttribute(int order, ChildCategory childCategory)
     : this(order, childCategory, typeof(Element))
 {
 }
Esempio n. 31
0
 public ChildElementAttribute(int order, ChildCategory childCategory, Type childType)
 {
     this.Order         = order;
     this.ChildCategory = childCategory;
     this.ChildType     = childType;
 }
Esempio n. 32
0
        public ActionResult AddChildImage(SubCategory obj)
        {
            ChildCategory objChild  = new ChildCategory();
            string        _imgname  = string.Empty;
            var           imgPath2  = string.Empty;
            string        SubFolder = obj.Subcategory;

            SubFolder = Regex.Replace(SubFolder, @"\s", "");
            if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var pic = System.Web.HttpContext.Current.Request.Files["file"];
                if (pic.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(pic.FileName);
                    var _ext     = Path.GetExtension(pic.FileName);
                    _imgname = Guid.NewGuid().ToString();
                    var _comPath = String.Empty;
                    switch (obj.Category)
                    {
                    case 1:
                        //_comPath = Server.MapPath("~/Images/IronWork/") + _imgname + _ext;
                        _comPath = Server.MapPath("~/Images/IronWork/");
                        imgPath2 = "/Images/IronWork/";
                        break;

                    case 2:
                        _comPath = Server.MapPath("~/Images/Landscape/");
                        imgPath2 = "/Images/Landscape/";
                        break;

                    case 3:
                        _comPath = Server.MapPath("~/Images/Masonary/");
                        imgPath2 = "/Images/Masonary/";
                        break;

                    case 4:
                        _comPath = Server.MapPath("~/Images/Construction/");
                        imgPath2 = "/Images/Construction/";
                        break;

                    case 5:
                        _comPath = Server.MapPath("~/Images/Kitchens/");
                        imgPath2 = "/Images/Kitchens/";
                        break;

                    case 6:
                        _comPath = Server.MapPath("~/Images/DriveWays/");
                        imgPath2 = "/Images/DriveWays/";
                        break;

                    default:
                        Console.WriteLine("Invalid grade");
                        break;
                    }

                    var DirectoryImage = _comPath + SubFolder;

                    if (!Directory.Exists(DirectoryImage))
                    {
                        Directory.CreateDirectory(DirectoryImage);
                    }
                    _comPath = _comPath + SubFolder + "/" + _imgname + _ext;
                    imgPath2 = imgPath2 + SubFolder + "/" + _imgname + _ext;
                    var path = _comPath;
                    pic.SaveAs(path);
                    objChild.AddChildImage(obj, imgPath2);
                }
            }
            return(Json("Child Category Add Successfully", JsonRequestBehavior.AllowGet));
        }