using System using System Collections Generic using System Linq using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcAppTEST.Models
{
public class TaskRepository
{
private MvcBugDataContext _dataContext;
public TaskRepository(MvcBugDataContext datacontext)
{
_dataContext = datacontext;
}
public IEnumerable<Task> GetTasks()
{
return _dataContext.Tasks.OrderBy(t => t.CreatedOn);
}
public Task GetTask(int taskId)
{
return _dataContext.Tasks.SingleOrDefault(t => t.TaskId == taskId);
}
public Task CreateTask(string title, string text)
{
Task t = new Task { Title = title, Text = text, StateId = 1 };
_dataContext.Tasks.InsertOnSubmit(t);
_dataContext.SubmitChanges();
return t;
}
public void UpdateTask(Task t)
{
Task dbTask = GetTask(t.TaskId);
dbTask.AssignedOn = t.AssignedOn;
dbTask.Title = t.Title;
dbTask.Text = t.Text;
dbTask.StateId = t.StateId;
_dataContext.SubmitChanges();
}
public void DeleteTask(int taskId)
{
Task dbTask = GetTask(taskId);
_dataContext.Tasks.DeleteOnSubmit(dbTask);
_dataContext.SubmitChanges();
}
}
}