-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTalkRepository.cs
More file actions
55 lines (48 loc) · 1.52 KB
/
TalkRepository.cs
File metadata and controls
55 lines (48 loc) · 1.52 KB
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
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CodeTalk.Domain.Contracts;
using CodeTalk.Domain.Contracts.Repositories;
using CodeTalk.Domain.Models;
using System.Data.Entity;
namespace CodeTalk.DataSource.Repositories
{
public class TalkRepository: ITalkRepository
{
private CodeTalkContext codeTalkContext;
public TalkRepository()
{
codeTalkContext = new CodeTalkContext();
}
public IQueryable<Domain.Models.Talk> GetTalks()
{
var ctx = new CodeTalkContext();
return ctx.Talks.Include("Comments");
}
public bool AddTalk(Domain.Models.Talk newTalk)
{
codeTalkContext.Talks.Add(newTalk);
codeTalkContext.SaveChanges();
return true;
}
public void EditTalk(Talk talk)
{
Talk serverTalk = codeTalkContext.Talks.FirstOrDefault(t => t.Id == talk.Id);
serverTalk.Title = talk.Title;
serverTalk.Description = talk.Description;
serverTalk.DateCreated = talk.DateCreated;
serverTalk.DateModified = DateTime.Now;
codeTalkContext.SaveChanges();
}
public void DeleteTalk(Domain.Models.Talk talk)
{
throw new NotImplementedException();
}
public Domain.Models.Talk GetTalkById(int id)
{
return codeTalkContext.Talks.FirstOrDefault(t => t.Id == id);
}
}
}