public OperationResult <int> DeleteContact(int id) { var result = new OperationResult <int>(); result.Data = table.Delete(key: id); return(result); }
public bool Delete(Entity entity, string key, IList <PropertyDeleteViewModel> propertiesDeleteOptions) { var deleteOptions = propertiesDeleteOptions.ToDictionary(x => x.PropertyName, x => x.DeleteOption); foreach (var property in entity.Properties.Where(x => x.IsForeignKey && x.IsCollection)) { if (!deleteOptions.ContainsKey(property.ForeignEntity.Name)) { deleteOptions[property.ForeignEntity.Name] = property.DeleteOption; } } var table = new DynamicModel(AdminInitialise.ConnectionString, tableName: entity.TableName, primaryKeyField: entity.Key.ColumnName); var keyObject = GetKeyObject(entity, key); var result = 0; if (deleteOptions.All(x => x.Value == DeleteOption.Nothing)) { result = table.Delete(keyObject); } else { var sql = String.Empty; var recordHierarchy = GetRecordHierarchy(entity); foreach (var subRecord in recordHierarchy.SubRecordsHierarchies) { var deleteOption = DeleteOption.Nothing; if (deleteOptions.ContainsKey(subRecord.Entity.Name)) { deleteOption = deleteOptions[subRecord.Entity.Name]; } if (deleteOption == DeleteOption.SetNull) { sql += GetSetToNullUpdateSql(entity, subRecord) + Environment.NewLine; } else if (deleteOption == DeleteOption.CascadeDelete) { sql += string.Join(Environment.NewLine, GetDeleteRelatedEntityDeleteSql(subRecord).Reverse()) + Environment.NewLine; } } var cmd = table.CreateDeleteCommand(key: keyObject); cmd.CommandText = sql + cmd.CommandText; result = table.Execute(cmd); } if (result < 1) { Error(IlaroAdminResources.EntityNotExist); return(false); } AddEntityChange(entity.Name, key, EntityChangeType.Delete); return(true); }
public void Remove(int id) { var invoicesDetail = new DynamicModel("invoicesDB", "invoiceDetail", "id"); invoicesDetail.Delete(where : "WHERE idInvoice=@0", args: id); var invoices = new DynamicModel("invoicesDB", "invoice", "id"); invoices.Delete(id); }
public string Delete(string id) { try { tbl.Delete(id); } catch { TempData["Error"] = "There was a problem deleting this record"; } return("true"); }
public ActionResult Delete(int id) { comments.Delete(key: id); return(RedirectToAction("Index")); }
public void RemoveDetail(int id) { var invoicesDetail = new DynamicModel("invoicesDB", "invoiceDetail", "id"); invoicesDetail.Delete(id); }