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(); } }
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()); }
public ActionResult ParentCategoriesList2() { ParentCategory model = new ParentCategory(); var query = _pageRepository.GetParentCategoriesList2(); return(PartialView("_ParentCategories")); }
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()); }
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(); } }
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(); } }
public GameObject GetAudioObjectPrefab() { if (AudioObjectPrefab != null) { return(AudioObjectPrefab); } return(ParentCategory != null?ParentCategory.GetAudioObjectPrefab() : AudioController.AudioObjectPrefab); }
public ActionResult DeleteConfirmed(string id) { ParentCategory parentCategory = db.ParentCategories.Find(id); db.ParentCategories.Remove(parentCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
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); }
public ActionResult Create(ParentCategory category) { if (ModelState.IsValid) { category.Save(); return(RedirectToAction("Index")); } return(View()); }
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 })); }
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)); }
public void AddMainCategory(string name, string imageUrl) { var category = new ParentCategory() { Name = name, ImageUrl = imageUrl }; this.db.ParentCategories.Add(category); this.db.SaveChanges(); }
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()); }
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)); }
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(); } }
public ActionResult CreateCategory(ParentCategory newCategory) { try { newCategory.SaveCategory(); return(RedirectToAction("Index", "Home")); } catch (Exception ex) { return(RedirectToAction("CreateCategory")); } }
public IActionResult AddParentCategory(ParentCategory entity) { if (ModelState.IsValid) { entity.Categories = new List <Category>(); unitOfWork.ParentCategories.Add(entity); unitOfWork.SaveChanges(); return(Ok(entity)); } return(BadRequest()); }
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); }
public ActionResult CreateParentCategory(ParentCategory pcat) { if (pcat.ParentName != null || pcat.ParentName != "") { var addParent = db.insertParentCategory(pcat.ParentName); return(RedirectToAction("ParentList")); } else { return(View()); } }
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(); } }
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")); }