public string ProductSearchAjax(int ProductID) { Producttbl P = context.Producttbl.FirstOrDefault <Producttbl>(m => m.Id == ProductID); string data = ""; data += "<table class='table table-striped'>"; data += "<tr>"; data += "<td>"; data += P.Id; data += "</td>"; data += "<td>"; data += P.ProductName; data += "</td>"; data += "<td>"; data += P.ProductDescription; data += "</td>"; data += "<td>"; data += P.ProductPrice; data += "</td>"; data += "<td>"; data += "<img src=/UploadedData/pps/" + P.PrductImage + " style='width: 40%; height:100px' class='img-'/>"; data += "</td>"; data += "</tr>"; data += "</table>"; return(data); }
public string DeleteProduct(int ProductID) { Producttbl S = new Producttbl(); S.Id = ProductID; try { context.Producttbl.Remove(S); context.SaveChanges(); return("DONE"); } catch (Exception ex) { } //for http requests only //return RedirectToAction("AllStudents"); return("ERROR"); }
public IActionResult AddProduct(Producttbl P) { foreach (var file in Request.Form.Files) { var name = file.Name; var ext = System.IO.Path.GetExtension(file.FileName); var filename = DateTime.Now.ToString("ddMMyyyyhhmmss") + ext; FileStream fs = new FileStream(env.WebRootPath + "/UploadedData/pps/" + filename, FileMode.Create); file.CopyTo(fs); fs.Close(); P.PrductImage = filename; } P.CreatedDate = DateTime.Today; P.ModifiedDate = DateTime.Today; context.Producttbl.Add(P); context.SaveChanges(); return(RedirectToAction("AddProduct")); }