public ActionResult Create([Bind(Include = "RecordID,PatientID,Date,Bought_Medicine,Buying_Reason,Comment")] Record record) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); db.Records.Add(record); db.SaveChanges(); string connectionString = "Integrated Security=SSPI;Initial Catalog=MVCThree;Data Source=HISOKA"; SqlConnection sql; sql = new SqlConnection(connectionString); sql.Open(); using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand("", connection)) { connection.Open(); command.CommandText = "update Record set PatientID = @Name, Date=GETDATE() where RecordID = (select MAX(RecordID) from Record)"; command.Parameters.AddWithValue("@Name", userId); command.ExecuteNonQuery(); connection.Close(); } sql.Close(); return(RedirectToAction("Index")); } return(View(record)); }
public ActionResult Create([Bind(Include = "WishID,WishMedName,RequestAmount,Comment,RequesterID")] Wishlist wishlist) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); db.Wishlists.Add(wishlist); db.SaveChanges(); string connectionString = "Integrated Security=SSPI;Initial Catalog=MVCThree;Data Source=HISOKA"; SqlConnection sql; sql = new SqlConnection(connectionString); sql.Open(); using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand("", connection)) { connection.Open(); command.CommandText = "update Wishlist set RequesterID = @Name where WishID = (select MAX(WishID) from Wishlist)"; command.Parameters.AddWithValue("@Name", userId); command.ExecuteNonQuery(); connection.Close(); } sql.Close(); return(RedirectToAction("Index")); } return(View(wishlist)); }
public ActionResult Edit([Bind(Include = "MedID,MedName,Quantity,Price,SupplierID")] Instock_Medicine instock_Medicine) { if (ModelState.IsValid) { db.Entry(instock_Medicine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(instock_Medicine)); }
public ActionResult Create([Bind(Include = "SupID,SupName,SupAddress,SupPhone,MedicineID")] Supplier supplier) { if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public ActionResult Create([Bind(Include = "SupID,SupName,SupAddress,SupPhone,MedicineID")] Supplier supplier) { if (!db.Instock_Medicine.Any(c => c.MedID == supplier.MedicineID)) { ModelState.AddModelError("CustomerId", "Medicine ID not found."); } if (ModelState.IsValid) { db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
//[HttpPost] //public ActionResult Index(HttpPostedFileBase postedFile) //{ // byte[] bytes; // using (BinaryReader br = new BinaryReader(postedFile.InputStream)) // { // bytes = br.ReadBytes(postedFile.ContentLength); // } // MVCThreeEntities entities = new MVCThreeEntities(); // entities.Instock_Medicine.Add(new Instock_Medicine // { // Med_Img = bytes // }); // entities.SaveChanges(); // return RedirectToAction("Index"); //} // more details see http://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Create([Bind(Include = "MedID,MedName,Quantity,Price,SupplierID,Description,")] Instock_Medicine instock_Medicine, HttpPostedFileBase File1, HttpPostedFileBase File2) //{ // if (ModelState.IsValid) // { // //if (File1 != null && File1.ContentLength > 0 && File2 != null) // //{ // instock_Medicine.Med_Img = new byte[File1.ContentLength]; // File1.InputStream.Read(instock_Medicine.Med_Img, 0, File1.ContentLength); // string ImageName = System.IO.Path.GetFileName(File2.FileName); // string physicalPath = Server.MapPath("~/img/" + ImageName); // File2.SaveAs(physicalPath); // instock_Medicine.Img_Path="img/" + ImageName; // db.Instock_Medicine.Add(instock_Medicine); // db.SaveChanges(); // return RedirectToAction("Index"); // //byte[] bytes; // //using (BinaryReader br = new BinaryReader(postedFile.InputStream)) // //{ // // bytes = br.ReadBytes(postedFile.ContentLength); // //} // //MVCThreeEntities entities = new MVCThreeEntities(); // //entities.Instock_Medicine.Add(new Instock_Medicine { // // Med_Img = bytes }); // // entities.SaveChanges(); // //string connectionString = "Integrated Security=SSPI;Initial Catalog=MVCThree;Data Source=HISOKA"; // //SqlConnection sql; // //sql = new SqlConnection(connectionString); // //sql.Open(); // //using (SqlConnection connection = new SqlConnection(connectionString)) // //using (SqlCommand command = new SqlCommand("", connection)) // //{ // // connection.Open(); // // command.CommandText = "update Instock_Medicine set Med_Img = @Name where MedID = (select MAX(MedID) from Instock_Medicine)"; // // command.Parameters.AddWithValue("@Name", bytes); // // command.ExecuteNonQuery(); // // connection.Close(); // //} // //sql.Close(); // //} // } // return View(instock_Medicine); //}] public ActionResult FileUpload(HttpPostedFileBase file) { if (file != null) { MVCThreeEntities db = new MVCThreeEntities(); string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Content/" + ImageName); file.SaveAs(physicalPath); Instock_Medicine med = new Instock_Medicine(); //med.MedID = int.Parse(Request.Form["MedID"]); med.Med_Img = new byte[file.ContentLength]; file.InputStream.Read(med.Med_Img, 0, file.ContentLength); med.MedName = Request.Form["MedName"]; med.Quantity = int.Parse(Request.Form["Quantity"]); med.Price = int.Parse(Request.Form["Price"]); med.SupplierID = int.Parse(Request.Form["SupplierID"]); med.Description = Request.Form["Description"]; med.Img_Path = ImageName; db.Instock_Medicine.Add(med); db.SaveChanges(); string connectionString = "Integrated Security=SSPI;Initial Catalog=MVCThree;Data Source=HISOKA"; SqlConnection sql; sql = new SqlConnection(connectionString); sql.Open(); using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand("", connection)) { connection.Open(); command.CommandText = "update Instock_Medicine set Instock_Date = GetDate() where MedID = (select MAX(MedID) from Instock_Medicine)"; command.ExecuteNonQuery(); connection.Close(); } sql.Close(); } return(RedirectToAction("Index")); }