public ActionResult Index() { ViewBag.Title = "Welcome to free eshop platform."; return(View(ProductManage.GetAllProducts())); //return View(); }
public ActionResult DeleteProduct(int Id) { ProductManage pm = new ProductManage(); pm.Delete(Id); return(RedirectToAction("Index", "Admin")); }
public List <ProductDTO> GetAllProducts() { if (HttpContext.Current.Cache[keyAllProduct] != null) { return((List <ProductDTO>)HttpContext.Current.Cache[keyAllProduct]); } List <ProductDTO> list = ProductManage.GetAllProducts().Select(u => new ProductDTO { ProductId = u.ProductId, ProductName = u.ProductName, ProductSEOName = u.ProductSEOName, Category = u.Category, ProductPrice = u.ProductPrice, ProductCount = u.ProductCount, Discount = u.Discount, Tax = u.Tax, Shipping = u.Shipping, Status = u.Status, ImagePath = u.ImagePath }).ToList(); HttpContext.Current.Cache.Insert(keyAllProduct, list, null, DateTime.Now.ToUniversalTime().AddMinutes(10), Cache.NoSlidingExpiration); return(list); }
public HttpResponseMessage Post(int id) { string saveFileName = ""; //int id = int.Parse(HttpContext.Current.Request["id"]); var file = HttpContext.Current.Request.Files[0]; //for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++) //{ //HttpPostedFile file = HttpContext.Current.Request.Files[i]; var extension = new FileInfo(file.FileName).Extension; saveFileName = Guid.NewGuid().ToString() + extension; if (file != null && file.ContentLength > 0) { string filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Uploads"), saveFileName); file.SaveAs(filePath); ProductManage.UpdateImagePath(id, saveFileName); HttpContext.Current.Cache.Remove(keyPrefixProductId + id); HttpContext.Current.Cache.Remove(keyAllProduct); HttpResponse.RemoveOutputCacheItem("/Home/Index"); } //} return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = saveFileName })); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> // POST api/<controller> public HttpResponseMessage Post([FromBody] ProductDTO p) { ProductManage.Save(p); HttpContext.Current.Cache.Remove(keyAllProduct); HttpContext.Current.Cache.Remove(keyPrefixProductId + p.ProductId); HttpResponse.RemoveOutputCacheItem("/Home/Index"); return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Has added." })); }
/// <summary> /// DELETE /// </summary> /// <param name="id"></param> /// <returns></returns> public HttpResponseMessage Delete(int id) { ProductManage.Remove(id); HttpContext.Current.Cache.Remove(keyPrefixProductId + id); HttpContext.Current.Cache.Remove(keyAllProduct); HttpResponse.RemoveOutputCacheItem("/Home/Index"); return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Has deleted." })); }
/// <summary> /// 构造方法 /// </summary> public ProductAppService(IRepository <Product, int> productRepository, ProductManage productManage ) { _productRepository = productRepository; _productManage = productManage; }
/// <summary> /// Update /// </summary> /// <param name="id"></param> /// <param name="Product"></param> /// <returns></returns> public HttpResponseMessage Put(int id, ProductDTO Product) { Product.ProductId = id; if (!ProductManage.Update(Product)) { throw new HttpResponseException(HttpStatusCode.NotFound); } HttpContext.Current.Cache.Remove(keyPrefixProductId + id); HttpContext.Current.Cache.Remove(keyAllProduct); HttpResponse.RemoveOutputCacheItem("/Home/Index"); return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Has updated." })); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (productId > 0) { productInfo = ProductManage.GetProductInfoByProductId(productId); this.txtContent.Text = productInfo.Content; this.txtTitle.Text = productInfo.Title; } } }
/// <summary> /// 添加或编辑 /// </summary> /// <param name="model"></param> /// <returns></returns> public static ProductInfo Create(ProductInfo model) { if (model.Id == 0) { model.Id = ProductManage.Insert(model); } else { ProductManage.Update(model); } return(model); }
private void button10_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "确认要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { ProductManage deleteproduct = new ProductManage(); int id = Convert.ToInt32(dataGridView2.CurrentRow.Cells[0].Value); int tt = deleteproduct.deleteProduct(id); if (tt == 1) { MessageBox.Show("删除成功!", "提示"); GetData(dataAdapter.SelectCommand.CommandText); } } }
public JsonResult GetProducts(int?page, int?limit, string sortBy, string direction, string searchString = null) { int total = 0; var records = new object(); try { records = ProductManage.GetAllProducts(page, limit, sortBy, direction, searchString, out total); } catch (Exception e) { records = "error:" + e.Message; } return(Json(new { records, total }, JsonRequestBehavior.AllowGet)); }
void InitInfo() { productId = CECRequest.GetQueryInt("productId", 0); action = CECRequest.GetQueryString("action"); categoryId = CECRequest.GetQueryInt("categoryid", 0); if (action.ToLower() == "del") { ProductManage.Delete(productId); Response.Redirect("productlist.aspx"); return; } this.ddlcategoryList.BuildTree(ProductCategoryManage.GetCategoryForTable(), "CategoryName", "CategoryId"); this.ddlcategoryList.SelectedValue = categoryId.ToString(); }
void btnSave_Click(object sender, EventArgs e) { int _selectCategoryId = Convert.ToInt32(this.ddlcategoryList.SelectedValue); if (_selectCategoryId == 0) { this.ltErrorMsg.Text = "请选择所属分类"; return; } productInfo = new ProductInfo(); productInfo.CategoryId = _selectCategoryId; productInfo.Content = txtContent.Text; productInfo.Title = txtTitle.Text; ProductManage.Update(productInfo); string js = string.Format("alert('保存成功!');window.location.href='productlist.aspx?categoryId={0}';", _selectCategoryId); Page.ClientScript.RegisterStartupScript(this.GetType(), "SaveSuccess", js, true); }
public ActionResult AddProduct(Product product, List <HttpPostedFileBase> images) { if (!ModelState.IsValid) { using (StreamWriter sw = new StreamWriter(@"D:\test.txt", true, System.Text.Encoding.Default)) { } return(RedirectToAction("Index", "Home")); } ProductManage pm = new ProductManage(); if (pm.Add(product, images)) { return(RedirectToAction("Index", "Admin")); } else { return(RedirectToAction("Index", "Admin")); } }
static void Main(string[] args) { ProductManage carList = new ProductManage(); Console.Write(string.Format("{{0, -{0}}}|", 10), "Product"); Console.Write(string.Format("{{0, -{0}}}|", 5), "Price"); Console.Write(string.Format("{{0, -{0}}}|", 20), "DeliveryDate"); Console.Write(string.Format("{{0, -{0}}}|", 20), "Days"); Console.Write(string.Format("{{0, -{0}}}|", 20), "DelayDate"); Console.Write(string.Format("{{0, -{0}}}|", 20), "Status"); Console.WriteLine(); foreach (Product s in ProductManage.ViewProductsList) { Console.Write(string.Format("{{0, -{0}}}|", 10), s.Name); Console.Write(string.Format("{{0, -{0}}}|", 5), s.Price); Console.Write(string.Format("{{0, -{0}}}|", 20), s.DeliveryDate); Console.Write(string.Format("{{0, -{0}}}|", 20), s.ExpirationDays); Console.Write(string.Format("{{0, -{0}}}|", 20), s.GetDelayDate(s.DeliveryDate)); Console.Write(string.Format("{{0, -{0}}}|", 20), s.StatusProduct); Console.WriteLine(); } Console.ReadKey(); }
public ProductDTO GetProduct(int id) { if (HttpContext.Current.Cache[keyPrefixProductId + id] != null) { return((ProductDTO)HttpContext.Current.Cache[keyPrefixProductId + id]); } Product p = ProductManage.Get(id); if (p == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } ProductDTO mpd = new ProductDTO { ProductId = p.ProductId, ProductName = p.ProductName, ProductSEOName = p.ProductSEOName, Category = p.Category, Discount = p.Discount, Tax = p.Tax, Shipping = p.Shipping, ProductPrice = p.ProductPrice, ProductCount = p.ProductCount, Status = p.Status, ImagePath = p.ImagePath }; //HttpContext.Current.Cache[keyPrefixProductId + id] = mpd; HttpContext.Current.Cache.Insert(keyPrefixProductId + id, mpd, null, DateTime.Now.ToUniversalTime().AddMinutes(5), Cache.NoSlidingExpiration); return(mpd); }
/// <summary> /// 列表 /// </summary> /// <param name="setting"></param> /// <returns></returns> public static IPageOfList <ProductInfo> List(ProductSearchSetting setting) { return(ProductManage.List(setting)); }
private void LoadProduct() { var product = new ProductManage(); ShowForm.Show(product, Dialog: true); }
private void btnManagement_Click(object sender, EventArgs e) { productManage = new ProductManage(); frmLayout.panelContents.Controls.Clear(); frmLayout.panelContents.Controls.Add(productManage); }
/// <summary> /// 获得详细信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public static ProductInfo Get(int id) { return(ProductManage.Get(id)); }
public ActionResult Create(HttpPostedFileBase file1, HttpPostedFileBase file2, ProductManage emp) //Argument for HttpPostBase Files. { string filename1 = Path.GetFileName(file1.FileName); //filename1 variable is created for Small image. if (file2 != null) //if Large image is not null then following code will execute. { string filename2 = Path.GetFileName(file2.FileName); //filename2 is variable for large image. string _filename2 = DateTime.Now.ToString("yymmssfff") + filename2; //Append Date Time to filename2. string extension2 = Path.GetExtension(file2.FileName); //Extension for filename2. string path2 = Path.Combine(Server.MapPath("~/Images/"), _filename2); //Create path for Large image. emp.Large_Image = "~/Images/" + _filename2; //Table Object emp will stores the Large image path in Images folder. if (extension2.ToLower() == ".jpg" || extension2.ToLower() == ".jpeg" || extension2.ToLower() == ".png" && file2.ContentLength <= 1000000) //validation for extension and size of image. { file2.SaveAs(path2); //save file if validation is true. } } string _filename1 = DateTime.Now.ToString("yymmssfff") + filename1; //Append Date and time for small image. string extension1 = Path.GetExtension(file1.FileName); //get extension for small image. string path1 = Path.Combine(Server.MapPath("~/Images/"), _filename1); //Create path for Small image. emp.Small_Image = "~/Images/" + _filename1; //Table Object emp will stores the Small image path in Images folder. if (extension1.ToLower() == ".jpg" || extension1.ToLower() == ".jpeg" || extension1.ToLower() == ".png" && file1.ContentLength <= 1000000) //validation for extension and size of file. { db.ProductManages.Add(emp); if (db.SaveChanges() > 0) { file1.SaveAs(path1); ViewBag.msg = "Record Added"; ModelState.Clear(); } } else { ViewBag.msg = "Size is too Large!"; } db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); //save changes in database. HttpCookie cookie1 = new HttpCookie("CookieAdd"); //cookie is created for Toaster message. cookie1.Value = "Add"; //add value to cookie. Response.Cookies.Add(cookie1); //response is stored in cookie. cookie1.Expires = DateTime.Now.AddSeconds(5); // cookie will expire in 5 seconds. return(RedirectToAction("Index")); }
public ActionResult Edit(HttpPostedFileBase file1, HttpPostedFileBase file2, ProductManage emp) { if (file1 != null) //if small image is not null then following code is executed. it has same code as create. { string filename1 = Path.GetFileNameWithoutExtension(file1.FileName); string extension1 = Path.GetExtension(file1.FileName); string _filename1 = filename1 + DateTime.Now.ToString("yymmssfff") + extension1; string path1 = Path.Combine(Server.MapPath("~/Images/"), _filename1); emp.Small_Image = "~/Images/" + _filename1; if (extension1.ToLower() == ".jpg" || extension1.ToLower() == ".jpeg" || extension1.ToLower() == ".png" && file1.ContentLength <= 1000000) { db.Entry(emp).State = EntityState.Modified; string oldImgPath1 = Request.MapPath(Session["imgPath1"].ToString()); if (db.SaveChanges() > 0) { file1.SaveAs(path1); ModelState.Clear(); if (System.IO.File.Exists(oldImgPath1)) { System.IO.File.Delete(oldImgPath1); } }//following code is for toaster message for 5 second. HttpCookie cookie2 = new HttpCookie("CookieEdit"); cookie2.Value = "Edit"; Response.Cookies.Add(cookie2); cookie2.Expires = DateTime.Now.AddSeconds(5); return(RedirectToAction("Index")); } else { ViewBag.msg = "Size is too Large!"; } } else { emp.Small_Image = Session["imgPath1"].ToString(); db.Entry(emp).State = EntityState.Modified; if (db.SaveChanges() > 0) {//following code is for toaster message for 5 second. HttpCookie cookie2 = new HttpCookie("CookieEdit"); cookie2.Value = "Edit"; Response.Cookies.Add(cookie2); cookie2.Expires = DateTime.Now.AddSeconds(5); return(RedirectToAction("Index")); } } if (file2 != null) //if large image is not null then following code is executed and code is same as create. { string filename2 = Path.GetFileNameWithoutExtension(file2.FileName); string extension2 = Path.GetExtension(file2.FileName); string _filename2 = filename2 + DateTime.Now.ToString("yymmssfff") + extension2; string path2 = Path.Combine(Server.MapPath("~/Images/"), _filename2); emp.Large_Image = "~/Images/" + _filename2; if (extension2.ToLower() == ".jpg" || extension2.ToLower() == ".jpeg" || extension2.ToLower() == ".png" && file2.ContentLength <= 1000000) { db.Entry(emp).State = EntityState.Modified; string oldImgPath2 = Request.MapPath(Session["imgPath2"].ToString()); if (db.SaveChanges() > 0) { file2.SaveAs(path2); ModelState.Clear(); if (System.IO.File.Exists(oldImgPath2)) { System.IO.File.Delete(oldImgPath2); } }//following code is for toaster message for 5 second. HttpCookie cookie2 = new HttpCookie("CookieEdit"); cookie2.Value = "Edit"; Response.Cookies.Add(cookie2); cookie2.Expires = DateTime.Now.AddSeconds(5); return(RedirectToAction("Index")); } else { ViewBag.msg = "Size is too Large!"; } TempData["msg"] = "Record Updated"; } else { try { emp.Large_Image = Session["imgPath2"].ToString(); } catch { } db.Entry(emp).State = EntityState.Modified; if (db.SaveChanges() > 0) {//following code is for toaster message for 5 second. HttpCookie cookie2 = new HttpCookie("CookieEdit"); cookie2.Value = "Edit"; Response.Cookies.Add(cookie2); cookie2.Expires = DateTime.Now.AddSeconds(5); return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }