示例#1
0
        private void Button_Click_AddTask(object sender, RoutedEventArgs e)
        {
            //Check for length
            var taskToAdd = AddTask.Text;

            if (taskToAdd.Length < 5)
            {
                MessageBox.Show("The task should be at least 5 letters long!");
                return;
            }

            //adding the task to DB
            using (var context = new EverydayJournalContext())
            {
                var person = context.People.Find(LoggerUtility.UserId);
                var task   = new Task()
                {
                    Name = taskToAdd,
                    Date = new Date()
                    {
                        ExactDate = DateTime.Now
                    },
                    Person = person
                };

                context.Tasks.AddOrUpdate(task);
                context.SaveChanges();
                MessageBox.Show("Successfully added task");
                //Refresh the page
                TasksPage tasksPage = new TasksPage();
                this.NavigationService?.Navigate(tasksPage);
            }
        }
示例#2
0
        public async System.Threading.Tasks.Task AddTagsToTask(Task task, IEnumerable <string> tags)
        {
            await using var context = ContextFactory.CreateDbContext(ConnectionString);
            var connection = context.Database.GetDbConnection();
            var command    = connection.CreateCommand();
            var parameters = (tags as string[] ?? tags.ToArray()).Select(t => $"\'{t}\'");

            command.CommandText = $"call add_tags_to_task({task.Id}, {string.Join(',', parameters)})";

            try
            {
                await connection.OpenAsync();

                await command.ExecuteNonQueryAsync();
            }
            catch (PostgresException ex)
            {
                switch (ex.SqlState)
                {
                case PgsqlErrors.RaiseException:
                    throw new RepositoryException(ex.MessageText);
                }

                throw;
            }
        }
        public ActionResult DeleteTask(Task task)
        {
            this.repository.DeleteTask(task.ListId, task.TaskId);

            TaskList list = this.repository.GetTaskList(task.ListId);

            return Json(true);
        }
        public ActionResult UpdateTask(Task task)
        {
            TaskList list = this.repository.GetTaskList(task.ListId);
            Task oldTask = this.repository.GetTask(task.TaskId, list.ListId);

            this.repository.UpdateTask(task);            

            return Json(task);
        }
示例#5
0
        public async System.Threading.Tasks.Task UpdateTask(Task task)
        {
            await using var context = ContextFactory.CreateDbContext(ConnectionString);
            var entry = context.Tasks.FirstOrDefault(t => t.Id == task.Id)
                        ?? throw new RepositoryException("Такой задачи не существует.");

            context.Entry(entry).CurrentValues.SetValues(task);
            await context.SaveChangesAsync();
        }
        public ActionResult CreateTask(Task task)
        {
            if (task.StartDate == DateTime.MaxValue)
            {
                task.StartDate = DateTime.Now;
            }

            this.repository.CreateTask(task);

            return Json(task);
        }
示例#7
0
        public async System.Threading.Tasks.Task DeleteTaskTags(Task task, IEnumerable <string> tags)
        {
            await using var context = ContextFactory.CreateDbContext(ConnectionString);
            var connection = context.Database.GetDbConnection();
            var command    = connection.CreateCommand();
            var parameters = (tags as string[] ?? tags.ToArray()).Select(t => $"\'{t}\'");

            command.CommandText = $"call delete_task_tags({task.Id}, {string.Join(',', parameters)})";
            await connection.OpenAsync();

            await command.ExecuteNonQueryAsync();
        }
示例#8
0
        // [EnableCors("AllowAll")]
        public async Task <IActionResult> CreateTask([FromBody] Models.Task item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            ApplicationDbContext.Tasks.Add(item);
            await ApplicationDbContext.SaveChangesAsync();

            return(this.CreatedAtRoute("GetTaskByProfileId", new { Controller = "TasksController", profileId = item.ProfileId }, item));
        }
示例#9
0
        public async Task <ActionResult> PostTask([FromBody] Model.Task task, long projectId)
        {
            var user = await userManager.GetUserAsync(HttpContext.User);

            task.CreationDate = DateTime.Now;
            task.AuthorId     = user.Id;
            task.Project      = await dbContext.Projects.FindAsync(projectId);

            dbContext.Tasks.Add(task);
            await dbContext.SaveChangesAsync();

            return(Ok(task.Id));
        }
