public static SLstore searchStore(string storeName)
 {
     BuissnessLayer.commerce.Store store = BuissnessLayer.commerce.Stores.searchStore(storeName);
     return(StoreController.makeSLstore(store));
 }
        public static DecodedMessge act(DecodedMessge msg)
        {
            bool   ans   = false;
            string ans_d = "";

            string[]      ans_a;
            DecodedMessge msg_send = new DecodedMessge();

            if (msg.type == msgType.FUNC)
            {
                switch (msg.name)
                {
                case ("register"):
                    var ans_r = TradingSystem.ServiceLayer.UserController.register(msg.param_list[0], msg.param_list[1], double.Parse(msg.param_list[2]), msg.param_list[3], msg.param_list[4]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string[]";
                    msg_send.param_list = ans_r;
                    //  byte[] enc_r = TradingSystem.ServiceLayer.Encoder.encode(msg_send);
                    //   ServerConnectionManager.sendMessage(enc_r);
                    break;

                case ("login"):
                    ans_a = TradingSystem.ServiceLayer.UserController.login(msg.param_list[0], msg.param_list[1]);
                    ans_d = "false";
                    if (ans_a[0].Equals("true"))
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "login response";
                    msg_send.param_list = ans_a;
                    //   byte[] enc_l = TradingSystem.ServiceLayer.Encoder.encode(msg_send);
                    // ServerConnectionManager.sendMessage(enc_l);
                    break;

                case ("get online user"):
                    TradingSystem.ServiceLayer.UserController.getCorrentOnlineUser();
                    break;

                case ("get online user name"):
                    ans_d               = TradingSystem.ServiceLayer.UserController.getCorrentOnlineUserName();
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string";
                    msg_send.param_list = new string[] { ans_d };
                    //    byte[] enc_name = TradingSystem.ServiceLayer.Encoder.encode(msg_send);
                    //        ServerConnectionManager.sendMessage(enc_name);
                    break;

                case ("logout"):
                    ans   = TradingSystem.ServiceLayer.UserController.logout();
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    //   byte[] enc_lo = TradingSystem.ServiceLayer.Encoder.encode(msg_send);
                    //    ServerConnectionManager.sendMessage(enc_lo);
                    break;

                case ("save product"):     // Products : "name1&15$name2&30 ..."
                    ans = TradingSystem.ServiceLayer.UserController.saveProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], StringToDictionary(msg.param_list[3]));
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("remove product"):     // Products : "name1&15$name2&30 ..."
                    ans = TradingSystem.ServiceLayer.UserController.removeProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], StringToDictionary(msg.param_list[3]));
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("delete product"):     // string username, string storeName, string productName, string manufacturer
                    ans = TradingSystem.ServiceLayer.UserController.removeProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], msg.param_list[3]);
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("get basket"):     // string username, string storeName
                    var ans_gb = TradingSystem.ServiceLayer.UserController.getBasket(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "basket";
                    msg_send.param_list = BasketToStringArray(ans_gb);     // {user name, store name, pros}. pros -> pro$pro -> proInfo^feedback -> feedback_feedback -> user#comment
                    break;

                case ("get cart"):     // CartToStringArray
                    var ans_gc = TradingSystem.ServiceLayer.UserController.getCart(msg.param_list[0]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "cart";
                    msg_send.param_list = CartToStringArray(ans_gc);     // {basket, basket}. basket -> username&storename&pros. pros -> -> pro$pro -> proInfo^feedback -> feedback_feedback -> user#comment
                    break;

                case ("open store"):
                    ans   = TradingSystem.ServiceLayer.UserController.EstablishStore(msg.param_list[0], msg.param_list[1]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    // byte[] enc_os = TradingSystem.ServiceLayer.Encoder.encode(msg_send);
                    // ServerConnectionManager.sendMessage(enc_os);
                    break;

                case ("purchase"):     // string username, string creditNumber, string validity, string cvv
                    var ans_p = TradingSystem.ServiceLayer.UserController.purchase(msg.param_list[0], msg.param_list[1], msg.param_list[2], msg.param_list[3]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "receipts";
                    msg_send.param_list = ans_p;     // { bool, receipt, receipt }. receipt -> user$store$price$date$id$products. products -> pro1&pro2&pro3 -> proInfo^feedback -> feedback_feedback -> user#comment
                    break;

                case ("check price"):     // string username
                    ans_d               = "" + TradingSystem.ServiceLayer.UserController.checkPrice(msg.param_list[0]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "double";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("browse products"):     // string username, string productName, string manufacturer
                    var ans_bp = TradingSystem.ServiceLayer.UserController.browseProducts(msg.param_list[0], msg.param_list[1], msg.param_list[2]);
                    msg_send.type = msgType.OBJ;
                    msg_send.name = "dictionary product";
                    List <string> lst = new List <string>();
                    foreach (KeyValuePair <string, SLproduct> item in ans_bp)
                    {
                        lst.AddRange(item.Value.toStringarr(item.Key));
                    }
                    msg_send.param_list = lst.ToArray();    // arr[i] -> store$product -> proInfo^feedback -> feedback_feedback -> user#comment
                    break;

                case ("browse store"):
                    ans_d               = TradingSystem.ServiceLayer.UserController.browseStore(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("search store"):
                    ans_d = "";
                    var temp = StoreController.searchStore(msg.param_list[0]);
                    if (temp != null)
                    {
                        ans_d = temp.storeName;
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("get receipts in store"):
                    var ans_grs = TradingSystem.ServiceLayer.UserController.getReceiptsHistory(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "receipts";
                    msg_send.param_list = ReceiptsToStringArray(ans_grs);
                    break;

                case ("get all receipts in store"):
                    var ans_gra = TradingSystem.ServiceLayer.UserController.getAllReceiptsHistory(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "receipts";
                    msg_send.param_list = ReceiptsToStringArray(ans_gra);
                    break;

                case ("get all my receipts"):
                    var ans_gamr = TradingSystem.ServiceLayer.UserController.getAllMyReceiptHistory(msg.param_list[0]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "receipts";
                    msg_send.param_list = ReceiptsToStringArray(ans_gamr);
                    break;

                case ("get my employees"):
                    var ans_gme = TradingSystem.ServiceLayer.UserController.getInfoEmployees(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "users";
                    msg_send.param_list = UsersToStringArray(ans_gme);     // { user, user, user }. user -> name$permissions. permissions -> per1&per2&per3. per -> store^pers. pers -> pername#pername
                    break;

                case ("add new product to store"):     // string username, string storeName, string productName, double price, int amount, string category, string manufacturer
                    ans   = TradingSystem.ServiceLayer.UserController.addNewProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], double.Parse(msg.param_list[3]), int.Parse(msg.param_list[4]), msg.param_list[5], msg.param_list[6]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("remove product from store"):     // string username, string storeName, string productName, string manufacturer
                    ans   = TradingSystem.ServiceLayer.UserController.removeProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], msg.param_list[3]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("edit product from store"):     //string username, string storeName, string productName, double price, string manufacturer
                    ans   = TradingSystem.ServiceLayer.UserController.editProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], double.Parse(msg.param_list[3]), msg.param_list[4]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("supply product"):     //string username, string storeName, string productName, int amount, string manufacturer
                    ans   = TradingSystem.ServiceLayer.UserController.supplyProduct(msg.param_list[0], msg.param_list[1], msg.param_list[2], int.Parse(msg.param_list[3]), msg.param_list[4]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("hire new manager"):     //string username, string storeName, string userToHire
                    ans   = TradingSystem.ServiceLayer.UserController.hireNewStoreManager(msg.param_list[0], msg.param_list[1], msg.param_list[2]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("edit manager"):     //string username, string storeName, string userToHire, List<string> Permissions -> "pre1$pre2$pre3 ..."
                    ans   = TradingSystem.ServiceLayer.UserController.editManagerPermissions(msg.param_list[0], msg.param_list[1], msg.param_list[2], StringToList(msg.param_list[3]));
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("hire new owner"):     //string username, string storeName, string userToHire, List<string> Permissions -> "pre1$pre2$pre3 ..."
                    ans   = TradingSystem.ServiceLayer.UserController.hireNewStoreOwner(msg.param_list[0], msg.param_list[1], msg.param_list[2], StringToList(msg.param_list[3]));
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("remove manager"):     //string username, string storeName, string userToHire
                    ans   = TradingSystem.ServiceLayer.UserController.removeManager(msg.param_list[0], msg.param_list[1], msg.param_list[2]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("leave feedback"):     //string username, string storeName, string productName, string manufacturer, string comment
                    ans   = TradingSystem.ServiceLayer.UserController.leaveFeedback(msg.param_list[0], msg.param_list[1], msg.param_list[2], msg.param_list[3], msg.param_list[4]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("get all feedbacks"):     //string storeName, string productName, string manufacturer
                    var ans_afb = TradingSystem.ServiceLayer.UserController.getAllFeedbacks(msg.param_list[0], msg.param_list[1], msg.param_list[2]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "feedbacks";
                    msg_send.param_list = new string[] { feedbackToString(ans_afb) }; // feedback_feedback -> user#comment.    almog#what i think_gal#what he think
                    break;                                                            // feedbackToString

                case ("get all feedbacks for search"):                                //string storeName, string productName
                    var ans_afbs = TradingSystem.ServiceLayer.UserController.getAllFeedbacks(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "feedbacks";
                    msg_send.param_list = new string[] { feedbackToStringSearch(ans_afbs) }; // feedback\nfeedback -> user: comment.    almog: what i think\ngal: what he think
                    break;                                                                   // feedbackToString

                case ("username"):
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string";
                    msg_send.param_list = new string[] { UserController.getUserName() };
                    break;

                case ("get my stores"):     //string username
                    var ans_gms = TradingSystem.ServiceLayer.UserController.GetMyStores(msg.param_list[0]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string[]";
                    msg_send.param_list = ans_gms;
                    break;

                case ("get my permission on store"):     //string username, string storeName
                    var ans_gmp = TradingSystem.ServiceLayer.UserController.GetPermissions(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string[]";
                    msg_send.param_list = ans_gmp;
                    break;

                case ("get all products"):
                    var ans_gap = TradingSystem.ServiceLayer.ProductController.getAllProducts();
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string[]";
                    msg_send.param_list = AllProductsToStringArr(ans_gap);
                    break;

                case ("send message"):     // string username, string userToSend, string storeToSend, string msg, string storeRecive
                    ans   = TradingSystem.ServiceLayer.UserController.sendMessage(msg.param_list[0], msg.param_list[1], msg.param_list[2], msg.param_list[3], msg.param_list[4]);
                    ans_d = "false";
                    if (ans)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;

                case ("get store message"):     //string username, string storename
                    var ans_gmm = TradingSystem.ServiceLayer.UserController.getMessages(msg.param_list[0], msg.param_list[1]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string[]";
                    msg_send.param_list = ans_gmm;
                    break;

                case ("get my message"):     //string username
                    var ans_gmmu = TradingSystem.ServiceLayer.UserController.getMessages(msg.param_list[0]);
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "string[]";
                    msg_send.param_list = ans_gmmu;
                    break;

                case ("close store"):     //string username
                    var ans_cs = TradingSystem.ServiceLayer.UserController.closeStore(msg.param_list[0], msg.param_list[1]);
                    ans_d = "false";
                    if (ans_cs)
                    {
                        ans_d = "true";
                    }
                    msg_send.type       = msgType.OBJ;
                    msg_send.name       = "bool";
                    msg_send.param_list = new string[] { ans_d };
                    break;
                }
            }

            return(msg_send);
        }