예제 #1
0
        public EquipmentViewModel(IEquipmentService equipmentService = null)
        {
            _equipmentService = equipmentService ?? (IEquipmentService)Locator.Current.GetService(typeof(IEquipmentService));



            this.WhenAnyValue(vm => vm.Name)
            .Throttle(TimeSpan.FromSeconds(1))
            .Subscribe(name =>
            {
                if (name != "")
                {
                    Search(Name, Status, Type);
                }
                else
                {
                    GetAllEquipment();
                }
            });

            MessagingCenter.Subscribe <Equipment>(this, "NewEquipment", (item) =>
            {
                //var newItem = item as Equipment;
                Equipments.Add(item);
                //_equipmentService.Add(item);
            });

            MessagingCenter.Subscribe <Equipment>(this, "EditEquipment", (item) =>
            {
                var index                  = Equipments.ToList().FindIndex(c => c.Id == item.Id);
                Equipments[index].Id       = item.Id;
                Equipments[index].Name     = item.Name;
                Equipments[index].Type     = item.Type;
                Equipments[index].TypeName = item.TypeName;
                Equipments[index].Quantity = item.Quantity;
            });


            //this.WhenAnyValue(vm => vm.Type).Subscribe(type =>
            //{
            //    Search(Name, Status, Type);
            //});
            //this.WhenAnyValue(vm => vm.Status).Subscribe(status =>
            //{
            //    Search(Name, Status, Type);
            //});
        }