Exemplo n.º 1
0
        private async void PremiseSettingChangedExecute(object obj)
        {
            var list = new List <IUserWLanTimeEntryType>();

            list.AddRange(_userWlanSettingsService.WLansBoundToTimeEntryTypes);
            var availableNetworkList = await _connectivityService.GetAvailableNetworkList();

            var unlistedWLanTimeEntryTypes = availableNetworkList
                                             .Select(x => new UserWLanTimeEntryType(0, x))
                                             .Where(newWlans => list.All(x => x.WifiName != newWlans.WifiName));

            list.AddRange(unlistedWLanTimeEntryTypes);

            foreach (var userWLanTimeEntryType in list)
            {
                userWLanTimeEntryType.Connected = userWLanTimeEntryType.WifiName == await _connectivityService.GetWLanIdentification();
            }

            WLansBoundToTimeEntryTypes.Clear();
            WLansBoundToTimeEntryTypes.AddRange(list.Select(x =>
            {
                var timeEntryTypes = TimeEntryTypes.SingleOrDefault(t => t.Id == x.DefaultTimeEntryTypeId);
                return(new UserWLanTimeEntryTypeItemViewmodel(timeEntryTypes, x));
            }));
            WLansBoundToTimeEntryTypes.ItemChanged += WLansBoundToTimeEntryTypesOnCollectionChanged;
        }
        //private void CreateTimeEntryTypeCompleted(TimeEntryType newTimeEntryType)
        //{
        //    var timeEntryTypeViewModel = new TimeEntryTypeViewModel(newTimeEntryType);

        //    //control the default type
        //    if (newTimeEntryType.IsDefault)
        //        SetAsDefault(newTimeEntryType);

        //    TimeEntryTypes.Add(timeEntryTypeViewModel);

        //    //If its a global type, commit immediately
        //    if (newTimeEntryType.IsGlobal)
        //        Commit();

        //}

        private void EditTimeEntryTypeCompleted(TimeEntryType timeEntryType)
        {
            //control the default type
            if (timeEntryType.IsDefault)
            {
                SetAsDefault(timeEntryType);
            }

            var timeEntryTypeViewModel = TimeEntryTypes.SingleOrDefault(t => t.TimeEntryType.TimeEntryTypeId == timeEntryType.TimeEntryTypeId);

            //If its a new one, we´ll add it
            if (timeEntryTypeViewModel == null)
            {
                timeEntryTypeViewModel = new TimeEntryTypeViewModel(timeEntryType);
                TimeEntryTypes.Add(timeEntryTypeViewModel);
                if (DataReady != null)
                {
                    DataReady(this, null);
                }
            }

            //If its a global type, commit immediately
            if (timeEntryType.Customer == null)
            {
                Commit();
            }
        }
        public void     Commit()
        {
            foreach (var timeEntryTypeModel in TimeEntryTypes)
            {
                _dataService.SaveTimeEntryType(timeEntryTypeModel.TimeEntryType).Subscribe(
                    timeEntryType =>
                {
                    var timeEntryTypeViewModel =
                        TimeEntryTypes.SingleOrDefault(
                            t => t.TimeEntryType.TimeEntryTypeId == timeEntryType.TimeEntryTypeId);

                    if (timeEntryTypeViewModel != null)
                    {
                        timeEntryTypeViewModel.TimeEntryType.TimeEntryTypeId = timeEntryType.TimeEntryTypeId;
                    }

                    timeEntryTypeModel.Update();
                });
            }

            if (DataCommitted != null)
            {
                DataCommitted(this, null);
            }
        }
Exemplo n.º 4
0
        private TimeEntryType GetMostUsedTimeEntryType(DayItemHeaderViewmodel dayItemHeaderViewmodel)
        {
            var timeEntries = dayItemHeaderViewmodel.TimeEntries
                              .ToList();

            if (!timeEntries.Any())
            {
                return(TimeEntryTypes.SingleOrDefault(x => x.IsDefault)); // Can be empty if resync is in progress
            }
            var mostUsedTimeEntryType = timeEntries
                                        .GroupBy(x => x.TimeEntryType.Id)
                                        .OrderByDescending(x => x.Count())
                                        .First().Key;

            return(TimeEntryTypes.SingleOrDefault(x => x.Id == mostUsedTimeEntryType)); // Can be empty if resync is in progress
        }