sep24migrations.ViewModels.Repo_Subject.DeleteExisting C# (CSharp) Method

DeleteExisting() public method

Delete existing
public DeleteExisting ( int id ) : void
id int Identifier
return void
        public void DeleteExisting(int id)
        {
            // Fetch the existing Program object
            var s = ds.Subjects.Find(id);

            if (s == null)
            {
                // Throw an exception, in 'version 2' of error and exception handling
            }
            else
            {
                try
                {
                    // If this fails, throw an exception, in 'version 2'...
                    // It may fail because of the presence of associated objects
                    // This implementation prevents the exception from bubbling up
                    ds.Subjects.Remove(s);
                    ds.SaveChanges();
                }
                catch (Exception) { }
            }
        }