Skip to content

Commit cca833c

Browse files
committed
add a software to manage leetcode issues
1 parent 8100e8c commit cca833c

File tree

64 files changed

+110453
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+110453
-0
lines changed

LeetcodeManager/App.config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6+
</configSections>
7+
<startup>
8+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
9+
</startup>
10+
<entityFramework>
11+
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
12+
<providers>
13+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
14+
</providers>
15+
</entityFramework>
16+
</configuration>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using LeetcodeManager.Controller;
2+
using LeetcodeManager.DAL;
3+
using LeetcodeManager.Entity;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Data.Entity;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace LeetcodeManager.Controller
12+
{
13+
public class ProblemInputController
14+
{
15+
private readonly TagDAL _tagDal = new TagDAL();
16+
private readonly ProblemDAL _problemDal = new ProblemDAL();
17+
18+
public bool IsNew(Problem problem)
19+
{
20+
if (problem == null) return true;
21+
return _problemDal.IsNew(problem);
22+
}
23+
public Problem SaveProblem(Problem problem)
24+
{
25+
return _problemDal.CreateAProblem(problem);
26+
}
27+
public void UpdateProblems()
28+
{
29+
_problemDal.UpdateProblems();
30+
}
31+
public void DeleteProblem(Problem problem)
32+
{
33+
_problemDal.DeleteAProblem(problem);
34+
}
35+
public void DeleteProblems(IList<Problem> problems)
36+
{
37+
_problemDal.DeleteProblems(problems);
38+
}
39+
}
40+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using LeetcodeManager.DAL;
2+
using LeetcodeManager.Entity;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace LeetcodeManager.Controller
11+
{
12+
public class TagInputController
13+
{
14+
private readonly TagDAL _tagDAL = new TagDAL();
15+
public DataTable TagsToTable()
16+
{
17+
var tagTable = new DataTable();
18+
tagTable.Columns.AddRange(new DataColumn[]{
19+
new DataColumn("TagId",typeof(int)),
20+
new DataColumn("Name",typeof(string))
21+
});
22+
IEnumerable<Tag> tags = _tagDAL.QueryAllTags();
23+
foreach (var tag in tags)
24+
{
25+
var row = tagTable.NewRow();
26+
row["TagId"] = tag.TagId;
27+
row["Name"] = tag.Name;
28+
tagTable.Rows.Add(row);
29+
}
30+
return tagTable;
31+
}
32+
public Tag GetATagByName(string name)
33+
{
34+
return _tagDAL.QueryTagByName(name);
35+
}
36+
public Tag GetATagById(int id)
37+
{
38+
return _tagDAL.QueryTagById(id);
39+
}
40+
public IEnumerable<Tag> GetAllTags()
41+
{
42+
return _tagDAL.QueryAllTags();
43+
}
44+
public bool IsNew(Tag tag)
45+
{
46+
if (tag == null) return true;
47+
return _tagDAL.IsNew(tag);
48+
}
49+
50+
public Tag SaveTagToDb(Tag tag)
51+
{
52+
return _tagDAL.CreateATag(tag);
53+
}
54+
55+
public void DeleteTag(Tag tag)
56+
{
57+
_tagDAL.DeleteATag(tag);
58+
}
59+
60+
public void UpdateTagName(Tag tag)
61+
{
62+
_tagDAL.UpdateATagName(tag);
63+
}
64+
}
65+
}

LeetcodeManager/DAL/BaseDAL.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using LeetcodeManager.DAL;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace LeetcodeManager.DAL
9+
{
10+
public class BaseDAL
11+
{
12+
protected static MyDb _db;
13+
protected BaseDAL()
14+
{
15+
_db = _db ?? new MyDb();
16+
}
17+
}
18+
}

LeetcodeManager/DAL/MyDb.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using LeetcodeManager.Entity;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Data.Entity;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace LeetcodeManager.DAL
10+
{
11+
public class MyDb:DbContext
12+
{
13+
public DbSet<Tag> Tags { get; set; }
14+
public DbSet<Problem> Problems { get; set; }
15+
16+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
17+
{
18+
modelBuilder.Entity<Tag>().HasMany(p => p.Problems).WithMany(r => r.Tags).Map(
19+
t => t.ToTable("TagProblem").
20+
MapLeftKey("TagId").
21+
MapRightKey("ProblemId"));
22+
}
23+
}
24+
}

LeetcodeManager/DAL/ProblemDAL.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using LeetcodeManager.Entity;
2+
using LeetcodeManager.Lib;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data.Entity;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace LeetcodeManager.DAL
11+
{
12+
public class ProblemDAL:BaseDAL
13+
{
14+
public IEnumerable<Tag> QueryAllTags()
15+
{
16+
DbSet<Tag> tags = _db.Tags;
17+
if (tags == null) return new List<Tag>();
18+
return tags.AsEnumerable<Tag>();
19+
}
20+
21+
public bool IsNew(Problem problem)
22+
{
23+
return problem.ProblemId == 0;
24+
}
25+
public Problem CreateAProblem(Problem problem)
26+
{
27+
if (!IsNew(problem)) return problem;
28+
_db.Problems.Add(problem);
29+
_db.SaveChanges();
30+
var problems = _db.Problems.OrderByDescending(r => r.ProblemId).AsEnumerable<Problem>();
31+
if (!SysHelper.CollectionNullOrEmpty<Problem>(problems))
32+
return problems.First();
33+
return new Problem();
34+
}
35+
public void UpdateProblems()
36+
{
37+
_db.SaveChanges();
38+
}
39+
40+
public void DeleteAProblem(Problem problem)
41+
{
42+
_db.Problems.Remove(problem);
43+
_db.SaveChanges();
44+
}
45+
46+
public void DeleteProblems(IList<Problem> problems)
47+
{
48+
int cnt = problems.Count();
49+
for(int i=0;i<cnt;i++)
50+
{
51+
_db.Problems.Remove(problems[i]);
52+
}
53+
_db.SaveChanges();
54+
}
55+
56+
}
57+
}

LeetcodeManager/DAL/TagDAL.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using LeetcodeManager.Entity;
2+
using LeetcodeManager.Lib;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data.Entity;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace LeetcodeManager.DAL
11+
{
12+
public class TagDAL:BaseDAL
13+
{
14+
public IEnumerable<Tag> QueryAllTags()
15+
{
16+
DbSet<Tag> tags = _db.Tags;
17+
if (tags == null) return new List<Tag>();
18+
return tags.AsEnumerable<Tag>();
19+
}
20+
public Tag QueryTagByName(string name)
21+
{
22+
DbSet<Tag> tags = _db.Tags;
23+
if (tags == null) return new Tag();
24+
return tags.FirstOrDefault(r => r.Name == name);
25+
}
26+
27+
public Tag QueryTagById(int id)
28+
{
29+
DbSet<Tag> tags = _db.Tags;
30+
if (tags == null) return new Tag();
31+
return tags.FirstOrDefault(r => r.TagId == id);
32+
}
33+
34+
public bool IsNew(Tag tag)
35+
{
36+
return tag.TagId == 0;
37+
}
38+
39+
public Tag CreateATag(Tag tag)
40+
{
41+
if (!IsNew(tag)) return tag;
42+
_db.Tags.Add(tag);
43+
_db.SaveChanges();
44+
var tags = _db.Tags.OrderByDescending(r => r.TagId).AsEnumerable<Tag>();
45+
if (!SysHelper.CollectionNullOrEmpty<Tag>(tags))
46+
return tags.First();
47+
return new Tag();
48+
}
49+
50+
public void DeleteATag(Tag tag)
51+
{
52+
_db.Tags.Remove(tag);
53+
_db.SaveChanges();
54+
}
55+
56+
public void UpdateATagName(Tag tag)
57+
{
58+
Tag tagdb = _db.Tags.FirstOrDefault(r => r.TagId == tag.TagId);
59+
if (tag != null)
60+
tagdb.Name = tag.Name;
61+
_db.SaveChanges();
62+
}
63+
}
64+
}

LeetcodeManager/Entity/Problem.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace LeetcodeManager.Entity
9+
{
10+
public class Problem
11+
{
12+
public int ProblemId { get; set; }
13+
[MaxLength(50)]
14+
[Required(ErrorMessage = "Title is required.")]
15+
public string Title { get; set; }
16+
public string LtUrl { get; set; }
17+
public string CsdnAddress { get; set; }
18+
public string Content { get; set; }
19+
public virtual IList<Tag> Tags { get; set; }
20+
}
21+
}

LeetcodeManager/Entity/Tag.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Data.Entity;
7+
using System.ComponentModel.DataAnnotations;
8+
9+
namespace LeetcodeManager.Entity
10+
{
11+
public class Tag
12+
{
13+
public int TagId { get; set; }
14+
[MaxLength(30)]
15+
public string Name { get; set; }
16+
17+
public virtual IList<Problem> Problems { get; set; }
18+
}
19+
}

0 commit comments

Comments
 (0)