Exemplo n.º 1
0
 /// <summary>
 /// Provides a deterministic way to create the Timers property.
 /// </summary>
 public static void CreateTimers()
 {
     if (_timers == null)
     {
         _timers = new TimersViewModel();
     }
 }
Exemplo n.º 2
0
        public TimersViewPage(TimersViewModel viewModel)
        {
            InitializeComponent();

            _viewModel       = viewModel;
            this.DataContext = _viewModel;
        }
        public ActivityDetailsWindow(Window owner, TimersViewModel viewModel)
        {
            InitializeComponent();

            _owner                 = owner;
            _viewModel             = viewModel;
            this.DataContext       = _viewModel;
            this.Closing          += (sender, e) => { _viewModel.OnCloseActivityDetailsWindow(); e.Cancel = true; };
            this.IsVisibleChanged += (sender, e) =>
            {
                switch (Visibility)
                {
                case Visibility.Visible:
                    this.Owner     = _owner;
                    _owner.Opacity = 0.3;
                    break;

                case Visibility.Hidden:
                    _owner.Opacity = 1.0;
                    break;
                }
            };

            this.Topmost = true;
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(TimersViewModel timer)
        {
            var selectedUserId = timer.SelectedUserId;

            if (!ModelState.IsValid ||
                !int.TryParse(timer.SelectedTaskId, out var selectedTaskId) ||
                selectedUserId == null)
            {
                return(View(timer));
            }

            var newTimer = new Timer
            {
                StartTime = timer.StartTime,
                StopTime  = timer.StopTime,
                Duration  = CalculateDuration(timer),
                User      = await _context.Users.FindAsync(selectedUserId),
                Task      = await _context.Tasks.FindAsync(selectedTaskId)
            };

            _context.Add(newTimer);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", "Tasks", new { Id = timer.SelectedTaskId }));
        }
Exemplo n.º 5
0
        // GET: Timers/Create
        public async Task <IActionResult> Create(int?taskId)
        {
            Task task;

            if (taskId != null)
            {
                task = await _context.Tasks.FindAsync(taskId);
            }
            else
            {
                task = null;
            }

            var vm = new TimersViewModel
            {
                StartTime = DateTime.Now,
                StopTime  = null,
                Tasks     = await _context.Tasks
                            .Select(t => new SelectListItem {
                    Text = t.Name, Value = t.Id.ToString()
                })
                            .ToListAsync(),
                Users = await _context.Users
                        .Select(u => new SelectListItem {
                    Text = u.UserName, Value = u.Id
                })
                        .ToListAsync()
            };

            if (User.Identity.IsAuthenticated)
            {
                var query = from user in _context.Users
                            where user.UserName == User.Identity.Name
                            select user.Id;

                vm.SelectedUserId = query.FirstOrDefault();
            }

            if (task != null)
            {
                vm.Task           = task;
                vm.SelectedTaskId = task.Id.ToString();
            }

            return(View(vm));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,StartTime,StopTime,SelectedTaskId,SelectedUserId")] TimersViewModel timerVM)
        {
            var timer = await _context.Timers.FindAsync(id);

            if (timer == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid &&
                int.TryParse(timerVM.SelectedTaskId, out var selectedTaskID))
            {
                try
                {
                    timer.StartTime = timerVM.StartTime;
                    timer.StopTime  = timerVM.StopTime;
                    timer.User      = await _context.Users.FindAsync(timerVM.SelectedUserId);

                    timer.Task = await _context.Tasks.FindAsync(selectedTaskID);

                    if (timerVM.StopTime != null)
                    {
                        timer.Duration = CalculateDuration(timerVM);
                    }

                    _context.Update(timer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TimerExists(timerVM.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(timerVM));
        }
Exemplo n.º 7
0
        // GET: Timers/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var timer = await _context.Timers
                        .Include(t => t.Task)
                        .Include(t => t.User)
                        .FirstOrDefaultAsync(t => t.Id == id);

            if (timer == null)
            {
                return(NotFound());
            }

            var selectedUserId = timer.User.Id;
            var selectedTaskId = timer.Task.Id.ToString();

            var vm = new TimersViewModel
            {
                Id             = timer.Id,
                StartTime      = timer.StartTime,
                StopTime       = timer.StopTime,
                Duration       = timer.Duration,
                SelectedTaskId = selectedTaskId,
                SelectedUserId = selectedUserId,
                User           = await _context.Users.FindAsync(selectedUserId),
                Tasks          = await _context.Tasks
                                 .Select(t => new SelectListItem {
                    Text = t.Name, Value = t.Id.ToString()
                })
                                 .ToListAsync(),
                Users = await _context.Users
                        .Select(u => new SelectListItem {
                    Text = u.UserName, Value = u.Id
                })
                        .ToListAsync()
            };

            return(View(vm));
        }
Exemplo n.º 8
0
        public void Startup()
        {
            _appApplicationEnvironment = new ApplicationEnvironment();
            _appApplicationEnvironment.SetupApplicationEnvironment();

            _appApplicationEnvironment.EventHub.Subscribe <AppExitMessage>(OnAppShutdownHandler);

            Logger.Log.Info("Init data models");
            _entryModel               = new EntryViewModel(_appApplicationEnvironment);
            _appViewModel             = new ApplicationViewModel(_appApplicationEnvironment);
            _timersViewModel          = new TimersViewModel(_appApplicationEnvironment);
            _reportsViewModel         = new ReportsViewModel(_appApplicationEnvironment);
            _settingsViewModel        = new SettingsViewModel(_appApplicationEnvironment);
            _notificationViewModel    = new NotificationViewModel(_appApplicationEnvironment);
            _profileSettingsViewModel = new ProfileSettingsViewModel(_appApplicationEnvironment);

            Logger.Log.Info("Init dialog service");
            _dialogService = new DialogService();
            _dialogService.RegisterDialog <ConfirmationDialogModel, ConfirmationDialog>();

            Logger.Log.Info("Init views");
            _mainView = new MainWindow(_dialogService, _appViewModel);

            _entryWindow = new EntryWindow(_entryModel);

            _activityDetailsWindow = new ActivityDetailsWindow(_mainView, _timersViewModel);

            _notificationWindow    = new NotificationWindow(_mainView, _notificationViewModel);
            _profileSettingsWindow = new ProfileSettingsWindow(_mainView, _profileSettingsViewModel);

            _timersViewPage = new TimersViewPage(_timersViewModel);
            _mainView.AddPage(_timersViewPage);

            _reportsViewPage = new ReportsViewPage(_reportsViewModel);
            _mainView.AddPage(_reportsViewPage);

            _settingsViewPage = new SettingsViewPage(_settingsViewModel);
            _mainView.AddPage(_settingsViewPage);

            _mainView.Run();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Provides a deterministic way to delete the Timers property.
 /// </summary>
 public static void ClearTimers()
 {
     _timers.Cleanup();
     _timers = null;
 }