Beispiel #1
0
        private void register(Opertaion op, int i)
        {
            if (op.args.Count != 2)
            {
                throw new Exception("wrong agument number in system init register");
            }

            var userId = _facade.Register(Guid.NewGuid(), op.args[0], op.args[1]);

            _results.Add("r" + i, userId);
        }
Beispiel #2
0
        private void openshop(Opertaion op, int i)
        {
            if (op.args.Count != 2)
            {
                throw new Exception("wrong agument number in system init register");
            }

            var userId = _results[op.args[0]];
            var shop   = new Shop(userId, op.args[1]);

            _unitOfWork.ShopRepository.Add(shop);
            _results.Add("r" + i, shop.Guid);
        }
Beispiel #3
0
        private void admin(Opertaion op)
        {
            if (op.args.Count != 1)
            {
                throw new Exception("wrong agument number in system init register");
            }
            var userId = _results[op.args[0]];

            var user = _unitOfWork.BaseUserRepository.FindByIdOrNull(userId);

            if (user != null)
            {
                user.IsAdmin = true;
                _unitOfWork.BaseUserRepository.Update(user);
            }
        }
Beispiel #4
0
        private void Addproduct(Opertaion op)
        {
            if (op.args.Count != 6)
            {
                throw new Exception("wrong agument number in system init register");
            }

            var         userId   = _results[op.args[0]];
            var         shopId   = _results[op.args[1]];
            var         name     = op.args[2];
            var         category = op.args[3];
            var         price    = float.Parse(op.args[4]);
            var         quantity = int.Parse(op.args[5]);
            ShopProduct product  = new ShopProduct(new Product(name, category), price, quantity);

            var shop = _unitOfWork.ShopRepository.FindByIdOrNull(shopId);

            shop.ShopProducts.Add(product);
            _unitOfWork.ShopRepository.Update(shop);
        }
Beispiel #5
0
        private void runOperation(Opertaion op, int i)
        {
            switch (op.operationName.ToLower())
            {
            case "register":
                register(op, i);
                break;

            case "admin":
                admin(op);
                break;

            case "openshop":
                openshop(op, i);
                break;

            case "addproduct":
                Addproduct(op);
                break;

            default:
                throw new Exception("bad init operation");
            }
        }