public ActionResult DeleteConfirmed(int id) { TypeOfToy typeOfToy = db.ToysType.Find(id); db.ToysType.Remove(typeOfToy); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(TypeOfToy typeOfToy) { if (ModelState.IsValid) { db.Entry(typeOfToy).State = EntityState.Modified;//if the typeOfToy is the same //that we are searching it will update the data base //one col not expensive db.SaveChanges(); return(RedirectToAction("Index")); } return(View(typeOfToy)); }
// GET: TypeOfToys/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TypeOfToy typeOfToy = db.ToysType.Find(id); if (typeOfToy == null) { return(HttpNotFound()); } return(View(typeOfToy)); }
public void DeleteType(string deleteTypeName) { try { TypeOfToy deleteType = context.TypeOfToys.Single(s => s.TypeName == deleteTypeName); context.TypeOfToys.Remove(deleteType); context.SaveChanges(); Console.WriteLine($"Type {deleteTypeName} is deelted successfully.."); } catch (Exception) { Console.WriteLine($"Type doesn't exists..."); } }
[ValidateAntiForgeryToken] //we used it in the view public ActionResult Create(TypeOfToy typeOfToy) //([Bind(Include = "TypeOfToyID,Name")]TypeOfToy typeOfToy) { // ModelState- once we add all the required -- //-- attributs from the modle then it will be valid if (ModelState.IsValid) { db.ToysType.Add(typeOfToy); // Add the toy to the db db.SaveChanges(); return(RedirectToAction("Index")); // We wants to desplay the index -- //-- view wite the new toy that was added } return(View(typeOfToy)); }
// GET: TypeOfToys/Details/5 //general id public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TypeOfToy typeOfToy = db.ToysType.Find(id);// find me a toytype where id is //equal to what we are passing if (typeOfToy == null) { return(HttpNotFound()); } return(View(typeOfToy)); }
public void AddType(string AddTypeName) { try { context.TypeOfToys.Single(s => s.TypeName == AddTypeName); Console.WriteLine("Type is already exists..."); } catch (Exception) { TypeOfToy addType = new TypeOfToy() { TypeName = AddTypeName }; context.TypeOfToys.Add(addType); context.SaveChanges(); TypeOfToy AddedType = context.TypeOfToys.ToList().Last(); Console.WriteLine($"New type of toy is {AddedType.TypeName} and id is {AddedType.TypeId}"); } }
public void UpdateType(string UpdateTypeName) { try { TypeOfToy updateType = context.TypeOfToys.Single(s => s.TypeName == UpdateTypeName); Console.WriteLine($"Enter type name to update it :"); string UpdateNameType = Console.ReadLine(); try { context.TypeOfToys.Single(s => s.TypeName == UpdateNameType); Console.WriteLine("Type name is already exists..."); } catch (Exception) { updateType.TypeName = UpdateNameType; context.SaveChanges(); Console.WriteLine($"The type {UpdateTypeName} is updated with {UpdateNameType}"); } } catch (Exception) { Console.WriteLine($"Type {UpdateTypeName} doesn't exists..."); } }
public ActionResult groupBy(TypeOfToy type) { var toys = db.Toys.GroupBy(toy => toy.TypeOfToyID.Equals(type.TypeOfToyID)); return(View(toys.ToList())); }