示例#10
0
        private void RunTest(
            Test test,
            Models.Enums.TestMode testMode = Models.Enums.TestMode.Practice, Models.Task resumeTask = null)
        {
            Dictionary <string, string> appProcesses = new Dictionary <string, string>();

            appProcesses.Add("Word", "winword");
            appProcesses.Add("PowerPoint", "powerpnt");
            appProcesses.Add("Excel", "excel");

            Process[] ps = Process.GetProcessesByName(appProcesses[test.OfficeApp]);
            if (ps.Length > 0)
            {
                DialogResult result = MessageBox.Show(ps.Length.ToString() + " " + test.OfficeApp + " process(es) should be end. Do you want to end all processes?", "End Process", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    foreach (var p in ps)
                    {
                        p.Kill();
                    }
                }
                else
                {
                    return;
                }
            }

            frmLoading.Show();

            switch (test.OfficeVersion)
            {
            case "2013":
                (new frmRunTestOffice2013(this, this.txtUserName.Text, test, testMode, resumeTask)).Show();
                break;

            case "2016":
                (new frmRunTestOffice2016(this, this.txtUserName.Text, test, testMode, resumeTask)).Show();
                break;

            default:
                throw new Exception("Error");
            }

            this.Hide();
        }
示例#11
0
        private void dataGridTasks_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Models.Task task = this.dataGridTasks.Rows[e.RowIndex].DataBoundItem as Models.Task;
            Test        test = Repository.getTestById(task.TestID);

            if (task.IsCompleted)
            {
                (new frmShowResult(task, test)).ShowDialog();
                return;
            }

            if (test == null)
            {
                MessageBox.Show("Test not found");
                return;
            }
            this.RunTest(test, (Models.Enums.TestMode)task.Mode, task);
        }
示例#12
0
        public async System.Threading.Tasks.Task AddTask(Task task)
        {
            try
            {
                await using var context = ContextFactory.CreateDbContext(ConnectionString);
                await context.Tasks.AddAsync(task);

                await context.SaveChangesAsync();
            }
            catch (DbUpdateException ex)
            {
                if (ex.InnerException is PostgresException innerException)
                {
                    switch (innerException.SqlState)
                    {
                    case PgsqlErrors.RaiseException:
                        throw new RepositoryException(innerException.MessageText);
                    }
                }

                throw;
            }
        }
        public frmRunTestOffice2016(Form parent, string userName, Test test, Models.Enums.TestMode mode, Models.Task resumeTask = null) : base(parent, userName, test, mode)
        {
            InitializeComponent();

            this.groupQuestions();
            this.LoadApp();

            if (resumeTask != null)
            {
                this.Task = resumeTask;
                this.loadTask();
            }
            else
            {
                List <List <bool> > dict = new List <List <bool> >();
                foreach (var p in this.Projects)
                {
                    List <bool> l = new List <bool>();
                    for (int j = 0; j < p.Count - 1; ++j)
                    {
                        l.Add(false);
                    }
                    dict.Add(l);
                }
                this.CreateTask(dict);
            }

            this.SelectedProject = 0;
            this.loadProject();
            this.CreateDirTemp();
            this.ResizeForm();

            if (mode == Models.Enums.TestMode.Testing)
            {
                this.ucTimer.Max       = this.Test.LimitTime * 60;
                this.ucTimer.EndEvent += this.TimerEnd;
            }
            this.ucTimer.Start();
            this.labelTestName.Text = this.Test.Name + " - " + this.Mode.ToString() + " Mode";
        }
