/// <summary> /// Create location /// </summary> /// <param name="message"></param> /// <param name="origin">Item that initiated request</param> /// <param name="mm">Module manager</param> /// <param name="response"></param> public IResponse HandleDeleteLocationRequest( IMessage message, Item origin, IModuleManager mm, IResponse response) { var request = message.GetMessageAsType <WorldDeleteLocationRequest>(); response = HandleRequestWrapper <WorldDeleteLocationResponse>(request, res => { var itemManager = mm.GetManager <IItemManager>(); var location = itemManager.Read(request.LocationItemId); var exits = mm.GetManager <IExitItemDataManager>() .GetLocationExits(location.Id); itemManager.Delete(exits, true); location = itemManager.Read(request.LocationItemId); itemManager.Delete(new List <Item>() { location }); var deletedItems = exits ?? new List <Item>(); deletedItems.Add(location); var deleteItemEvent = new CoreDeleteItemCrudEvent() { Items = deletedItems }; ((WorldDeleteLocationResponse)response).DeleteItemEvent = deleteItemEvent; ((WorldDeleteLocationResponse)response)._responseSuccess = true; res.SetSuccess(true); }); return(response); }
/// <summary> /// Permenantly delete an item and remove from data store /// </summary> /// <remarks> /// All children will be re-homed to the item parent unless otherwise specified /// </remarks> /// <param name="items">List of items to delete</param> /// <param name="deleteChildren">Also delete all children</param> public void Delete(List <Item> items, bool?deleteChildren = false) { var messageManager = ModuleManager.GetManager <IMessageManager>(); // Move item children items.ForEach((item) => { if (deleteChildren == false) { var oldParent = item.Parent; if (oldParent != null) { item.Children?.ForEach((child) => { Move(child, oldParent, item); }); } // Blank out the children, otherwise ef will try and delete item.Children = new List <Item>(); } var deleteItemEvent = new CoreDeleteItemCrudEvent() { Items = new List <Item>() { item } }; var parentItem = Read(item.ParentId.Value); messageManager.SendMessage(new List <IMessage>() { deleteItemEvent }, new List <Item>() { parentItem }); messageManager.SendMessageToSiblings(new List <IMessage>() { deleteItemEvent }, item); }); ItemRepo.Delete(items); }
/// <summary> /// Handle a message /// </summary> /// <param name="message"></param> /// <param name="origin">Item that initiated request</param> /// <param name="mm">Module manager</param> /// <param name="response"></param> private IResponse HandleCoreDeleteItemCrudRequest( IMessage message, Item origin, IModuleManager mm, IResponse response) { var request = message.GetMessageAsType <CoreDeleteItemCrudRequest>(); response = HandleRequestWrapper <CoreDeleteItemCrudResponse>(request, res => { var items = mm.GetManager <IItemManager>().Read(request.ItemIds); mm.GetManager <IItemManager>().Delete(items, true); var deleteItemEvent = new CoreDeleteItemCrudEvent() { Items = items }; ((CoreDeleteItemCrudResponse)res).CoreDeleteItemCrudEvent = deleteItemEvent; res.SetSuccess(true); }); return(response); }