public bool CascadeRemoveShopOwner(Shop shop, Guid userGuid, Guid ownerToRemoveGuid) { var removedOwners = shop.CascadeRemoveShopOwner(userGuid, ownerToRemoveGuid); foreach (var removedOwner in removedOwners) { var newEvent = new RemovedOwnerEvent(removedOwner, ownerToRemoveGuid, shop.Guid); newEvent.SetMessages(_unitOfWork); UpdateCenter.RaiseEvent(newEvent); } _unitOfWork.ShopRepository.Update(shop); return(true); }
public bool CascadeRemoveShopOwner(UserIdentifier userIdentifier, Guid shopGuid, Guid ownerToRemoveGuid) { VerifySystemIsInitialized(); _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, shopGuid, ownerToRemoveGuid); var result = _userDomain.GetUserObject(userIdentifier).CascadeRemoveShopOwner(shopGuid, ownerToRemoveGuid); if (result) //Maybe change CascadeRemoveShopOwner in IUser to return a collection of all removed owners. { _logger.Log(LogLevel.Information, $"{GetUserName(userIdentifier.Guid)} removed" + $" {GetUserName(ownerToRemoveGuid)} as a shop owner from shop {GetShopName(shopGuid)} successfuly."); var newEvent = new RemovedOwnerEvent(ownerToRemoveGuid, userIdentifier.Guid, shopGuid); newEvent.SetMessages(_unitOfWork); UpdateCenter.RaiseEvent(newEvent); } else { _logger.Log(LogLevel.Information, $"{GetUserName(userIdentifier.Guid)} failed to remove" + $" {GetUserName(ownerToRemoveGuid)} as a shop owner from shop {GetShopName(shopGuid)}."); } return(result); }
public bool RemoveOwner(Shop shop, Guid toRemoveOwnerGuid) { var ownerToRemove = shop.GetOwner(toRemoveOwnerGuid); if (ownerToRemove.OwnerGuid.Equals(shop.Creator.OwnerGuid)) { return(false); } foreach (var otherOwner in shop.Owners) { if (otherOwner.AppointerGuid.Equals(toRemoveOwnerGuid)) { RemoveOwner(shop, otherOwner.OwnerGuid); var newEvent = new RemovedOwnerEvent(otherOwner.OwnerGuid, toRemoveOwnerGuid, shop.Guid); newEvent.SetMessages(_unitOfWork); UpdateCenter.RaiseEvent(newEvent); } } shop.Owners.Remove(ownerToRemove);// remove the owner from the owners list _unitOfWork.ShopRepository.Update(shop); return(true); }