Esempio n. 1
0
        public void CloseShopPermanently(UserIdentifier userIdentifier, Guid shopGuid)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, shopGuid);
            _userDomain.GetUserObject(userIdentifier).CloseShopPermanently(shopGuid);
            var newEvent = new ClosedShopPermanentlyEvent(userIdentifier.Guid, shopGuid);

            newEvent.SetMessages(_unitOfWork);
            _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} closed shop {GetShopName(shopGuid)} permanently successfuly.");
            UpdateCenter.RaiseEvent(newEvent);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public Guid OpenShop(UserIdentifier userIdentifier)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier);
            var shopGuid = _userDomain.GetUserObject(userIdentifier).OpenShop();

            if (!shopGuid.Equals(Guid.Empty))
            {
                var newEvent = new OpenedShopEvent(userIdentifier.Guid, shopGuid);
                newEvent.SetMessages(_unitOfWork);
                _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} opened shop successfuly.");
                UpdateCenter.RaiseEvent(newEvent);
            }
            return(shopGuid);
        }
Esempio n. 4
0
        public Guid Login(UserIdentifier userIdentifier, string username, string password)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, username, password);
            var result = _userDomain.Login(username, password);

            if (!result.Equals(Guid.Empty))
            {
                var newEvent = new UserLoggedInEvent(result);
                //newEvent.SetTargets(DomainData.ShopsCollection.Values, DomainData.RegisteredUsersCollection.Values);
                //newEvent.SetMessage(DomainData.ShopsCollection.Values, DomainData.RegisteredUsersCollection.Values);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
                _logger.LogInformation($"{username} logged in successfuly.");
            }
            return(result);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public bool AddShopOwner(UserIdentifier userIdentifier, Guid shopGuid, Guid newShopOwnerGuid)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, shopGuid, newShopOwnerGuid);
            bool result = _userDomain.GetUserObject(userIdentifier).AddShopOwner(shopGuid, newShopOwnerGuid);

            if (result)
            {
                _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} added {GetUserName(newShopOwnerGuid)} " +
                                       $" as a new owner of shop {GetShopName(shopGuid)}");
                var newEvent = new AddedOwnerEvent(newShopOwnerGuid, userIdentifier.Guid, shopGuid);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
            }
            else
            {
                _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} failed to add {GetUserName(newShopOwnerGuid)}" +
                                       $" as a new owner of shop {GetShopName(shopGuid)}.");
            }
            return(result);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public bool PurchaseCart(Shop shop, ShoppingBag bag)
        {
            var  cart            = bag.GetShoppingCartAndCreateIfNeededForGuestOnlyOrInBagDomain(shop.Guid);
            bool canPurchaseCart = true;

            foreach (var productAndAmountBought in cart.PurchasedProducts)
            {
                var      userGuid = cart.UserGuid;
                BaseUser user;
                try
                {
                    user = _unitOfWork.BaseUserRepository.FindByIdOrNull(userGuid);
                }
                catch (Exception)
                {
                    user = null;
                }
                //check purchase policies
                var quantity = productAndAmountBought.Item2;
                foreach (IPurchasePolicy policy in shop.PurchasePolicies)
                {
                    if (!policy.CheckPolicy(cart, productAndAmountBought.Item1.Guid, quantity, user, _unitOfWork) && !policyInCompound(shop, policy))
                    {
                        canPurchaseCart = false;
                    }
                }
            }
            if (!canPurchaseCart)
            {
                //_unitOfWork.ShopRepository.Update(shop);
                //_unitOfWork.BagRepository.Update(bag);
                return(false);
            }

            foreach (var productAndAmountBought in cart.PurchasedProducts)
            {
                var userGuid = cart.UserGuid;

                var actualProduct = shop.ShopProducts.FirstOrDefault(p => p.Guid.Equals(productAndAmountBought.Item1.Guid));
                //decrease stock quantity if it wasnt a discount record

                var quantity = productAndAmountBought.Item2;
                if (actualProduct != null)
                {
                    shop.UsersPurchaseHistory.Add(new Tuple <Guid, ShopProduct, int>(userGuid, actualProduct, quantity));
                    actualProduct.Quantity -= quantity;
                }
                else
                {
                    shop.UsersPurchaseHistory.Add(new Tuple <Guid, ShopProduct, int>(userGuid, productAndAmountBought.Item1, quantity));
                }
            }
            double total_price = cart.PurchasedProducts.Aggregate(0d, (total, p) => total += Convert.ToDouble(p.Item1.Price) * p.Item2);
            var    newEvent    = new PurchasedCartEvent(cart.UserGuid, cart.ShopGuid, total_price);

            newEvent.SetMessages(_unitOfWork);
            UpdateCenter.RaiseEvent(newEvent);
            ShoppingBagDomain.PurchaseCart(bag, shop.Guid);
            _unitOfWork.ShopRepository.Update(shop);
            return(true);
        }