Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
*.mdf
*.ldf

#############
## Windows detritus
Expand Down
1 change: 1 addition & 0 deletions CodeTalk.DataSource/CodeTalk.DataSource.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CodeTalkContext.cs" />
<Compile Include="Repositories\CommentRepository.cs" />
<Compile Include="Repositories\TalkRepository.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion CodeTalk.DataSource/CodeTalkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

namespace CodeTalk.DataSource
{
class CodeTalkContext: DbContext
public class CodeTalkContext: DbContext
{
//public CodeTalkContext()
// : base("DefaultConnection")
//{
//}

public DbSet<Talk> Talks { get; set; }
public DbSet<Comment> Comments { get; set; }
}
}
54 changes: 54 additions & 0 deletions CodeTalk.DataSource/Repositories/CommentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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;

namespace CodeTalk.DataSource.Repositories
{
public class CommentRepository : ICommentRepository
{

private CodeTalkContext codeTalkContext;
public CommentRepository()
{
codeTalkContext = new CodeTalkContext();
}
public IQueryable<Comment> GetComments()
{
var ctx = new CodeTalkContext();
return ctx.Comments;
}

public bool AddComment(Domain.Models.Comment newComment)
{
codeTalkContext.Comments.Add(newComment);
codeTalkContext.SaveChanges();
return true;
}


public void EditComment(Comment comment)
{
Comment serverComment = codeTalkContext.Comments.FirstOrDefault(t => t.Id == comment.Id);
serverComment.Body = comment.Body;
serverComment.DateCreated = comment.DateCreated;
serverComment.DateModified = DateTime.Now;

codeTalkContext.SaveChanges();
}

public void DeleteComment(Comment comment)
{
throw new NotImplementedException();
}

public Domain.Models.Comment GetCommentById(int id)
{
return codeTalkContext.Comments.FirstOrDefault(t => t.Id == id);
}
}
}
36 changes: 32 additions & 4 deletions CodeTalk.DataSource/Repositories/TalkRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,51 @@
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;
return ctx.Talks.Include("Comments");
}

public bool AddTalk(Domain.Models.Talk newTalk)
{
var ctx = new CodeTalkContext();
ctx.Talks.Add(newTalk);
ctx.SaveChanges();
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);
}
}
}
3 changes: 3 additions & 0 deletions CodeTalk.Domain/CodeTalk.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -39,7 +40,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Contracts\Repositories\ICommentRepository.cs" />
<Compile Include="Contracts\Repositories\ITalkRepository.cs" />
<Compile Include="Contracts\Services\ICommentService.cs" />
<Compile Include="Contracts\Services\ITalkService.cs" />
<Compile Include="Models\Comment.cs" />
<Compile Include="Models\Talk.cs" />
Expand Down
19 changes: 19 additions & 0 deletions CodeTalk.Domain/Contracts/Repositories/ICommentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CodeTalk.Domain.Models;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTalk.Domain.Contracts.Repositories
{
public interface ICommentRepository
{
IQueryable<Comment> GetComments();
bool AddComment(Comment newComment);
void EditComment(Comment comment);
void DeleteComment(Comment comment);
Comment GetCommentById(int id);
}
}
5 changes: 3 additions & 2 deletions CodeTalk.Domain/Contracts/Repositories/ITalkRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public interface ITalkRepository
{
IQueryable<Talk> GetTalks();
bool AddTalk(Talk newTalk);


void EditTalk(Talk talk);
void DeleteTalk(Talk talk);
Talk GetTalkById(int id);
}
}
16 changes: 16 additions & 0 deletions CodeTalk.Domain/Contracts/Services/ICommentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CodeTalk.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTalk.Domain.Contracts.Services
{
public interface ICommentService
{
IList<Comment> GetComments();
bool AddComment(Comment newComment);

}
}
9 changes: 9 additions & 0 deletions CodeTalk.Domain/Models/Comment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -9,12 +10,20 @@ namespace CodeTalk.Domain.Models
public class Comment
{
public int Id { get; set; }
[Required]
public string Body { get; set; }
[Required]
public string CommenterName { get; set; }

public int TalkId { get; set; }

public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }

