Add post, fix delete forum, fix null pointer exceptions, min max limist

on database strings
This commit is contained in:
2017-06-12 17:22:58 +03:00
parent 1249950059
commit 430d02f59e
10 changed files with 148 additions and 22 deletions

View File

@@ -8,10 +8,23 @@ namespace DAL.Domain
{
[Key]
public int FoorumId { get; set; }
[MaxLength(length: 128)]
[MinLength(length: 1)]
public string Title { get; set; }
[MaxLength(length: 256)]
[MinLength(length: 1)]
public string Description { get; set; }
[MaxLength(length: 1024)]
[MinLength(length: 1)]
public string Body { get; set; }
public DateTime CreationTime { get; set; }
[MaxLength(length: 128)]
[MinLength(length: 1)]
public string Author { get; set; }
public bool Visible { get; set; } = true;

View File

@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DAL.Domain
{
@@ -7,13 +8,22 @@ namespace DAL.Domain
{
[Key]
public int PostId { get; set; }
[MaxLength(length: 128)]
[MinLength(length: 1)]
public string Title { get; set; }
[MaxLength(length: 1024)]
[MinLength(length: 1)]
public string Body { get; set; }
public DateTime CreationTime { get; set; }
[MaxLength(length: 128)]
[MinLength(length: 1)]
public string Author { get; set; }
public int ForumId { get; set; }
public Foorum Foorum { get; set; }
}
}

View File

@@ -21,6 +21,7 @@ namespace DAL.Helpers
};
ctx.Foorums.Add(foorum);
ctx.SaveChanges();
for (int i = 0; i < 3; i++)
@@ -30,7 +31,8 @@ namespace DAL.Helpers
Title = $"Post {i}",
Author = "Karu",
Body = $"Pikk sisu {i}",
CreationTime = DateTime.Now
CreationTime = DateTime.Now,
ForumId = foorum.FoorumId
};
ctx.Posts.Add(post);
foorum.Posts.Add(post);