示例#14
0
        /// <param name='id'>
        /// </param>
        /// <param name='task'>
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="HttpOperationException">
        /// Thrown when the operation returned an invalid status code
        /// </exception>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse> ApiTasksByIdPutWithHttpMessagesAsync(System.Guid id, Models.Task task = default(Models.Task), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (task != null)
            {
                task.Validate();
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("id", id);
                tracingParameters.Add("task", task);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "ApiTasksByIdPut", tracingParameters);
            }
            // Construct URL
            var _baseUrl = BaseUri.AbsoluteUri;
            var _url     = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/Tasks/{id}").ToString();

            _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSettings).Trim('"')));
            // Create HTTP transport objects
            var _httpRequest = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("PUT");
            _httpRequest.RequestUri = new System.Uri(_url);
            // Set Headers


            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (task != null)
            {
                _requestContent      = SafeJsonConvert.SerializeObject(task, SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 200)
            {
                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                if (_httpResponse.Content != null)
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                }
                else
                {
                    _responseContent = string.Empty;
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
示例#15
0
        private VolunteerTask MapModel(Task model)
        {
            var vt = new VolunteerTask
            {
                Id = model.Id,
                StartTime = model.StartTime,
                EndTime = model.EndTime,
                Description = model.Description,
                Capacity = model.Capacity,
                Volunteers = new List<Volunteer>(model.Assignees.Count()),
            };

            if (model.Event != null)
            {
                vt.Event = new Models.Event {Name = model.Event.Name, ID = model.Event.ID};
            }

            if (model.Assignees != null)
            {
                model.Assignees
                     .ToList()
                     .ForEach(a => vt.Volunteers
                                     .Add(new Volunteer
                                              {
                                                  FirstName = a.FirstName,
                                                  LastName = a.LastName,
                                              }));
            }
            return vt;
        }
        protected void CreateInitialLists()
        {
            var document = this.TaskRepository.RetrieveInitialLists();

            if (document.Nodes().Count() == 0)
            {
                return;
            }

            var todoController = new TodoController();
            todoController.ControllerContext = this.ControllerContext;

            foreach (var taskList in document.Descendants("TaskList"))
            {
                var taskListName = taskList.Element("Name").Value;
                var taskListIsPublic = bool.Parse(taskList.Element("IsPublic").Value);

                var createdTaskList = this.TaskRepository.CreateList(taskListName, taskListIsPublic);

                if (createdTaskList == null || string.IsNullOrEmpty(createdTaskList.ListId))
                {
                    return;
                }

                foreach (var task in taskList.Descendants("Task"))
                {
                    var newTask = new Task
                    {
                        ListId = createdTaskList.ListId,
                        Subject = task.Element("Subject").Value,
                        DueDate = string.IsNullOrEmpty(task.Element("DueDate").Value) ? DateTime.MaxValue : DateTime.Parse(task.Element("DueDate").Value, CultureInfo.InvariantCulture),
                        IsComplete = bool.Parse(task.Element("IsComplete").Value)
                    };

                    todoController.CreateTask(newTask);
                }
            }
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='task'>
 /// </param>
 public static void ApiTasksByIdPut(this ITaskServiceAPI operations, System.Guid id, Models.Task task = default(Models.Task))
 {
     operations.ApiTasksByIdPutAsync(id, task).GetAwaiter().GetResult();
 }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='task'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task ApiTasksPostAsync(this ITaskServiceAPI operations, Models.Task task = default(Models.Task), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.ApiTasksPostWithHttpMessagesAsync(task, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='task'>
 /// </param>
 public static void ApiTasksPost(this ITaskServiceAPI operations, Models.Task task = default(Models.Task))
 {
     operations.ApiTasksPostAsync(task).GetAwaiter().GetResult();
 }
示例#20
0
        public frmShowResult(Models.Task task, Test test)
        {
            InitializeComponent();

            lblScore.Text      = task.Score.ToString();
            lblName.Text      += task.UserName;
            lblCreatedAt.Text += task.CreatedAt.ToString();
            lblTest.Text      += string.Format("{0}-{1} {2}", test.OfficeApp, test.Name, task.Mode == (int)TestMode.Practice ? "Practice" : "Testing");
            lblTime.Text      += task.UsedTime.ToString();

            List <RowResult> list = new List <RowResult>();

            int indexQuestion = 1;

            switch (test.OfficeVersion)
            {
            case "2013":

                foreach (var group in test.Questions.OrderBy(x => x.Key))
                {
                    foreach (var question in group.Value)
                    {
                        list.Add(new RowResult {
                            Title = indexQuestion.ToString() + ". " + question.Title, IsCorrected = task.Points[0][indexQuestion - 1] ? "true" : "false"
                        });
                        indexQuestion++;
                    }
                }
                break;

            case "2016":
                int indexGroup = 0;
                foreach (var group in test.Questions.OrderBy(x => x.Key))
                {
                    indexQuestion = 0;
                    foreach (var question in group.Value)
                    {
                        if (indexQuestion == 0)
                        {
                            list.Add(new RowResult
                            {
                                Title       = "PROJECT " + group.Key,
                                IsCorrected = "---"
                            });
                        }
                        else
                        {
                            list.Add(new RowResult
                            {
                                Title       = question.Title,
                                IsCorrected = task.Points[indexGroup][indexQuestion - 1] ? "true" : "false"
                            });
                        }
                        indexQuestion++;
                    }
                    indexGroup++;
                }
                break;
            }

            dataGridView.DataSource = list;
        }
示例#21
0
 public void Insert(Task task)
 {
     taskRepository.Add(task);
 }
示例#22
0
 public frmBaseRunTest(Form parent, string userName, Test test, Models.Enums.TestMode mode, Models.Task resumeTask = null)
 {
     this.Test       = test;
     this.Mode       = mode;
     this.ParentForm = parent;
     this.UserName   = userName;
 }