2020-09-15 12:31:52 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-09-20 03:43:08 +00:00
|
|
|
using Snootalogue.Data;
|
|
|
|
using System.Runtime;
|
2020-09-15 12:31:52 +00:00
|
|
|
|
|
|
|
namespace Snootalogue.Models {
|
|
|
|
public class Document {
|
2020-09-20 03:43:08 +00:00
|
|
|
public string ID { get; set; }
|
2020-09-15 12:31:52 +00:00
|
|
|
public string Filename { get; set; }
|
|
|
|
public string Hash { get; set; }
|
2020-09-16 01:43:55 +00:00
|
|
|
[UIHint("FileSize")]
|
2020-09-15 12:31:52 +00:00
|
|
|
public long Size { get; set; }
|
|
|
|
|
|
|
|
public string Title { get; set; }
|
2020-09-16 01:43:55 +00:00
|
|
|
[UIHint("CommaSeparatedList")]
|
2020-09-15 12:31:52 +00:00
|
|
|
public List<string> Authors { get; set; }
|
|
|
|
public string Category { get; set; }
|
2020-09-17 13:37:11 +00:00
|
|
|
[Display(Name = "Date added")]
|
2020-09-15 12:31:52 +00:00
|
|
|
public DateTime DateAdded { get; set; }
|
2020-09-16 01:43:55 +00:00
|
|
|
[UIHint("CommaSeparatedList")]
|
2020-09-15 12:31:52 +00:00
|
|
|
public List<string> Tags { get; set; }
|
|
|
|
public Boolean Read { get; set; }
|
2020-09-17 13:37:11 +00:00
|
|
|
public string Notes { get; set; }
|
2020-09-20 03:43:08 +00:00
|
|
|
|
|
|
|
public static string NewID(SnootalogueContext context) {
|
|
|
|
// - no vowels to avoid (most) (non-welsh) naughty words
|
|
|
|
// - no l1I because it's always confusing
|
|
|
|
// - no 0
|
|
|
|
string idCharacters = "bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ23456789";
|
|
|
|
var rng = new Random();
|
|
|
|
var collision = true;
|
|
|
|
string id = "";
|
|
|
|
while (collision) {
|
|
|
|
id = "";
|
|
|
|
for (var i = 0; i < 7; i++) {
|
|
|
|
id += idCharacters[rng.Next(idCharacters.Length)];
|
|
|
|
}
|
|
|
|
collision = context.Document.Find(id) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2020-09-15 12:31:52 +00:00
|
|
|
}
|
|
|
|
}
|