Ejemplo n.º 1
0
        public int Save(Task task)
        {
            TodoListDbEntities db = new TodoListDbEntities();
            Task dbTask;
            if (task.Id > 0)
            {
                dbTask = db.Tasks.Find(task.Id);
                if (dbTask != null)
                {
                    dbTask.Name = task.Name;
                    dbTask.DueDate = task.DueDate;
                    dbTask.IsCompleted = task.IsCompleted;
                    dbTask.Priority = task.Priority;
                    dbTask.ProjectId = task.ProjectId;
                    dbTask.Changed = DateTime.Now;
                }
            }
            else
            {
                task.Created = DateTime.Now;
                task.Changed = DateTime.Now;
                dbTask = db.Tasks.Add(task);
            }

            db.SaveChanges();
            UpdateProjectCount(task.ProjectId, db);
            return dbTask.Id;
        }
Ejemplo n.º 2
0
 public bool Delete(int id)
 {
     TodoListDbEntities db = new TodoListDbEntities();
     Task task = db.Tasks.Find(id);
     if (task != null)
     {
         db.Tasks.Remove(task);
         db.SaveChanges();
     }
     return true;
 }
Ejemplo n.º 3
0
 public bool Delete(int id)
 {
     TodoListDbEntities db = new TodoListDbEntities();
     Project project = db.Projects.Find(id);
     if (project !=null)
     {
         db.Projects.Remove(project);
         db.SaveChanges();
     }
     return true;
 }
Ejemplo n.º 4
0
 public int Save(Project project)
 {
     TodoListDbEntities db = new TodoListDbEntities();
     Project dbProject ;
     if (project.Id > 0)
     {
         dbProject = db.Projects.Find(project.Id);
         if (dbProject != null)
         {
             dbProject.Name = project.Name;
             dbProject.Changed = DateTime.Now;
         }
     }
     else
     {
         project.Created = DateTime.Now;
         project.Changed = DateTime.Now;
         dbProject = db.Projects.Add(project);  
     }
   
     db.SaveChanges();
     return dbProject.Id;
 }
Ejemplo n.º 5
0
 public bool MarkComplete(Task task)
 {
     TodoListDbEntities db = new TodoListDbEntities();
     Task dbTask = db.Tasks.Find(task.Id);
     if (dbTask != null)
     {
         dbTask.IsCompleted = true;
         db.SaveChanges();
         int projectId = dbTask.ProjectId;
         UpdateProjectCount(projectId, db);
     }
     return true;
 }
Ejemplo n.º 6
0
 private static void UpdateProjectCount(int projectId, TodoListDbEntities db)
 {
     int unfinished = db.Tasks.Count(x => x.ProjectId == projectId && x.IsCompleted == false);
     Project dbProject = db.Projects.Find(projectId);
     dbProject.Count = unfinished;
     db.SaveChanges();
 }