public Comment()
{
DateCreated = DateTime.Now;
DateModified = DateTime.Now;
}
}
}
2 changes: 1 addition & 1 deletion CodeTalk.Domain/Models/Talk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Talk()
public string Title { get; set; }
public string Description { get; set; }

ICollection<Comment> Comments { get; set; }
public ICollection<Comment> Comments { get; set; }

public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
Expand Down
1 change: 1 addition & 0 deletions CodeTalk.ServiceLayer/CodeTalk.ServiceLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommentService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TalkService.cs" />
</ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions CodeTalk.ServiceLayer/CommentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CodeTalk.Domain.Contracts.Services;
using CodeTalk.DataSource;
using CodeTalk.DataSource.Repositories;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CodeTalk.Domain.Models;
using CodeTalk.Domain.Contracts.Repositories;



namespace CodeTalk.ServiceLayer
{
public class CommentService:ICommentService
{

private ICommentRepository commentRepository;
//public CommentService(ICommentRepository commentRepository)
public CommentService()
{
this.commentRepository = new CommentRepository();
}
public IList<Comment> GetComments()
{
return commentRepository.GetComments().ToList();
}

public bool AddComment(Comment comment)
{
return commentRepository.AddComment(comment);
}

public Comment GetCommentById(int id)
{
return commentRepository.GetCommentById(id);
}
public void EditComment(Comment comment)
{
commentRepository.EditComment(comment);
}
public void DeleteTalk(Comment comment)
{
commentRepository.DeleteComment(comment);
}
}
}
36 changes: 30 additions & 6 deletions CodeTalk.ServiceLayer/TalkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,47 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CodeTalk.Domain.Models;
using CodeTalk.Domain.Contracts.Repositories;



namespace CodeTalk.ServiceLayer
{
public class TalkService:ITalkService
{
public IList<Domain.Models.Talk> GetTalks()
private ITalkRepository talkRepository;
//public TalkService(ITalkRepository talkRepository)
public TalkService()
{
var repo = new TalkRepository();
return repo.GetTalks().ToList();
this.talkRepository = new TalkRepository();
}
public IList<Talk> GetTalks()
{
//var repo = new TalkRepository();
return talkRepository.GetTalks().ToList();
}

public bool AddTalk(Talk newTalk)
{
//var repo = new TalkRepository();
return talkRepository.AddTalk(newTalk);
}

public bool AddTalk(Domain.Models.Talk newTalk)
public Talk GetTalkById(int id)
{
//var repo = new TalkRepository();
return talkRepository.GetTalkById(id);
}
public void EditTalk(Talk talk)
{
//var repo = new TalkRepository();
talkRepository.EditTalk(talk);
}
public void DeleteTalk(Talk talk)
{
var repo = new TalkRepository();
return repo.AddTalk(newTalk);
//var repo = new TalkRepository();
talkRepository.DeleteTalk(talk);
}
}
}
9 changes: 9 additions & 0 deletions CodeTalk/CodeTalk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\CommentController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\TalkController.cs" />
<Compile Include="Filters\InitializeSimpleMembershipAttribute.cs" />
Expand Down Expand Up @@ -304,6 +305,14 @@
<Content Include="Views\Web.config" />
<Content Include="Views\Talk\Index.cshtml" />
<Content Include="Views\Talk\Insert.cshtml" />
<Content Include="Views\Talk\Edit.cshtml" />
<Content Include="Views\Talk\Details.cshtml" />
<Content Include="Views\Comment\Index.cshtml" />
<Content Include="Views\Comment\Insert.cshtml" />
<Content Include="Views\Comment\Edit.cshtml" />
<Content Include="Views\Comment\Details.cshtml" />
<Content Include="Views\Home\SubmitTalk.cshtml" />
<Content Include="Views\Home\AddComment.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
Expand Down
Loading