예제 #1
0
        public RequestDialogViewModel()
        {
            AlertExists     = false;
            _requestService = new RequestServiceImpl.RequestService(AppSettings.DbConnection);
            var contactInfo = new ContactDto {
                Id = 1, IsMain = true, PhoneNumber = AppSettings.LastIncomingCall
            };

            _callUniqueId   = _requestService.GetActiveCallUniqueId();
            StreetList      = new ObservableCollection <StreetDto>();
            HouseList       = new ObservableCollection <HouseDto>();
            FlatList        = new ObservableCollection <FlatDto>();
            AddressTypeList = new ObservableCollection <AddressTypeDto>(_requestService.GetAddressTypes());
            //if (AddressTypeList.Count > 0)
            //{
            //    SelectedAddressType = AddressTypeList.FirstOrDefault();
            //}
            CityList = new ObservableCollection <CityDto>(_requestService.GetCities());
            if (CityList.Count > 0)
            {
                SelectedCity = CityList.FirstOrDefault();
            }
            RequestList = new ObservableCollection <RequestItemViewModel> {
                new RequestItemViewModel()
            };
            //AppSettings.LastIncomingCall = "932";
            CanEditAddress = AppSettings.CurrentUser.Roles.Select(r => r.Name).Contains("admin");
            if (!string.IsNullOrEmpty(AppSettings.LastIncomingCall))
            {
                var clientInfoDto = _requestService.GetLastAddressByClientPhone(AppSettings.LastIncomingCall);
                if (clientInfoDto != null)
                {
                    SelectedStreet = StreetList.FirstOrDefault(s => s.Id == clientInfoDto.StreetId);
                    SelectedHouse  = HouseList.FirstOrDefault(h => h.Building == clientInfoDto.Building &&
                                                              h.Corpus == clientInfoDto.Corpus);
                    SelectedFlat = FlatList.FirstOrDefault(f => f.Flat == clientInfoDto.Flat);
                    contactInfo  = new ContactDto {
                        Id = 1, IsMain = true, PhoneNumber = AppSettings.LastIncomingCall, Name = clientInfoDto.Name
                    };
                }
            }
            ContactList = new ObservableCollection <ContactDto>(new[] { contactInfo });
        }