Beispiel #1
0
        public static void login(string Email, string password)
        {
            MileStone4.AlmogException unicorn = new MileStone4.AlmogException();
            unicorn.Value = new List <String>(); // Collection of messages

            if (!(CheckPassword(password)))      // password cheack
            {
                ((List <String>)unicorn.Value).Add("Password isn't valid");
            }
            try
            {
                CheckEmailValid(Email);
            }
            catch (MileStone4.AlmogException e)
            {
                for (int i = 0; i < ((List <String>)e.Value).Count; i++) // add message
                {
                    ((List <String>)unicorn.Value).Add(((List <String>)e.Value)[i]);
                }
            }
            if (((List <String>)unicorn.Value).Count == 0 || (((List <String>)unicorn.Value).Count == 1 && ((List <String>)unicorn.Value).Contains("Email's ending isn't valid")))
            {
                logged = aUser.login(Email, password); // create user if nothing disturbing
            }
            else if (((List <String>)unicorn.Value).Count != 0)
            {
                throw unicorn;
            }
        }
 public override bool isValid(ICollection <Product> products, aUser user)
 {
     foreach (Product item in products)
     {
         if (this.isRelevant(item))
         {
             return(predicate(item, user));
         }
     }
     return(this.Default);
 }
Beispiel #3
0
 public override bool isValid(ICollection <Product> products, aUser user)
 {
     foreach (iPolicy policy in this.policies)
     {
         if (policy.isValid(products, user))
         {
             return(true);
         }
     }
     // non of the policies is valid
     return(false);
 }
