Example #1
0
        public bool AddOwner(Shop shop, Guid appointerGuid, Guid newOwnerGuid)
        {
            var result = false;
            int signatures_required = shop.Owners.Count() + 1;     //+1 for the shop creator

            if (shop.candidate == null && signatures_required > 1) // a new candidate
            {
                var newCandidate = new OwnerCandidate(newOwnerGuid, shop.Guid, appointerGuid, signatures_required, _unitOfWork.BaseUserRepository.GetUsername(appointerGuid));
                shop.candidate = newCandidate;
            }
            else if (shop.candidate != null) // there is a candidate, sign it if possible
            {
                var candidate = shop.candidate;
                if (candidate.signature_target - candidate.Signatures.Count() == 1) // last sign , promote the candidate to a shop owner
                {
                    var newOwner = new ShopOwner(newOwnerGuid, candidate.AppointerGuid, shop.Guid);
                    shop.Owners.Add(newOwner);
                    shop.candidate = null;
                }
                else if (!candidate.Signatures.Values.Contains(appointerGuid)) //if not already signed , sign the candidate
                {
                    candidate.Signatures.Add(_unitOfWork.BaseUserRepository.GetUsername(appointerGuid), appointerGuid);
                }
            }
            else// in the case: adding the second shopowner
            {
                var newOwner = new ShopOwner(newOwnerGuid, appointerGuid, shop.Guid);
                shop.Owners.Add(newOwner);
            }
            result = true;
            _unitOfWork.ShopRepository.Update(shop);
            return(result);
        }
Example #2
0
        public void AddShopOwner(Shop shop, Guid userGuid, Guid newOwnerGuid, string appointerUsername)
        {
            int signatures_required = shop.Owners.Count() + 1;     //+1 For Creator

            if (shop.candidate == null && signatures_required > 1) // a new candidate
            {
                var newCandidate = new OwnerCandidate(newOwnerGuid, shop.Guid, userGuid, signatures_required, appointerUsername);
                shop.candidate = newCandidate;
            }
            else if (shop.candidate != null) // there is a candidate, sign it if possible
            {
                var candidate = shop.candidate;
                if (candidate.signature_target - candidate.Signatures.Count() == 1) // last sign , promote the candidate to a shop owner
                {
                    var newOwner = new ShopOwner(newOwnerGuid, candidate.AppointerGuid, shop.Guid);
                    shop.Owners.Add(newOwner);
                    shop.candidate = null;
                }
                else if (!candidate.Signatures.Values.Contains(userGuid)) //if not already signed , sign the candidate
                {
                    candidate.Signatures.Add(appointerUsername, userGuid);
                }
            }
            else// in the case: adding the second shopowner
            {
                var newOwner = new ShopOwner(newOwnerGuid, userGuid, shop.Guid);
                shop.Owners.Add(newOwner);
            }

            _unitOfWork.ShopRepository.Update(shop);
        }
Example #3
0
 private static void VerifyOwnerCandidate(OwnerCandidate expected, OwnerCandidate actual)
 {
     Assert.AreEqual(expected.AppointerGuid, actual.AppointerGuid);
     Assert.AreEqual(expected.OwnerGuid, actual.OwnerGuid);
     Assert.AreEqual(expected.ShopGuid, actual.ShopGuid);
     CollectionAssert.AreEquivalent(expected.Signatures, actual.Signatures);
     Assert.AreEqual(expected.signature_target, actual.signature_target);
 }
Example #4
0
        public static Shop SaveShopOwnerCandidate()
        {
            var shop      = SaveShopWithName();
            var candidate = new OwnerCandidate(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), 2, "sa");

            shop.candidate = candidate;
            candidate.Signatures.Add("hi", Guid.NewGuid());
            return(shop);
        }