private void CreateAOrUpdateTask(object o) { if (string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(DueDate)) { MessageBox.Show("Required fields can not be empty", Enums.MessageTypes.Warning.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); return; } try { var task = new TaskModel() { IdTask = (IdTask.HasValue ? (int)this.IdTask : 0), Title = this.Title, Description = this.Description, State = Enums.StateTypes.Active, DueDate = DateTime.ParseExact(this.DueDate, "dd/MM/yyyy", CultureInfo.CurrentCulture), CreationDate = DateTime.Now }; if (!IdTask.HasValue) { if (taskBL.Create(task)) { MessageBox.Show("Task added correctly", Enums.MessageTypes.Success.ToString(), MessageBoxButton.OK, MessageBoxImage.Information); Cancel(o); } else { MessageBox.Show("Something went wrong", Enums.MessageTypes.Warning.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } } else { if (taskBL.Update((int)IdTask, task)) { MessageBox.Show("Task update correctly", Enums.MessageTypes.Success.ToString(), MessageBoxButton.OK, MessageBoxImage.Information); Cancel(o); } else { MessageBox.Show("Something went wrong", Enums.MessageTypes.Warning.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Enums.MessageTypes.Error.ToString(), MessageBoxButton.OK, MessageBoxImage.Error); return; } }