Beispiel #4
0
        public bool hasRequestPermission(aUser user)
        {
            foreach (aUser owner in this.owners)
            {
                if (owner.userName.Equals(user.userName))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
        public OfferRequest(Product product, aUser requester, Store store)
        {
            // increment id
            lock (idLocker)
            {
                currentId++;
                this.id = currentId;
            }

            this.product   = product;
            this.requester = requester;
            this.store     = store;
            this.status    = Status.NULL;
        }
        public bool isUserExist(string username, string password)
        {
            aUser user = UserServices.getUser(username);

            if (user == null)
            {
                return(false);
            }
            if (user is Guest)
            {
                return(false);
            }
            return(((Member)user).password.Equals(password));
        }
Beispiel #7
0
        public bool reject(aUser rejector)
        {
            if (this.status != Status.PENDING_STORE | !userHasPermission(rejector))
            {
                return(false);
            }

            lock (responseLocker)
            {
                this.status = Status.REJECTED;
                // send a notification to the user
                notifyUser();
            }
            return(true);
        }
Beispiel #8
0
        public bool accept(aUser acceptor)
        {
            if (this.status != Status.PENDING_STORE | !userHasPermission(acceptor))
            {
                return(false);
            }
            this.store.acceptOffer(acceptor, this.id);

            if (store.isOfferAccepted(this.id))
            {
                this.status = Status.ACCEPTED;
            }

            notifyUser();
            return(true);
        }
Beispiel #9
0
        public bool negotiate(double price, aUser negotiator) // used by managers/owners
        {
            if (this.status != Status.PENDING_STORE | !userHasPermission(negotiator))
            {
                return(false);
            }

            lock (responseLocker)
            {
                editPrice(price, negotiator);
                this.status = Status.ACCEPTED;

                notifyUser();
            }
            return(true);
        }
Beispiel #10
0
        public string[] executeOfferPurchase(aUser user, Product product, string creditNumber, string validity, string cvv)
        {  // lock the store for purchase
            Receipt receipt;

            lock (this.purchaseLock)
            {
                string policy = checkPolicies(product);
                if (policy.Length != 0)
                {
                    return new string[] { "false", policy }
                }
                ;
                if (!checkAmounts(new LinkedList <Product>(new Product[] { product })))
                {
                    return new string[] { "false", "not enough items in stock" }
                }
                ;
                if (!PaymentSystem.VerificationSystem.paymentSystem.Pay(user.userName, creditNumber, validity, cvv))
                {
                    return new string[] { "false", "payment not approved" }
                }
                ;
                if (!SupplySystem.SupplySystem.supplySystem.OrderPackage(name, user.userName, user.getAddress(), ProductToString(product)))
                {
                    return new string[] { "false", "supply not approved" }
                }
                ;

                // create a temp basket for purchase
                ShoppingBasket basket = new ShoppingBasket(this, user);
                basket.products.Add(product);

                receipt = validPurchase(basket);
                if (!basket.owner.userName.Equals("guest"))
                {
                    receipt.save();
                }

                user.addReceipt(receipt);

                // update the origin store
                Stores.stores[this.name].inventory = this.inventory;
                Stores.stores[this.name].receipts  = this.receipts;
            }

            return(new string[] { "true", "" + receipt.receiptId });;
        }
 public static bool logout()
 {
     if (!user.getUserName().Equals("guest") && UserServices.onlineUsers.Contains(user.getUserName()))
     {
         //       DirAppend.AddToLogger("user " + user.getUserName() + " logout", Result.Log);
         //       DirAppend.AddToLogger("user " + user.getUserName() + " logout", Result.Log);
         if (UserServices.logout(user.getUserName()))
         {
             aUser olduser = user;
             user     = new Guest();
             userName = user.getUserName();
             return(true);
         }
     }
     //    DirAppend.AddToLogger("There was a failed login attempt", Result.Warnning);
     return(false);
 }
Beispiel #12
0
        public override bool isValid(ICollection <Product> products, aUser user)
        {
            if (this.policies.Count == 0)
            {
                return(this.Default);
            }

            foreach (Product item in products)
            {
                if (this.isRelevant(item))
                {
                    return(this.policies[0].isValid(products, user));
                }
            }

            return(this.Default);
        }
Beispiel #13
0
        public ShoppingBasket(BasketInRecipt shoppingBasketData)
        {
            this.products = new LinkedList <Product>();
            ICollection <ProductData> productsInBasketData = shoppingBasketData.products;

            foreach (ProductData p_data in productsInBasketData)
            {
                this.products.Add(new Product(p_data));
            }
            ThreadStart linkStore = new ThreadStart(() => this.store = Stores.searchStore(shoppingBasketData.recipt.store.storeName));
            ThreadStart linkOwner = new ThreadStart(() => this.owner = UserServices.getUser(shoppingBasketData.recipt.user.userName));

            //  this.store = new Store(shoppingBasketData.recipt.store);
            // this.owner = new Member(shoppingBasketData.recipt.user);
            Build.addLink(linkStore);
            Build.addLink(linkOwner);
        }
        public static string[] login(string username, string password)
        {
            //     DirAppend.AddToLogger("user " + username + " login", Result.Log);

            string[] ans = BuissnessLayer.UserServices.login(username, password);
            if (ans[0].Equals("false"))
            {
                //UserServices.getAdmin().addAlarm("login failed", ans[1]);
                return(ans);
            }

            aUser olduser = user;

            user     = BuissnessLayer.UserServices.getUser(username);
            userName = user.getUserName();

            return(ans);
        }
Beispiel #15
0
        public void acceptOffer(aUser acceptor, int offerID)
        {
            if (!this.requestsAcceptors.ContainsKey(offerID))
            {
                this.requestsAcceptors.Add(offerID, new LinkedList <aUser>());
            }

            if (this.requestsAcceptors[offerID] == null)
            {
                this.requestsAcceptors[offerID] = new LinkedList <aUser>();
            }

            // check if the user has accepted the request before
            foreach (aUser owner in this.requestsAcceptors[offerID])
            {
                if (owner.userName.Equals(acceptor.userName))
                {
                    return;
                }
            }

            this.requestsAcceptors[offerID].Add(acceptor);
        }
Beispiel #16
0
 public bool editPrice(double price, aUser editor)
 {
     if (price < 0)
     {
         return(false);
     }
     // if the user is waiting for the store to response then he/she can't edit the price
     if (this.status == Status.PENDING_STORE && !userHasPermission(editor))
     {
         return(false);
     }
     lock (this.responseLocker)
     {
         this.product.price = price;
         // there is a new price, all the owners have to confirm
         this.store.removeAllAcceptors(this.id);
         // if the editor is an owner then add him/her again
         if (userHasPermission(editor))
         {
             this.store.acceptOffer(editor, this.id);
         }
     }
     return(true);
 }
Beispiel #17
0
 public abstract bool isValid(ICollection <Product> products, aUser user);
 public ShoppingCart(aUser owner, ICollection <BasketInCart> baskets)
 {
     //todo
     this.owner   = owner;
     this.baskets = new LinkedList <ShoppingBasket>();
 }
Beispiel #19
0
 public ShoppingBasket(Store store, aUser owner)
 {
     this.store    = store;
     this.products = new LinkedList <Product>();
     this.owner    = owner;
 }
Beispiel #20
0
 public static void logout()
 {
     logged = null;
 }
Beispiel #21
0
 private bool userHasPermission(aUser editor)
 {
     // check if the user has the permission to edit the price
     return(this.store.hasRequestPermission(editor));
 }
 public ShoppingCart(aUser owner)
 {
     this.owner   = owner;
     this.baskets = new LinkedList <ShoppingBasket>();
 }
 public override bool isValid(ICollection <Product> products, aUser user)
 {
     throw new NotImplementedException();
 }
 public static void threadInit()
 {
     user     = new Guest();
     userName = user.getUserName();
 }