public IEnumerable <PartManufacturer> GetAll() { var result = new List <PartManufacturer>(); using (_connection) { _connection.Open(); string sql = "select * from part_manufacturer"; SqlCommand cmd = new SqlCommand(sql, _connection); cmd.CommandType = CommandType.Text; var reader = cmd.ExecuteReader(); while (reader.Read()) { PartManufacturer partManufacturer = new PartManufacturer() { Id = (long)reader["id"], Name = (string)reader["name"], Active = (bool)reader["active"] }; result.Add(partManufacturer); } } return(result.AsEnumerable()); }
public PartManufacturer Create(string name) { using (_connection) { _connection.Open(); string sql = "insert into part_manufacturer (name) values (@name)"; SqlCommand cmd = new SqlCommand(sql, _connection); cmd.Parameters.AddWithValue("@name", name); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); sql = "select * from part_manufacturer where name = @name"; cmd = new SqlCommand(sql, _connection); cmd.Parameters.AddWithValue("@name", name); var reader = cmd.ExecuteReader(); if (reader.Read()) { PartManufacturer partManufacturer = new PartManufacturer() { Id = (long)reader["id"], Name = (string)reader["name"], Active = (bool)reader["active"] }; return(partManufacturer); } throw new Exception("Manufacturer with this name is already registered"); } }
public ActionResult DeleteConfirmed(int id) { PartManufacturer partManufacturer = db.PartManufacturers.Find(id); db.PartManufacturers.Remove(partManufacturer); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name,Code,CodeEsteem,CodeEsteemAlt")] PartManufacturer partManufacturer) { if (ModelState.IsValid) { partManufacturer.UpdatedDate = DateTime.Now; db.Entry(partManufacturer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(partManufacturer)); }
public ActionResult Create([Bind(Include = "Id,Name,Code,CodeEsteem,CodeEsteemAlt")] PartManufacturer partManufacturer) { partManufacturer.CreatedDate = DateTime.Now; if (ModelState.IsValid) { db.PartManufacturers.Add(partManufacturer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(partManufacturer)); }
// GET: PartManufacturers/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PartManufacturer partManufacturer = db.PartManufacturers.Find(id); if (partManufacturer == null) { return(HttpNotFound()); } return(View(partManufacturer)); }