public int CompareTo(Product other) { const StringComparison comparisonIgnoreCase = StringComparison.OrdinalIgnoreCase; if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } var codeProductComparison = CodeProduct.CompareTo(other.CodeProduct); if (codeProductComparison != 0) { return(codeProductComparison); } var nameComparison = string.Compare(Name, other.Name, comparisonIgnoreCase); if (nameComparison != 0) { return(nameComparison); } return(string.Compare(Mark, other.Mark, comparisonIgnoreCase)); }
/// <summary> /// accion del boton para guardar los datos del productos y las compras. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btSave_Click(object sender, RoutedEventArgs e) { if (validar()) { Product product = new Product(); product.nameProduct = TxtNameProduct.Text; product.price = AmountPrice(decimal.Parse(TxtPriceSale.Text), decimal.Parse(TxtAmount.Text)); product.IdCategory = db.Category.Where(b => b.nameCategory == CBCategory.SelectedItem.ToString()).FirstOrDefault().IdCategory; Buy buy = new Buy(); buy.DateBuy = DateTime.Now.Date; buy.IdUser = idUser; ControlBuy control = new ControlBuy(); CodeProduct code = new CodeProduct(); code.IdCodeBox = Convert.ToInt64(TxtCodPaquete.Text); code.IdCodeProduct = Convert.ToInt64(TxtCodProduct.Text); code.Enable = true; code.Quality = decimal.Parse(TxtQuality.Text); code.DateMaturity = CalDate.SelectedDate.Value.Date; if (control.addProduct(product, buy, decimal.Parse(TxtPriceSale.Text), code)) { MessageBox.Show("registro con exito", "exito"); clearValue(); } else { MessageBox.Show("error en el sistema", "error Sistema", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("Ingrese los datos por favor", "registro", MessageBoxButton.OK, MessageBoxImage.Information); } }
public ActionResult Create(Product entity) { if (ModelState.IsValid) { try { entity.CreatedDate = DateTime.Now; entity.Status = true; var model = new CodeProduct(); model.Add(entity); return(RedirectToAction("Index")); } catch (DbUpdateException ex) { ViewData["Error"] = ex.Message; return(View(entity)); } catch (Exception ex) { ViewData["Error"] = ex.Message; return(View(entity)); } } else { SetViewBag(); return(View(entity)); } }
public ActionResult ProductDetail(long id) { var model = new CodeProduct(); var result = model.ViewDetail(id); return(View(result)); }
public ActionResult ProductCategory(int id, int page = 1, int pageSize = 4) { var productcategory = new CodeCategory().ViewDetail(id); ViewBag.Category = productcategory; int totalRecord = 0; var model = new CodeProduct().ListProductCategory(id, ref totalRecord, page, pageSize); //ViewBag.TagPost = new CodePost().ListPostCategory(id); ViewBag.Total = totalRecord; ViewBag.Page = page; int maxPage = 4; int totalPage = 0; totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); ViewBag.TotalPage = totalPage; ViewBag.MaxPage = maxPage; ViewBag.First = 1; ViewBag.Last = totalPage; ViewBag.Next = page + 1; ViewBag.Prev = page - 1; return(View(model)); }
public ActionResult Edit(long ID) { var model = new CodeProduct(); var result = model.ViewDetail(ID); SetViewBag(result.ID); return(View(result)); }
public override int GetHashCode() { unchecked { var hashCode = Id.GetHashCode(); hashCode = (hashCode * 397) ^ CodeProduct.GetHashCode(); hashCode = (hashCode * 397) ^ (Name != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(Name) : 0); hashCode = (hashCode * 397) ^ (Mark != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(Mark) : 0); return(hashCode); } }
/// <summary> /// añade los detalles de la compra del producto correspodiente. /// </summary> /// <param name="buy"></param> /// <param name="priceBuy"></param> /// <param name="code"></param> /// <param name="t"></param> private void addDetailBuy(Buy buy, decimal priceBuy, CodeProduct code, Product t) { addBuy(buy); DetailBuy detailBuy = new DetailBuy(); detailBuy.IdBuy = db.Buy.Max(b => b.IdBuy); detailBuy.IdProduct = db.Product.Where(b => b.nameProduct == t.nameProduct).FirstOrDefault().IdProduct; detailBuy.PriceBuy = priceBuy; detailBuy.Quality = code.Quality; db.DetailBuy.InsertOnSubmit(detailBuy); db.SubmitChanges(); }
public JsonResult Delete(long Id) { try { var model = new CodeProduct(); model.Delete(Id); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Success = false, Msg = ex.Message }, JsonRequestBehavior.AllowGet)); } }
// GET: Admin/Product public ActionResult Index(int page = 1, int pagesize = 5) { try { var model = new CodeProduct(); var result = model.GetAllProduct(); return(View(result)); } catch (Exception ex) { ViewData["Error"] = ex.Message; return(View()); } }
public ActionResult Edit(Product entity) { try { entity.ModifiedDate = DateTime.Now; var model = new CodeProduct(); model.Update(entity); return(RedirectToAction("Index")); } catch (Exception ex) { ViewData["Error"] = ex.Message; return(View(entity)); } }
public JsonResult DataTableGet([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel) { var context = new ShopBanHangDbContext(); var model = new CodeProduct(); IQueryable <ProductModel> query = model.GetAllProduct().AsQueryable(); var totalCount = query.Count(); // Apply filters if (!string.IsNullOrEmpty(requestModel.Search.Value)) { var value = requestModel.Search.Value.Trim(); query = query.Where(p => p.Name.Contains(value)); } var filteredCount = query.Count(); // Sort var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; foreach (var column in sortedColumns) { orderByString += orderByString != String.Empty ? "," : ""; orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc"); } orderByString = orderByString == String.Empty ? "ID asc" : orderByString; query = query.OrderBy(orderByString); // Paging query = query.Skip(requestModel.Start).Take(requestModel.Length); var data = query.Select(p => new { Id = p.ID, Name = p.Name, Price = p.Price, Quantity = p.Quantity, Category = p.Category, CreatedDate = p.CreatedDate.ToString("dd-MM-yyyy"), Action = "<br /><p class=\"btn-action\"><a href=\"#\" class=\"detail\"><i class=\"ui-tooltip fa fa-pencil-square-o detail\" style=\"font-size: 22px;\" data-original-title=\"Detail\"></i></a> <a href=\"#\" class=\"remove\" ><i class=\"ui-tooltip fa fa-trash-o remove\" style=\"font-size: 20px;\" data-original-title=\"Delete\" tooltip=\"Delete\"></i></a></p>", }).ToList(); return(Json(new DataTablesResponse(requestModel.Draw, data, filteredCount, totalCount), JsonRequestBehavior.AllowGet)); }
/// <summary> /// añade un producto a la base de datos. /// </summary> /// <param name="product"></param> /// <param name="buy"></param> /// <param name="priceBuy"></param> /// <param name="code"></param> /// <returns>true si todo fue correcto y no existe ningun error</returns> public bool addProduct(Product product, Buy buy, decimal priceBuy, CodeProduct code) { try { var verificar = db.Product.Where(b => b.nameProduct == product.nameProduct).Count(); if (verificar == 0) { db.Product.InsertOnSubmit(product); db.SubmitChanges(); code.IdProduct = db.Product.Where(b => b.nameProduct == product.nameProduct).FirstOrDefault().IdProduct; db.CodeProduct.InsertOnSubmit(code); db.SubmitChanges(); addDetailBuy(buy, priceBuy, code, product); } else { Product t = db.Product.Where(b => b.nameProduct == product.nameProduct).FirstOrDefault(); t.price = product.price; db.SubmitChanges(); var verifi = db.CodeProduct.Where(b => b.IdCodeProduct == code.IdCodeProduct).Count(); if (verifi == 0) { code.IdProduct = t.IdProduct; db.CodeProduct.InsertOnSubmit(code); db.SubmitChanges(); addDetailBuy(buy, priceBuy, code, product); } else { CodeProduct produ = db.CodeProduct.Where(b => b.IdProduct == t.IdProduct).FirstOrDefault(); produ.Quality = produ.Quality + code.Quality; db.SubmitChanges(); addDetailBuy(buy, priceBuy, code, product); } } return(true); } catch (Exception) { return(false); } }
public ActionResult PostAll(int page = 1, int pageSize = 10) { int totalRecord = 0; var model = new CodeProduct().ListAll(ref totalRecord, page, pageSize); ViewBag.Total = totalRecord; ViewBag.Page = page; int maxPage = 4; int totalPage = 0; totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); ViewBag.TotalPage = totalPage; ViewBag.MaxPage = maxPage; ViewBag.First = 1; ViewBag.Last = totalPage; ViewBag.Next = page + 1; ViewBag.Prev = page - 1; return(View(model)); }
public JsonResult AddItem(long productId, int quantity) { var product = new CodeProduct().ViewDetail(productId); var cart = Session[Common.CommonConstants.CartSession]; if (cart != null) { var list = (List <CartItem>)cart; if (list.Exists(x => x.Product.ID == productId)) { foreach (var item in list) { if (item.Product.ID == productId) { item.Quantity += quantity; } } } else { var item = new CartItem(); item.Product = product; item.Quantity = quantity; list.Add(item); } Session[CommonConstants.CartSession] = list; } else { var item = new CartItem(); item.Product = product; item.Quantity = quantity; var list = new List <CartItem>(); list.Add(item); Session[CommonConstants.CartSession] = list; } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult Search(string keyword, int page = 1, int pageSize = 10) { int totalRecord = 0; var model = new CodeProduct().ListSearchProduct(keyword, ref totalRecord, page, pageSize); //ViewBag.TagPost = new CodePost().ListPostCategory(id); ViewBag.Total = totalRecord; ViewBag.Page = page; ViewBag.Keyword = keyword; int maxPage = 4; int totalPage = 0; totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); ViewBag.TotalPage = totalPage; ViewBag.MaxPage = maxPage; ViewBag.First = 1; ViewBag.Last = totalPage; ViewBag.Next = page + 1; ViewBag.Prev = page - 1; return(View(model)); }
// GET: Home public ActionResult Index() { //Dung service List <ServiceShopBanHang.Product> listFeatureProduct = new List <ServiceShopBanHang.Product>(); try { listFeatureProduct = service.GetFeatureProduct().ToList(); } catch { // ignored } finally { var model = new CodeProduct(); ViewBag.FeatureProduct = listFeatureProduct; ViewBag.NewProduct = model.GetNewProduct(); } return(View()); }
public JsonResult ListName(string q) { var data = new CodeProduct().ListName(q); return(Json(new { data = data, Status = true }, JsonRequestBehavior.AllowGet)); }