Example #1
0
        protected override async Task <bool> DeleteItem()
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("¿Estas seguro de borrar la tarea?", "Confirmación de borrado", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                using (var db = new TimeTrackerModel())
                {
                    try
                    {
                        db.Tasks.Attach(SelectedItem);
                        db.Entry(SelectedItem).State = EntityState.Deleted;

                        var rows = await db.SaveChangesAsync();

                        if (rows > 0)
                        {
                            Status = SelectedItem.IdParent != null ? "Subtarea borrada correctamente" : "Tarea borrada correctamente";
                            _items.Remove(SelectedItem);
                        }
                        return(rows > 0);
                    } catch (Exception ex)
                    {
                        this.Status = "Error al borrar Tarea";
                    }
                }
            }
            return(false);
        }
        //DELETE
        protected override async Task <bool> DeleteItem()
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("¿Estas seguro de borrar el proyecto?", "confirmación de borrado", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                using (var db = new TimeTrackerModel())
                {
                    db.Projects.Attach(SelectedItem);
                    db.Entry(SelectedItem).State = EntityState.Deleted;
                    var rows = await db.SaveChangesAsync();

                    if (rows > 0)
                    {
                        _items.Remove(SelectedItem);
                        Status = "Proyecto borrado correctamente";
                    }
                    return(rows > 0);
                }
            }
            return(false);
        }
        public async Task <bool> Save()
        {
            using (var db = new TimeTrackerModel())
            {
                if (Project.Id == 0)
                {
                    db.Projects.Add(Project);
                }
                else
                {
                    db.Projects.Attach(Project);
                    db.Entry(Project).State = EntityState.Modified;
                }

                var rows = await db.SaveChangesAsync();

                Saved = rows == 1;

                window?.Close();

                return(Saved);
            }
        }