using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Pharmacy.Models;
namespace Pharmacy.Controllers
{
public class HomeController : Controller { private MedicineEntities _datamodel = new MedicineEntities(); public ActionResult Index() { return View(_datamodel.MDs.ToList()); }
// // GET: /Home/Details/5
public ActionResult Details(int id) { var prod = _datamodel.MDs.Where(item => item.id == id).First(); return View(prod); }
// // GET: /Home/Create
public ActionResult Create() { return View(); }
// // POST: /Home/Create
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude = "ID")] MD productToCreate) { if (!ModelState.IsValid) return View(); try { _datamodel.AddToMDs(productToCreate); _datamodel.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } } // // GET: /Home/Edit/5 public ActionResult Edit(int id) { return View(_datamodel.MDs.FirstOrDefault(item => item.id == id)); }
// // POST: /Home/Edit/5
[HttpPost] public ActionResult Edit(MD productToCreate) { try { var prod = _datamodel.MDs.Where(item => item.id == productToCreate.id).First(); prod.medicine_name = productToCreate.medicine_name; prod.description = productToCreate.description; prod.quantity =