private static void SyncCategories(ServiceReference2.StaticClient b, User user)
        {
            var typeTrans = b.GetAllTypeTransactionReasons(user.UserId);
            var cats = b.GetAllCategories(user.UserId);

            var catList = new List<Category>();

            var cat1 = cats[0];
            cat1.CategoryId = 0;
            cat1.Name = "ys1";
            cat1.TypeTransactionReasons = new List<TypeTransactionReason> { typeTrans.FirstOrDefault(x => x.Name == "Other") };
            cat1.ModifiedDate = DateTime.Now;
            
            var cat2 = cats[1];
            cat2.CategoryId = -1;
            cat2.Name = "ys2";
            cat2.TypeTransactionReasons = new List<TypeTransactionReason> { 
                                                            typeTrans.FirstOrDefault(x => x.Name == "Other"),
                                                            typeTrans.FirstOrDefault(x => x.Name != "Other")};
            cat2.ModifiedDate = DateTime.Now;

            catList.AddRange(new List<Category> { cat1, cat2 });
            //catList.AddRange(new List<Category> { cat1});

            b.SyncCategories(catList);
        }
        private static void UpdateTypeInterval(ServiceReference1.MainClient a, ServiceReference2.StaticClient b, User usr)
        {
            var cat = b.GetAllCategories(usr.UserId);
            var typeIntervals = b.GetAllTypeIntervals(usr.UserId);
            var recurrenceRules = b.GetAllRecurrenceRules();
            var typeTransactions = b.GetAllTypeTransactions(usr.UserId);

            // UPDATE //
            typeIntervals[0].Amount = 19d;
            typeIntervals[0].TransactionType = typeTransactions[1];
            typeIntervals[0].RecurrenceRuleValue.RulePartValueList[0].Value = "9123";
            typeIntervals[0].ModifiedDate = DateTime.Now;
            //staticData.TypeIntervals[1].ModifiedDate = DateTime.Now;

            typeIntervals[0].RecurrenceRangeRuleValue.RecurrenceRule = recurrenceRules.FirstOrDefault(x => x.Name == Const.Rule.RuleRangeTotalOcurrences.ToString());
            typeIntervals[0].RecurrenceRangeRuleValue.RulePartValueList[0].Value = "20100202";
            typeIntervals[0].RecurrenceRangeRuleValue.RulePartValueList[1].Value = "3";
            //staticData.TypeIntervals[0].RecurrenceRangeRuleValue.RulePartValueList[1].Value = "b22";
            //staticData.TypeIntervals[0].RecurrenceRangeRuleValue.RulePartValueList[1].Value = "c22";

            var k = new List<TypeInterval>();
            k.Add(typeIntervals[0]);

            var update = b.SaveTypeIntervals(k);

        }
        private static void InsertTypeInterval(ServiceReference1.MainClient a,ServiceReference2.StaticClient b, User usr)
        {
            var cat = b.GetAllCategories(usr.UserId);
            var typeTransReason = b.GetAllTypeTransactionReasons(usr.UserId);
            var typeIntervals = b.GetAllTypeIntervals(usr.UserId);
            var recurrenceRules = b.GetAllRecurrenceRules();
            var typeTransactions = b.GetAllTypeTransactions(usr.UserId);

            var catList = new CategoryList();
            cat.ForEach(x => catList.Add(x));

            var typeTransReasonList = new TypeTransactionReasonList();
            typeTransReason.ForEach(x => typeTransReasonList.Add(x));

            var typeTransactionsList = new TypeTransactionList();
            typeTransactions.ForEach(x => typeTransactionsList.Add(x));


            // INSERT //
            var intervals = new TypeIntervalList { new TypeInterval(catList, typeTransReasonList, typeTransactionsList, usr) };
            //intervals[0].RecurrenceRule = staticData.RecurrenceRules.FirstOrDefault(x => x.Name == "RuleDailyEveryDays");


            var found = recurrenceRules.FirstOrDefault(x => x.Name == "RuleDailyEveryDays");
            intervals[0].RecurrenceRuleValue.RecurrenceRule = found;
            intervals[0].RecurrenceRuleValue.RulePartValueList[0].Value = "aaa";
            intervals[0].RecurrenceRuleValue.RulePartValueList[1].Value = "bbb";

            intervals[0].RecurrenceRangeRuleValue.RecurrenceRule = recurrenceRules.FirstOrDefault(x => x.Name == Const.Rule.RuleRangeTotalOcurrences.ToString());
            intervals[0].RecurrenceRangeRuleValue.RulePartValueList[0].Value = "20111111";
            intervals[0].RecurrenceRangeRuleValue.RulePartValueList[1].Value = "234";


            var result = b.SaveTypeIntervals(intervals.ToList());

        }
        private static List<Category> SaveCategories(ServiceReference2.StaticClient b, User usr)
        {
            var allCat = b.GetAllCategories(usr.UserId);
            var allReasons = b.GetAllTypeTransactionReasons(usr.UserId);

            var catList = new CategoryList();
            var reasonList = new TypeTransactionReasonList();

            allReasons.ForEach(x=>reasonList.Add(x));
            var newCat = new Category(usr, reasonList);
            newCat = allCat[2];
            newCat.TypeTransactionReasons[1].IsDeleted = true;
            newCat.TypeTransactionReasons[1].ModifiedDate = DateTime.Now;

            newCat.HasChanges = true;
            newCat.ModifiedDate = DateTime.Now;

            //newCat.Name = "CarTest";

            //if (newCat.TypeTransactionReasons == null)
            //    newCat.TypeTransactionReasons = new List<TypeTransactionReason>();

            //newCat.TypeTransactionReasons.Add(allReasons[0]);
            //newCat.TypeTransactionReasons.Add(allReasons[1]);

            //var transReasonList = new List<TypeTransactionReason>();
            //var transReason = new TypeTransactionReason(usr);
            //transReason.Name = "CarTest";


            catList.Add(newCat);

            catList.OptimizeOnTopLevel();

            var result = b.SaveCategories(catList.ToList());
            //var arrC = st.ToList();

            //var c = b.SaveCategories(st.Categories);

            return result;
        }