/// <summary> /// Handles Delete of an item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolBtnDelete_Click(object sender, EventArgs e) { DataRow drv = gridView1.GetFocusedDataRow(); if (drv != null) { Items itm = new Items(); ProductsCategory proCat = new ProductsCategory(); int itemId = Convert.ToInt32(drv["ID"]); if (!itm.HasTransactions(itemId)) { if (XtraMessageBox.Show("Are You Sure, You want to delete this Transaction? You will not be able to restore this data.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { proCat.GetCategoryByItem(itemId); foreach (DataRowView drcat in proCat.DefaultView) { ProductsCategory cat = new ProductsCategory(); cat.LoadByPrimaryKey(Convert.ToInt32(drcat["ID"])); cat.MarkAsDeleted(); cat.Save(); } itm.LoadByPrimaryKey(itemId); itm.MarkAsDeleted(); itm.Save(); XtraMessageBox.Show("Item Deleted!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { XtraMessageBox.Show("Unable to Delete, This Item has been Received or Issued.", "Unable to Delete", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
public ProductsPage(ProductsCategory categorySelected) { InitializeComponent(); _categorySelected = categorySelected; _productsViewModel = new ProductsViewModel(); BindingContext = _productsViewModel; }
public async Task <IActionResult> Edit(int id, [Bind("Id,FkIdProducts,FkIdCategory")] ProductsCategory productsCategory) { if (id != productsCategory.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productsCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsCategoryExists(productsCategory.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FkIdCategory"] = new SelectList(_context.Category, "Id", "Description", productsCategory.FkIdCategory); ViewData["FkIdProducts"] = new SelectList(_context.Products, "Id", "Description", productsCategory.FkIdProducts); return(View(productsCategory)); }
public Products() { count++; No = count; Category = ProductsCategory.xeta; }
public ActionResult DeleteConfirmed(int id) { ProductsCategory productsCategory = db.ProductsCategories.Find(id); db.ProductsCategories.Remove(productsCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ShouldNotUpdateANonAttachedCategory() { var category = new ProductsCategory { Title = "Foo" }; _db.ProductsCategories.Add(category); category.Title = "Bar"; Assert.Throws <InvalidOperationException>(() => _db.ProductsCategories.Update(category)); }
public ActionResult Edit([Bind(Include = "Id")] ProductsCategory productsCategory) { if (ModelState.IsValid) { db.Entry(productsCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productsCategory)); }
public ActionResult Edit([Bind(Include = "Id,CategoryName")] ProductsCategory productsCategory) { if (ModelState.IsValid) { db.Entry(productsCategory).State = EntityState.Modified; db.SaveChanges(); return(Json(new { text = "Added", Id = productsCategory.Id, Name = productsCategory.CategoryName })); } return(Json("Error")); }
public async Task <IActionResult> Create(Products product) { if (ModelState.IsValid) { switch (product.SaveAs) { case 1: MemoryCache.Instance.CurrentProduct = product; return(RedirectToAction(nameof(IndexMemory))); case 2: _context.Add(product); foreach (int productCategory in product.ProductCategories) { ProductsCategory newProductCategory = new ProductsCategory { FkIdCategory = productCategory, FkIdProducts = product.Id }; _context.ProductsCategory.Add(newProductCategory); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); default: product.ProductCategoriesPicker = _combosHelper.GetComboCategories(); return(View(product)); } /* if (product.SaveAs == 1) { * MemoryCache.Instance.CurrentProduct = product; * return RedirectToAction(nameof(Index)); * } * _context.Add(product); * foreach (int productCategory in product.ProductCategories) * { * ProductsCategory newProductCategory = new ProductsCategory * { * FkIdCategory = productCategory, * FkIdProducts = product.Id * }; * _context.ProductsCategory.Add(newProductCategory); * } * * await _context.SaveChangesAsync(); * * * return RedirectToAction(nameof(Index));*/ } product.ProductCategoriesPicker = _combosHelper.GetComboCategories(); return(View(product)); }
public ActionResult Create([Bind(Include = "Id,CategoryName")] ProductsCategory productsCategory) { if (ModelState.IsValid) { ProductsCategory pc = db.ProductsCategory.Add(productsCategory); db.SaveChanges(); return(Json(new { text = "Added", Id = pc.Id })); } return(Json("Error")); }
public ActionResult Create([Bind(Include = "Id")] ProductsCategory productsCategory) { if (ModelState.IsValid) { db.ProductsCategories.Add(productsCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productsCategory)); }
public ActionResult DeleteConfirmed(int id) { ProductsCategory productsCategory = db.ProductsCategory.Find(id); if (productsCategory == null) { return(Json("Error")); } db.ProductsCategory.Remove(productsCategory); db.SaveChanges(); return(Json("Deleted")); }
public async Task <IActionResult> Create([Bind("Id,FkIdProducts,FkIdCategory")] ProductsCategory productsCategory) { if (ModelState.IsValid) { _context.Add(productsCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FkIdCategory"] = new SelectList(_context.Category, "Id", "Description", productsCategory.FkIdCategory); ViewData["FkIdProducts"] = new SelectList(_context.Products, "Id", "Description", productsCategory.FkIdProducts); return(View(productsCategory)); }
// GET: ProductsCategories/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductsCategory productsCategory = db.ProductsCategories.Find(id); if (productsCategory == null) { return(HttpNotFound()); } return(View(productsCategory)); }
public void ShouldDeleteACategory() { var category = new ProductsCategory { Title = "Foo" }; _db.ProductsCategories.Add(category); _db.SaveChanges(); Assert.Equal(1, _db.ProductsCategories.Count()); _db.ProductsCategories.Remove(category); Assert.Equal(EntityState.Deleted, _db.Entry(category).State); _db.SaveChanges(); Assert.Equal(EntityState.Detached, _db.Entry(category).State); Assert.Equal(0, _db.ProductsCategories.Count()); }
public void ShouldAddACategoryWithContext() { var category = new ProductsCategory { Title = "Foo" }; _db.Add(category); Assert.Equal(EntityState.Added, _db.Entry(category).State); Assert.True(category.Id < 0); Assert.Null(category.TimeStamp); _db.SaveChanges(); Assert.Equal(EntityState.Unchanged, _db.Entry(category).State); Assert.Equal(0, category.Id); Assert.NotNull(category.TimeStamp); Assert.Equal(1, _db.ProductsCategories.Count()); }
public void ShouldDeleteACategoryWithTimestampData() { var category = new ProductsCategory { Title = "Foo" }; _db.ProductsCategories.Add(category); _db.SaveChanges(); var context = new CoreContext(); var catToDelete = new ProductsCategory { Id = category.Id, TimeStamp = category.TimeStamp }; context.Entry(catToDelete).State = EntityState.Deleted; var affected = context.SaveChanges(); Assert.Equal(1, affected); }
private void removeToolStripMenuItem_Click(object sender, EventArgs e) { if (lstCat.SelectedItems.Count > 0) { if (lstCat.SelectedItems[0] != null) { ProductsCategory prodCate = new ProductsCategory(); int id = Convert.ToInt32(lstCat.SelectedItems[0].Tag); if (prodCate.CategoryExists(_itemId, id)) { prodCate.GetProductCategory(_itemId, id); prodCate.MarkAsDeleted(); prodCate.Save(); } lstCat.Items.Remove(lstCat.SelectedItems[0]); } } }
public void ShouldNotDeleteACategoryWithoutTimestampData() { var category = new ProductsCategory { Title = "Foo" }; _db.ProductsCategories.Add(category); _db.SaveChanges(); var context = new CoreContext(); var catToDelete = new ProductsCategory { Id = category.Id }; context.ProductsCategories.Remove(catToDelete); var ex = Assert.Throws <DbUpdateConcurrencyException>(() => context.SaveChanges()); Assert.Equal(1, ex.Entries.Count); Assert.Equal(category.Id, ((ProductsCategory)ex.Entries[0].Entity).Id); }
public void ShouldUpdateACategory() { var category = new ProductsCategory { Title = "Foo" }; _db.ProductsCategories.Add(category); _db.SaveChanges(); category.Title = "Bar"; _db.ProductsCategories.Update(category); Assert.Equal(EntityState.Modified, _db.Entry(category).State); _db.SaveChanges(); Assert.Equal(EntityState.Unchanged, _db.Entry(category).State); CoreContext context; using (context = new CoreContext()) { Assert.Equal("Bar", context.ProductsCategories.First().Title); } }
public bool Update(ProductsCategory entity) { try { var procate = db.ProductsCategories.Find(entity.id); procate.name = entity.name; procate.metaTitle = entity.metaTitle; procate.seoTitle = entity.seoTitle; procate.modifyDate = DateTime.Now; procate.modifyBy = entity.modifyBy; procate.metaKeyword = entity.metaKeyword; procate.showOnHome = entity.showOnHome; procate.status = entity.status; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public async Task SetData(ProductsCategory category) { try { IsLoading = true; HttpClient httpClient = new HttpClient(); var html = await httpClient.GetStringAsync(@"http://piranigroup.com.pk/product-2/"); var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); var nodes = htmlDocument.DocumentNode.Descendants("div") .Where(x => x.GetAttributeValue("class", "").Equals(category.CategoryUrl)); foreach (var htmlNode in nodes) { var product = new Product { ProductName = HtmlEntity.DeEntitize(htmlNode.Descendants("h2").FirstOrDefault()?.InnerText), ProductImage = HtmlEntity.DeEntitize(htmlNode.Descendants("img").FirstOrDefault()? .ChildAttributes("src") .FirstOrDefault()? .Value) }; ProductsCollection.Add(product); } } catch (System.Exception) { throw; } finally { IsLoading = false; } }
public ActionResult Update(ProductsCategory procate) { if (ModelState.IsValid) { var dao = new ProductCategoryDAO(); var userSession = (UserLogin)Session[Common.CommonConstant.USER_SESSION]; procate.modifyBy = userSession.userName; bool id = dao.Update(procate); if (id) { SetAlert("Cập nhật danh mục sản phẩm thành công", "success"); return(RedirectToAction("Index")); } else { SetAlert("Cập nhật danh mục không thành công", "error"); } //ModelState.AddModelError("", "Chỉnh sửa danh mục sản phẩm không thành công"); } SetViewBag(procate.parentID); return(View()); }
public async Task <IActionResult> Create(CreateViewModel model) { if (model == null) { return(NotFound()); } try { if (!ModelState.IsValid) { return(View(model)); } var item = new ProductsCategory { Name = model.Name }; var result = await _repository.ProductsCategories.CreateAsync(item); if (result.Succeeded) { _logger.Information("Products category {@ProductsCategory} successfully added.", item); StatusMessage = (new AlertMessage(AlertStatus.success, "Категория продукта успешно добавлена.")).SerializeObject(); return(RedirectToAction(nameof(Index))); } else { _logger.Error("Error {@Error} adding products category {@ProductsCategory}.", result.Errors, item); } AddErrors(result); return(View(model)); } catch (Exception ex) { Log.Error(ex, "There was an error adding {ProductsCategorytName} products category", model.Name); return(View()); } }
public ActionResult Create(ProductsCategory model) { if (ModelState.IsValid) { var userSession = (UserLogin)Session[CommonConstant.USER_SESSION]; model.createBy = userSession.userName; model.createDate = DateTime.Now; var id = new ProductCategoryDAO().Insert(model); if (id > 0) { SetAlert("Thêm danh mục sản phẩm thành công", "success"); return(RedirectToAction("Index")); } else { SetAlert("Thêm danh mục sản phẩm không thành công", "error"); //ModelState.AddModelError("", StaticResources.Resource.InsertCategoryFail); } } SetViewBag(model.parentID); return(View()); }
public int AddProduct(string Name, double ProductPrice, int Quantity, ProductsCategory category) { if (string.IsNullOrEmpty(Name)) { throw new ArgumentNullException("Name", "Product's name is empty"); } if (ProductPrice == 0) { throw new ArgumentOutOfRangeException("ProductPrice", "Product's price is wrong"); } if (ProductPrice < 0) { throw new ArgumentOutOfRangeException("ProductPrice", "Product's price can't less than 0"); } if (Quantity == 0) { throw new ArgumentOutOfRangeException("Quantity", "Product's count is wrong"); } if (ProductPrice < 1) { throw new ArgumentOutOfRangeException("Quantity", "Product's count can't less than 0"); } if (category == ProductsCategory.xeta) { throw new ArgumentNullException("category", "Product's category is wrong"); } Products product = new(); product.Name = Name; product.ProductPrice = ProductPrice; product.Quantity = Quantity; product.Category = category; Product.Add(product); return(product.No); }
public string Post(ProductsCategory productCategory) { try { DataTable dt = new DataTable(); using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["MarketPlaceDB"].ConnectionString)) using (var cmd = new SqlCommand(SP_CreateCategory, con)) using (var da = new SqlDataAdapter(cmd)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@categoryName", productCategory.categoryName); cmd.Parameters.AddWithValue("@categoryDescription", productCategory.categoryDescription); da.Fill(dt); } return("Category created Successfully"); } catch (Exception) { return("Category creation has failed "); } }
public async Task <ActionResult> PostProductCategory([FromBody] ProductsCategory productsCategory) { if (ModelState.IsValid) { if (await this._repository.AddProductCategory(productsCategory) > 0) { return(CreatedAtAction( "GetProductCategories", new { id = productsCategory.CategoryId }, productsCategory )); } else { return(BadRequest()); } } else { return(BadRequest(ModelState)); } }
public ActionResult Create([Bind(Include = "ProductCategoryId,ProductId,CategoryId")] ProductsCategory productsCategory) { if (ModelState.IsValid) { if (UsingInMemory()) { productscategoriesCache.Add(new ProductsCategory() { ProductCategoryId = productsCategory.ProductCategoryId, CategoryId = productsCategory.CategoryId, ProductId = productsCategory.ProductId, }); } else { db.ProductsCategories.Add(productsCategory); db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", productsCategory.CategoryId); ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Title", productsCategory.ProductId); return(View(productsCategory)); }
public async Task <int> Insert(ProductsCategory productsCategory) { _productsCategorieRepository.Create(productsCategory); return(await Context.SaveChangesAsync()); }