PhotoEntity.Controllers.Manager.PropertyDelete C# (CSharp) Method

PropertyDelete() public method

public PropertyDelete ( int id ) : bool
id int
return bool
        public bool PropertyDelete(int id)
        {
            // Attempt to fetch the object to be deleted
            var itemToDelete = ds.Properties.Find(id);

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

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }

Usage Example

コード例 #1
0
        public ActionResult Delete(int?id, FormCollection collection)
        {
            var wasDeleted = m.PropertyDelete(id.GetValueOrDefault());

            // "wasDeleted" 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(Redirect("~/properties/index"));
        }