public string DeleteProduct(ProductM productModel, int id) { DbHelper dbHelper = new DbHelper(); productModel = dbHelper.DeleteProduct(productModel, id); return("Success"); }
public ActionResult sendMail(int?id) { Product product = new Product(); ProductM p = new ProductM(); product = Service.GetById((int)id); p.IdProduct = product.IdProduct; p.qte = product.qte; using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Hello World"; mail.Body = "<h1>Hello !</h1>" + product.Nom + "veillez nous envoyer svp" + p.qte; mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)) { smtp.Credentials = new NetworkCredential("*****@*****.**", "Password"); smtp.EnableSsl = true; smtp.Send(mail); } } Service.Update(product); Service.Commit(); return(View(p)); }
public string fnInsert(ProductM productM) { string sSql = " INSERT INTO [dbo].[MNDTproduct_master] " + " ([product_id] " + " ,[company_id] " + " ,[name] " + " ,[unit] " + " ,[currency] " + " ,[cost] " + " ,[price] " + " ,[shelf_life] " + " ,[description] " + " ,[status] " + " ,[create_id] " + " ,[create_datetime]) " + " VALUES " + " ('" + productM.product_id + "' " + " ,'" + productM.company_id + "' " + " ,'" + productM.name + "' " + " ,'" + productM.unit + "' " + " ,'" + productM.currency + "' " + " ,'" + productM.cost + "' " + " ,'" + productM.price + "' " + " ,'" + productM.shelf_life + "' " + " ,'" + productM.description + "' " + " ,'N' " + " ,'" + productM.create_id + "' " + " ,GETDATE()) "; return(PublicApi.fnExecuteSQL(sSql, "MNDT")); }
// GET: Productt/Details/5 public ActionResult Details(int?id) { List <Rayon> Rayons = ServiceRayon.GetMany().ToList(); ViewBag.MyRayons = new SelectList(Rayons, "IdRayon", "typeR"); Product product = new Product(); ProductM p = new ProductM(); product = Service.GetById((int)id); p.IdProduct = product.IdProduct; p.Nom = product.Nom; p.imageP = product.imageP; p.description = product.description; p.barcode = product.barcode; p.IdRayon = product.IdRayon; p.marque = product.marque; p.price = product.price; p.dateC = product.dateC; p.dateF = product.dateF; p.qte = product.qte; return(View(p)); }
// iPage 第N頁 // iSize 最大顯示數量 public DataTable fnSelects(ProductM productM, int iPage, int iSize) { int iStart = (iPage - 1) * iSize + 1; int iEnd = iPage * iSize; string sCondition = ""; sCondition += PublicApi.fnAddCondition("[product_id]", productM.product_id); sCondition += PublicApi.fnAddCondition("[company_id]", productM.company_id); sCondition += PublicApi.fnAddCondition("[name]", productM.name); string sInquireSql = " SELECT [product_m].[NUM], " + " [product_m].[product_id], " + " [product_m].[company_id], " + " [product_m].[name], " + " CONVERT(CHAR, [product_m].[create_datetime], 111) [create_datetime] " + " FROM (SELECT Row_number() OVER(ORDER BY[" + productM.order + "] ASC) NUM, " + " * " + " FROM [MNDTproduct_master] " + " WHERE 1 = 1 " + sCondition + ") AS [product_m] " + " WHERE NUM BETWEEN " + iStart.ToString() + " AND " + iEnd.ToString(); return(PublicApi.fnGetDt(sInquireSql, "MNDT")); }
public async Task <IActionResult> Add(ProductM model) { if (!ModelState.IsValid) { return(View(model)); } Product product = new Product() { Name = model.Name, SaleAmount = model.SaleAmount, Barcode = model.Barcode, Specifications = model.Specifications, BuyAmount = model.BuyAmount, CostAmount = model.CostAmount, CreatedDate = DateTime.Now, Link = model.Link, Photo = Guid.NewGuid().ToString() + model.Photo.FileName }; string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", "products", product.Photo); using (FileStream stream = new FileStream(path, FileMode.Create)) { await model.Photo.CopyToAsync(stream); } await _context.Products.AddAsync(product); await _context.SaveChangesAsync(); return(RedirectToAction("List", "Product")); }
public string UpdateProduct(ProductM productModel) { DbHelper dbHelper = new DbHelper(); productModel = dbHelper.UpdateProduct(productModel); return("Success"); }
public bool fnIsExist(ProductM productM) { string sSql = " SELECT COUNT([product_id]) " + " FROM [MNDTproduct_master] " + " WHERE [product_id] = '" + productM.product_id + "' "; return(PublicApi.fnGetValue(sSql, "MNDT") == "1"); }
public ProductM GetByidProduct(int id) { Product product = serviceProduit.GetById(id); ProductM productm = new ProductM { IdProduct = product.IdProduct }; return(productm); }
public ProductM DeleteProduct(ProductM productModel, int id) { using (var dbEntities = new ProductContext()) { var productObj = dbEntities.ProductMs.SingleOrDefault(e => e.Id == id); dbEntities.ProductMs.Remove(productObj); dbEntities.SaveChanges(); productModel.Id = productObj.Id; } return(productModel); }
public ActionResult Edit(int id) { Product product = new Product(); ProductM productM = new ProductM(); product = Service.GetById(id); productM.description = product.description; productM.Nom = product.Nom; productM.marque = product.marque; productM.barcode = product.barcode; productM.price = product.price; productM.qte = product.qte; return(View(productM)); }
public DataTable fnSelect(ProductM productM) { string sSql = " SELECT TOP 1 [product_m].*, " + " ISNULL((SELECT Sum([product_d].[amount] * [material].[price]) " + " FROM [MNDTproduct_details] [product_d] " + " LEFT JOIN [MNDTmaterial] [material] " + " ON [product_d].[material_id] = " + " [material].[material_id] " + " WHERE [product_m].[product_id] = [product_d].[product_id]), 0) [suggest_cost] " + " FROM [MNDTproduct_master] [product_m] " + " WHERE [product_m].[product_id] = '" + productM.product_id + "' "; return(PublicApi.fnGetDt(sSql, "MNDT")); }
public ActionResult ProductAdd(ProductM tbl, HttpPostedFileBase file) { string img = null; if (file != null) { img = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/ProductImage/"), img); file.SaveAs(path); } tbl.ProductImage = img; tbl.CreatedDate = DateTime.Now; _UnitOfWork.GetRepositoryInstance <ProductM>().Add(tbl); return(RedirectToAction("Product")); }
public string fnCount(ProductM productM) { string sCondition = ""; sCondition += PublicApi.fnAddCondition("[product_id]", productM.product_id); sCondition += PublicApi.fnAddCondition("[company_id]", productM.company_id); sCondition += PublicApi.fnAddCondition("[name]", productM.name); string sCountSql = " SELECT COUNT([product_id]) " + " FROM [MNDTproduct_master] " + " WHERE 1 = 1 " + sCondition; string sPageSize = PublicApi.fnGetValue(sCountSql, "MNDT"); return(sPageSize); }
public ProductM CreateProduct(ProductM productModel) { using (var dbEntities = new ProductContext()) { var productObj = new ProductM() { //ID is auto generated. Name = productModel.Name, Price = productModel.Price }; dbEntities.ProductMs.Add(productObj); dbEntities.SaveChanges(); productModel.Id = productObj.Id; } return(productModel); }
public ProductM UpdateProduct(ProductM productModel) { using (var dbEntities = new ProductContext()) { var productObj = new ProductM() { //ID is auto generated. Id = productModel.Id, Name = productModel.Name, Price = productModel.Price }; dbEntities.Entry(productObj).State = System.Data.Entity.EntityState.Modified;; dbEntities.SaveChanges(); productModel.Id = productObj.Id; } return(productModel); }
// GET: Productt/Delete/5 public ActionResult Delete(int id) { Product product = new Product(); ProductM p = new ProductM(); product = Service.GetById((int)id); p.IdProduct = product.IdProduct; p.Nom = product.Nom; p.imageP = product.imageP; p.description = product.description; p.barcode = product.barcode; p.marque = product.marque; p.price = product.price; p.dateC = product.dateC; p.dateF = product.dateF; p.qte = product.qte; return(View(p)); }
public ActionResult Edit(int id, ProductM p) { Product product = new Product(); product = Service.GetById(id); product.description = p.description; product.Nom = p.Nom; product.marque = p.marque; product.barcode = p.barcode; product.price = p.price; product.qte = p.qte; Service.Update(product); Service.Commit(); return(RedirectToAction("index")); //return View(); }
// sNum 排行 public string fnSelectProductId(ProductM productM, string sNum) { string sCondition = ""; sCondition += PublicApi.fnAddCondition("[product_id]", productM.product_id); sCondition += PublicApi.fnAddCondition("[company_id]", productM.company_id); sCondition += PublicApi.fnAddCondition("[name]", productM.name); string sSql = " SELECT [product_m].[product_id] " + " FROM (SELECT Row_number() OVER (ORDER BY [" + productM.order + "] ASC) NUM, " + " * " + " FROM [MNDTproduct_master] " + " WHERE 1 = 1" + sCondition + ") AS [product_m] " + " WHERE [product_m].[NUM] = '" + sNum + "' "; return(PublicApi.fnGetValue(sSql, "MNDT")); }
public ActionResult EnvoyerMail(ProductM p) { //var x = es.GetById(id).mail; MailMessage mm = new MailMessage("*****@*****.**", "*****@*****.**"); mm.Subject = "we"; mm.Body = p.Nom; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; NetworkCredential nc = new NetworkCredential("*****@*****.**", " Password"); smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Send(mm); return(View()); }
public string fnDelete(ProductM productM, string sIP) { string sDetailsSql = " SELECT COUNT([product_id]) FROM [MNDTproduct_details] WHERE [product_id] = '" + productM.product_id + "' "; string sCount = PublicApi.fnGetValue(sDetailsSql, "MNDT"); if (sCount == "0") { string sSql = " DELETE [MNDTproduct_master] " + " WHERE [product_id] = '" + productM.product_id + "' "; ProductMTran productMTran = new ProductMTran(); productMTran.ProductId(productM.product_id) .IP(sIP) .Status("D") .CreateId(productM.create_id); sSql += fnInsertSql(productMTran); return(PublicApi.fnExecuteSQL(sSql, "MNDT")); } return("錯誤訊息:明細資料大於一筆。"); }
public string fnUpdate(ProductM productM, string sIP) { string sSql = " UPDATE [dbo].[MNDTproduct_master] " + " SET [company_id] = '" + productM.company_id + "' " + " ,[name] = '" + productM.name + "' " + " ,[unit] = '" + productM.unit + "' " + " ,[currency] = '" + productM.currency + "' " + " ,[cost] = '" + productM.cost + "' " + " ,[price] = '" + productM.price + "' " + " ,[shelf_life] = '" + productM.shelf_life + "' " + " ,[description] = '" + productM.description + "' " + " ,[status] = '" + productM.status + "' " + " WHERE [product_id] = '" + productM.product_id + "' "; ProductMTran productMTran = new ProductMTran(); productMTran.ProductId(productM.product_id) .IP(sIP) .Status("M") .CreateId(productM.create_id); sSql += fnInsertSql(productMTran); return(PublicApi.fnExecuteSQL(sSql, "MNDT")); }
public ProductM CreateProduct(ProductM ProductModel) { DbHelper dbInstance = new DbHelper(); return(dbInstance.CreateProduct(ProductModel)); }
public ActionResult Create(ProductM ProductM, HttpPostedFileBase Image, HttpPostedFileBase barCodeUpload) { string strin = string.Empty; string localSavePath = "~/Content/Uploads/"; string str = string.Empty; string strImage = string.Empty; string strBarCode = string.Empty; Product p = new Product() { IdProduct = ProductM.IdProduct, Nom = ProductM.Nom, imageP = Image.FileName, //imageP = ProductM.imageP, description = ProductM.description, barcode = barCodeUpload.FileName, marque = ProductM.marque, price = ProductM.price, dateC = ProductM.dateC, dateF = ProductM.dateF, IdRayon = ProductM.IdRayon, qte = ProductM.qte }; if (ProductM.dateC > DateTime.Today || ProductM.dateC == DateTime.Today) { strin = "the date of creation is not valid "; ViewBag.ErrorMessage = strin; } if (ProductM.dateF < DateTime.Today || ProductM.dateF == DateTime.Today) { strin = "the date of exp is not valid "; ViewBag.ErrorMessage = strin; } else { // Sauvgarde de l'image var path1 = Path.Combine(Server.MapPath("~/Content/Uploads/"), Image.FileName); Image.SaveAs(path1); var path = Path.Combine(Server.MapPath("~/Content/Uploads/"), barCodeUpload.FileName); barCodeUpload.SaveAs(path); strImage = "http://localhost:" + Request.Url.Port + "~/Content/Uploads/" + p.barcode; strBarCode = ReadBarCodeFromFile(path); if (strBarCode != "This is the right barcode #tunisia") { Response.Write("<script>alert('Data inserted successfully')</script>"); Service.Add(p); Service.Commit(); } else { Response.Write("<script>alert('Data not inserted! faileds ')</script>"); return(Content("<script language='javascript' type='text/javascript'>alert('100% tunisian product! #619');</script>")); } } ViewBag.ErrorMessage = str; ViewBag.BarCode = strBarCode; ViewBag.BarImage = strImage; return(RedirectToAction("Index")); }