AssocAddEdit.Controllers.Manager.VehicleDelete C# (CSharp) Метод

VehicleDelete() публичный Метод

public VehicleDelete ( int id ) : bool
id int
Результат bool
        public bool VehicleDelete(int id)
        {
            // Attempt to fetch the object to be deleted
            var itemToDelete = ds.Vehicles.Find(id);

            if (itemToDelete == null)
            {
                return false;
            }
            else
            {
                // Remove the object
                ds.Vehicles.Remove(itemToDelete);
                ds.SaveChanges();

                return true;
            }
        }

Usage Example

        public ActionResult Delete(int?id, FormCollection collection)
        {
            var result = m.VehicleDelete(id.GetValueOrDefault());

            // "result" will be true or false
            // We probably won't do much with the result, because
            // we don't want to leak info about the delete attempt

            // In the end, we should just redirect to the list view
            return(RedirectToAction("index"));
        }