<commit_before>﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Jirabox.Core.Contracts;
using System;
using System.Threading.Tasks;

namespace Jirabox.ViewModel
{
    public class LogWorkViewModel : ViewModelBase
    {
        private readonly INavigationService navigationService;
        private readonly IJiraService jiraService;

        public RelayCommand LogWorkCommand { get; private set; }

        private DateTime startDate;

        public DateTime StartDate
        {
            get { return startDate; }
            set
            {
                if (startDate != value)
                {
                    startDate = value;
                    RaisePropertyChanged(() => StartDate);
                }
            }
        }

        private DateTime endDate;

        public DateTime EndDate
        {
            get { return endDate; }
            set 
            {
                if (endDate != value)
                {
                    endDate = value;
                    RaisePropertyChanged(() => EndDate);
                }
            }
        }


        private int hour;

        public int Hour
        {
            get { return hour; }
            set 
            {
                if (hour != value)
                {
                    hour = value;
                    RaisePropertyChanged(() => Hour);
                }
            }
        }

        private int minute;

        public int Minute
        {
            get { return minute; }
            set 
            {
                if (minute != value)
                {
                    minute = value;
                    RaisePropertyChanged(() => Minute);
                }
            }
        }

        private string comment;

        public string Comment
        {
            get { return comment; }
            set 
            {
                if (comment != value)
                {
                    comment = value;
                    RaisePropertyChanged(() => Comment);
                }
            }
        }

        private bool isPeriod;

        public bool IsPeriod
        {
            get { return isPeriod; }
            set 
            {
                if (isPeriod != value)
                {
                    isPeriod = value;
                    RaisePropertyChanged(() => IsPeriod);
                }
            }
        }


        public LogWorkViewModel(INavigationService navigationService, IJiraService jiraService)
        {
            this.navigationService = navigationService;
            this.jiraService = jiraService;

            LogWorkCommand = new RelayCommand(async()=>await LogWork());
            StartDate = DateTime.Now;
            EndDate = DateTime.Now;
        }

        private async Task LogWork()
        {
            var issueKey = navigationService.GetNavigationParameter().ToString();
            while (StartDate.ToShortDateString() != EndDate.ToShortDateString())
            {
                var date = String.Format("{0:s}", StartDate);
                var timeSpent = String.Format("{0}h {1}m", Hour, minute);
                var result = await jiraService.LogWork(issueKey, date, timeSpent, Comment);
                StartDate = StartDate.AddDays(1);
            }            
        }
    }
}<commit_msg>Logwork period feature added.<commit_after>﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Jirabox.Core.Contracts;
using System;
using System.Threading.Tasks;

namespace Jirabox.ViewModel
{
    public class LogWorkViewModel : ViewModelBase
    {
        private readonly INavigationService navigationService;
        private readonly IJiraService jiraService;

        public RelayCommand LogWorkCommand { get; private set; }

        private DateTime startDate;

        public DateTime StartDate
        {
            get { return startDate; }
            set
            {
                if (startDate != value)
                {
                    startDate = value;
                    RaisePropertyChanged(() => StartDate);
                }
            }
        }

        private DateTime endDate;

        public DateTime EndDate
        {
            get { return endDate; }
            set 
            {
                if (endDate != value)
                {
                    endDate = value;
                    RaisePropertyChanged(() => EndDate);
                }
            }
        }


        private int hour;

        public int Hour
        {
            get { return hour; }
            set 
            {
                if (hour != value)
                {
                    hour = value;
                    RaisePropertyChanged(() => Hour);
                }
            }
        }

        private int minute;

        public int Minute
        {
            get { return minute; }
            set 
            {
                if (minute != value)
                {
                    minute = value;
                    RaisePropertyChanged(() => Minute);
                }
            }
        }

        private string comment;

        public string Comment
        {
            get { return comment; }
            set 
            {
                if (comment != value)
                {
                    comment = value;
                    RaisePropertyChanged(() => Comment);
                }
            }
        }

        private bool isPeriod;

        public bool IsPeriod
        {
            get { return isPeriod; }
            set 
            {
                if (isPeriod != value)
                {
                    isPeriod = value;
                    RaisePropertyChanged(() => IsPeriod);
                }
            }
        }


        public LogWorkViewModel(INavigationService navigationService, IJiraService jiraService)
        {
            this.navigationService = navigationService;
            this.jiraService = jiraService;

            LogWorkCommand = new RelayCommand(async()=>await LogWork());
            StartDate = DateTime.Now;
            EndDate = DateTime.Now;
        }

        private async Task LogWork()
        {
            var issueKey = navigationService.GetNavigationParameter().ToString();
            if (IsPeriod)
            {
                while (StartDate.ToShortDateString() != EndDate.ToShortDateString())
                {
                    var formattedDate = StartDate.ToString("O");
                    var dateIndex = formattedDate.LastIndexOf(":");
                    var date = formattedDate.Remove(dateIndex, 1);
                    var timeSpent = String.Format("{0}h {1}m", Hour, minute);
                    var result = await jiraService.LogWork(issueKey, date, timeSpent, Comment);
                    StartDate = StartDate.AddDays(1);
                }
            }
            else
            {
                //TODO:Convert date format
                var dateIndex = StartDate.ToString("O").LastIndexOf(":");
                var date = StartDate.ToString("O").Remove(dateIndex, 1);
                var timeSpent = String.Format("{0}h {1}m", Hour, minute);
                var result = await jiraService.LogWork(issueKey, date, timeSpent, Comment);
            }
            navigationService.GoBack();
        }
    }
}
{'fraction_non_alphanumeric': 0.07892217206948433, 'fraction_numerical': 0.0015045821365066339, 'mean_word_length': 1.117578916883869, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5537192', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1653, 'n_words': 392}