public class MyController : Controller
{
//
// GET: /My/
MyDBEntities db = new MyDBEntities();
public ActionResult Index()
{
return View(db.Information.ToList());
}
//
// GET: /My/Details/5
public ActionResult Details(int id)
{
return View();
}
//
// GET: /My/Create
public ActionResult Create()
{
return View();
}
//
// POST: /My/Create
[HttpPost]
public ActionResult Create([Bind(Exclude = "Id")]Information info)
{
try
{
// TODO: Add insert logic here
db.AddToInformation(info);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /My/Edit/5
public ActionResult Edit(int id)
{
// var cc = db.Information.Select(x => x.Id == id).FirstOrDefault();
var cc = (from info in db.Information where info.Id == id select info).FirstOrDefault();
return View(cc);
}
//
// POST: /My/Edit/5
[HttpPost]
public ActionResult Edit( Information info)
{
try
{
// TODO: Add update logic here
db.Information.AddObject(info);
db.ObjectStateManager.ChangeObjectState(info, System.Data.EntityState.Modified);
// db.AcceptAllChanges();
db.SaveChanges();
return RedirectToAction("Index");
}
catch(Exception ex)
{
return View();
}
}
//
// GET: /My/Delete/5
public ActionResult Delete(int id)
{
var cc = (from info in db.Information where info.Id == id select info).FirstOrDefault();
return View(cc);
}
//
// POST: /My/Delete/5
[HttpPost]
public ActionResult Delete(Information info)
{
try
{
db.Information.AddObject(info);
db.ObjectStateManager.ChangeObjectState(info, System.Data.EntityState.Deleted);
// db.AcceptAllChanges();
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
A blog about web application development mainly on backend side
Subscribe to:
Post Comments (Atom)
What is DaemonSet in Kubernetes
A DaemonSet is a type of controller object that ensures that a specific pod runs on each node in the cluster. DaemonSets are useful for dep...
-
Cross-platform compatibility: MAUI allows developers to write code that can run on multiple platforms with minimal modifications. Shared cod...
-
Both .NET and NodeJS are popular programming frameworks that have their own strengths and weaknesses, which makes for an interesting compar...
-
A DaemonSet is a type of controller object that ensures that a specific pod runs on each node in the cluster. DaemonSets are useful for dep...
No comments:
Post a Comment