public static Response DoAddCart(String UserID, String ProductID, int qty) { MsProduct product = Repository.RepositoryMsProduct.SearchProductByID(ProductID); int servedqty = Repository.RepositoryCart.GetServedQty(ProductID); MsCart cart = Repository.RepositoryCart.SearchCart(UserID, ProductID); if (qty > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } if ((qty + servedqty) > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } if (cart == null) { Repository.RepositoryCart.InsertCart(UserID, ProductID, qty); } else { Repository.RepositoryCart.AppendCart(UserID, ProductID, qty); } return(new Response(true)); }
protected void rptProducts_ItemDataBound(object sender, RepeaterItemEventArgs e) { Label lblProductID = (Label)e.Item.FindControl("lblProductID"); Label lblProductName = (Label)e.Item.FindControl("lblProductName"); Label lblProductStock = (Label)e.Item.FindControl("lblProductStock"); Label lblProductType = (Label)e.Item.FindControl("lblProductType"); Label lblProductQuantity = (Label)e.Item.FindControl("lblProductQuantity"); var div = e.Item.FindControl("AdminAction"); string user = Session["user_role"] == null ? "Guest" : Session["user_role"].ToString(); MsProduct Product = (MsProduct)e.Item.DataItem; if (user == "Admin") { div.Visible = true; } lblProductID.Text = Product.ID.ToString(); lblProductName.Text = Product.Name.ToString(); lblProductStock.Text = Product.Stock.ToString(); lblProductQuantity.Text = Product.Price.ToString(); MsProductType ProductType = ProductRepository.GetProductName(Product.ProductTypeID).ElementAt(0); lblProductType.Text = ProductType.Name.ToString(); if (user == "Admin") { Button lbUpdate = (Button)e.Item.FindControl("lbUpdate"); Button lbDelete = (Button)e.Item.FindControl("lbDelete"); lbDelete.CommandArgument = Product.ID.ToString(); lbUpdate.CommandArgument = Product.ID.ToString(); } }
public static void UpdateStockProduct(String ID, int Stock) { MsProduct product = SearchProductByID(ID); product.ProductStock = product.ProductStock - Stock; db.SaveChanges(); }
public static void DeleteProduct(String ID) { MsProduct product = SearchProductByID(ID); db.MsProducts.Remove(product); db.SaveChanges(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["LoginSession"] == null) { Response.Redirect("../HomeView/Home.aspx"); } else { String ID = Session["LoginSession"].ToString(); MsUser user = HomeController.FetchDataForHome(ID); if (user.RoleID != "RL1") { Response.Redirect("../HomeView/Home.aspx"); } else { if (Request.QueryString["id"] == null) { Response.Redirect("../HomeView/Home.aspx"); } else { if (!IsPostBack) { String ProductID = Request.QueryString["id"]; MsProduct product = UpdateProductController.GetProductByID(ProductID); BoxProductName.Text = product.ProductName.ToString(); BoxProductPrice.Text = product.ProductPrice.ToString(); BoxProductStock.Text = product.ProductStock.ToString(); } } } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["LoginSession"] == null) { Response.Redirect("../HomeView/Home.aspx"); } else if (Request.QueryString["id"] == null) { Response.Redirect("../HomeView/Home.aspx"); } else { String ID = Session["LoginSession"].ToString(); MsUser user = HomeController.FetchDataForHome(ID); if (user.RoleID != "RL2") { Response.Redirect("../HomeView/Home.aspx"); } else { String ProductID = Request.QueryString["id"]; MsProduct product = AddToCartController.FetchDataByID(ProductID); MsProductType type = AddToCartController.GetProductType(product.ProductTypeID); LabelProductName.Text = product.ProductName.ToString(); LabelProductStock.Text = product.ProductStock.ToString(); LabelProductPrice.Text = product.ProductPrice.ToString(); LabelProductType.Text = type.ProductTypeName.ToString(); } } }
public static void UpdateProduct(String ID, String Name, int Price, int Stock) { MsProduct product = SearchProductByID(ID); product.ProductName = Name; product.ProductPrice = Price; product.ProductStock = Stock; db.SaveChanges(); }
public static void UpdateProduct(int ID, string Name, int Stock, int Type, int Price) { MsProduct product = db.MsProducts.Single(x => x.ID == ID); product.Name = Name; product.Stock = Stock; product.ProductTypeID = Type; product.Price = Price; db.SaveChanges(); }
public static MsProduct initProduct(string Name, int Stock, int Price, int ProductType) { MsProduct product = new MsProduct() { Name = Name, Stock = Stock, Price = Price, ProductTypeID = ProductType }; return(product); }
public static MsProduct InitProduct(String TypeID, String Name, int Price, int Stock, Int64 ID) { MsProduct products = new MsProduct(); products.ProductID = "PD" + ID; products.ProductTypeID = TypeID; products.ProductName = Name; products.ProductPrice = Price; products.ProductStock = Stock; return(products); }
public void Process() { var rabbitMqServer = RabbitMQManager.GetRabbitMQServer("rabbitMQ177"); var worker = new Websosanh.Core.JobServer.Worker("CMS.CommentNotify", false, rabbitMqServer); worker.JobHandler = (downloadImageJob) => { var product = MsProduct.GetDataFromMessage(downloadImageJob.Data); var a = product; return(true); }; worker.Start(); }
public static Response DeleteProductType(String ID) { MsProduct product = Repository.RepositoryMsProduct.SearchProductByTypeID(ID); if (product != null) { return(new Response(false, "Cannot Delete Product Type")); } else { Repository.RepositoryMsProductType.DeleteType(ID); return(new Response(true)); } }
public static Response DoDeleteProduct(String ID) { DetailTransaction detail = Repository.RepositoryDetailTransaction.SearchDetailByID(ID); MsProduct product = Repository.RepositoryMsProduct.SearchProductByID(ID); if (detail != null) { return(new Response(false, "Cannot Delete Product")); } if (product == null) { return(new Response(false, "Product Cannot Found")); } Repository.RepositoryMsProduct.DeleteProduct(ID); return(new Response(true)); }
public int InsertNewProduct(MsProduct product) { try { if (ModelState.IsValid) { unitOfWork.ProductRepository.Insert(product); unitOfWork.Save(); return(1); } } catch (DataException /* dex */) { return(0); } return(0); }
protected void rptProducts_ItemDataBound(object sender, RepeaterItemEventArgs e) { Label lblProductID = (Label)e.Item.FindControl("lblProductID"); Label lblProductName = (Label)e.Item.FindControl("lblProductName"); Label lblProductStock = (Label)e.Item.FindControl("lblProductStock"); Label lblProductType = (Label)e.Item.FindControl("lblProductType"); Label lblProductQuantity = (Label)e.Item.FindControl("lblProductQuantity"); string user = Session["user_role"] == null ? "Guest" : Session["user_role"].ToString(); MsProduct Product = (MsProduct)e.Item.DataItem; lblProductID.Text = Product.ID.ToString(); lblProductName.Text = Product.Name.ToString(); lblProductStock.Text = Product.Stock.ToString(); lblProductQuantity.Text = Product.Price.ToString(); MsProductType ProductType = ProductRepository.GetProductName(Product.ProductTypeID).ElementAt(0); lblProductType.Text = ProductType.Name.ToString(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["user_role"] == null || Session["user_role"].ToString() != "Admin") { Response.Redirect("../Home/index.aspx"); } ddlProductType.DataSource = ProductRepository.GetProductType(); ddlProductType.DataBind(); ddlProductType.DataTextField = "Name"; ddlProductType.DataValueField = "ID"; ddlProductType.DataBind(); MsProduct product = ProductRepository.GetOneProduct(Convert.ToInt32(Session["update_id"].ToString())).ElementAt(0); txtProductName.Text = product.Name.ToString(); txtStock.Text = product.Stock.ToString(); txtPrice.Text = product.Price.ToString(); ddlProductType.SelectedValue = product.ProductTypeID.ToString(); } }
public static Response UpdateCart(String UserID, String ProductID, int Qty) { MsProduct product = Repository.RepositoryMsProduct.SearchProductByID(ProductID); int servedqty = Repository.RepositoryCart.GetServedQty(ProductID); MsCart cart = Repository.RepositoryCart.SearchCart(UserID, ProductID); if (Qty == cart.Quantity) { return(new Response(true)); } if (Qty > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } if ((Qty + servedqty) > product.ProductStock) { return(new Response(false, "Must Be Less than Or Equals to Product Stock")); } RepositoryCart.UpdateCart(ProductID, UserID, Qty); return(new Response(true)); }
private void PushlishErrorWhenRequest(MsProduct msProductError) { _producer.PublishString(msProductError.GetJson()); }
public void Process(MsProduct msProduct) { Regex regex = new Regex(@"http.+html"); if (msProduct != null) { long productId = msProduct.ProductId; string url = msProduct.DetailUrlMerchant; if (string.IsNullOrEmpty(msProduct.DetailUrlMerchant)) { var product = _productAdapter.GetProduct(msProduct.ProductId); if (product != null) { url = product.DetailUrl; } } if (!string.IsNullOrEmpty(url)) { if (!url.Contains("http")) { url = "http://" + url; } string keyword = ""; int Type = 2; if (_productProcess.IsUrlEncoded(url)) { string urlencode = url; string urldecode = HttpUtility.UrlDecode(HttpUtility.UrlDecode(HttpUtility.UrlDecode(urlencode))); url = urldecode; MatchCollection matches = regex.Matches(url); if (matches.Count > 0) { url = matches[0].Value.ToString().Trim(); } Regex regexReplace = new Regex(@"http.+url="); url = regexReplace.Replace(url, ""); } try { Uri uri = new Uri(url); if (!_checkLast.CheckCanDownload(uri.Host)) { Log.Info("Sleep to download html"); Thread.Sleep(3000); } if (!_checkLinkValid.CheckLink(url)) { var company = _productAdapter.GetCompanyId(productId); if (_productProcess.IsAdsScore(productId)) { keyword = _productProcess.GetKeywordAds(productId); Type = 1; } else { ////Nếu không phải sản phẩm quảng cáo => Hạ sản phẩm xuống và Gửi phá cache. _producerService.SetStatusProduct(productId, EStatusProduct.NoValid); Log.InfoFormat("Invalid product {0} : {1} because not download html", msProduct.ProductId, url); } _productProcess.UpdateError(new ProductError { ProductId = productId, CompanyId = (company == null) ? 0 : company.Id, DetailUrl = url, DateLog = DateTime.Now, Keyword = keyword, Type = Type }); _checkLast.SetLast(uri.Host); Log.InfoFormat("Saved Product: {0}", productId); } else { Log.InfoFormat("Product {0} is ok", msProduct.ProductId); } } catch (UriFormatException uriFormatException) { Log.ErrorFormat("Error UriFormatException {0} {1}", msProduct.ProductId, uriFormatException.Message); } catch (WebException ex) { MsProduct reqError = new MsProduct(); reqError.ProductId = productId; reqError.DetailUrlMerchant = url; reqError.Error = ex.ToString(); PushlishErrorWhenRequest(reqError); Log.ErrorFormat("Error: {0}", ex.Status); Thread.Sleep(10000); } } } }