private void btnCreateTask_Click(object sender, RoutedEventArgs e) { TaskerModel.Task tsk = null; Angajat responsible = (Angajat)cmbAngajati.SelectedItem; int priority = 1; //if rbtnLow.IsChecked if ((bool)rbtnMedium.IsChecked) { priority = Convert.ToInt32(medie); } else if ((bool)rbtnMedium.IsChecked) { priority = max; } try { if (ValidateTask()) { tsk = new TaskerModel.Task() { Denumire = txtTitle.Text.Trim(), Descriere = txtDescription.Text != null?txtDescription.Text.Trim() : null, Deadline = (DateTime)pickerDeadline.SelectedDate, Status = 1, DataCrearii = System.DateTime.Now, IdAngajat = responsible.Id, Prioritate = priority }; ctx.Tasks.Add(tsk); ctx.SaveChanges(); MessageBox.Show("Task Created Successfully!"); this.Close(); } } catch (DataException ex) { MessageBox.Show(ex.Message); } }
private void IncreasePriority(object sender, RoutedEventArgs e) { ListViewItem listViewItem = FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource); TaskerModel.Task tsk = (TaskerModel.Task)listViewItem.DataContext; var getTask = ctx.Tasks.Find(tsk.Id); var taskAbove = ctx.Tasks.Where(x => x.Status == getTask.Status && x.Prioritate > getTask.Prioritate).FirstOrDefault(); getTask.Prioritate = (taskAbove != null) ? taskAbove.Prioritate + 1 : getTask.Prioritate + 1; ctx.SaveChanges(); refresh(sender, e); }