public ActionResult Create(PostModel model, HttpPostedFileBase PubDoc) { if (ModelState.IsValid) { using (PublicationContext db = new PublicationContext()) { var publicationCard = new PublicationCard { Name = model.PostName, Author = model.PostAuthors, RealeseDate = model.RealeseDate, Rubric = db.Rubrics.FirstOrDefault(x => x.Name == model.PostTheme), Annotation = model.Annotation, Creator = User.Identity.Name }; db.PublicationCards.Add(publicationCard); db.SaveChanges(); if (PubDoc != null && PubDoc.ContentLength > 0) { string fileName = "publication(" + publicationCard.ID + ").pdf"; PubDoc.SaveAs(Server.MapPath("~/Documents/" + fileName)); } } } else { return(RedirectToAction("BadRequest", "Error")); } return(RedirectToAction("MyPublications", "Manage")); }
internal void SetTocAnchors(XDocument tocDocument) { Console.WriteLine("setting TOC chapter anchors..."); var xhtml = PublicationNamespaces.Xhtml; var anchors = tocDocument.Root .Element(xhtml + "body") .Element(xhtml + "div") .Elements(xhtml + "a"); XElement templatedChapterElement = null; var newChapterElementList = new List <XElement>(); var hrefTemplate = GetTOCHrefTemplate(); _chapterSet.Keys .Select((chapterId, i) => new { chapterId, i }) .ForEachInEnumerable(a => { var chapterId = a.chapterId; var i = a.i; var chapterElement = anchors.SingleOrDefault(item => { var href = item.Attribute("href").Value; return(href == string.Format(hrefTemplate, chapterId)); }); var canAddNavPoint = (chapterElement == null) && (i > 0); var isFirstChapterIdError = (chapterElement == null) && (i == 0); var isFirstChapterId = (chapterElement != null) && (i == 0); if (isFirstChapterIdError) { PublicationContext.Throw(string.Format("ERROR: cannot find templated element {0}", chapterId)); } else if (isFirstChapterId) { templatedChapterElement = chapterElement; this.SetTocAnchor(templatedChapterElement, chapterId); } else if (canAddNavPoint) { var @new = GetTOCAnchor(chapterId); this.SetTocAnchor(@new, chapterId); newChapterElementList.Add(new XElement(xhtml + "br")); newChapterElementList.Add(@new); } }); if (!newChapterElementList.Any()) { return; } Console.WriteLine("adding new elements under templated element..."); templatedChapterElement.AddAfterSelf(newChapterElementList.ToArray()); }
internal void SetManifestItemElementsForChapters() { Console.WriteLine("setting manifest item elements for chapters..."); var opf = PublicationNamespaces.IdpfOpenPackagingFormat; var items = _idpfDocument.Root .Element(opf + "manifest") .Elements(opf + "item"); XElement templatedChapterElement = null; var newChapterElementList = new List <XElement>(); _chapterSet.Keys .Select((chapterId, i) => new { chapterId, i }) .ForEachInEnumerable(a => { var chapterId = a.chapterId; var i = a.i; var chapterElement = items.SingleOrDefault(item => { var id = item.Attribute("id").Value; return(chapterId.Equals(id)); }); var canAddNavPoint = (chapterElement == null) && (i > 0); var isFirstChapterIdError = (chapterElement == null) && (i == 0); var isFirstChapterId = (chapterElement != null) && (i == 0); if (isFirstChapterIdError) { PublicationContext.Throw(string.Format("ERROR: cannot find templated element {0}", chapterId)); } else if (isFirstChapterId) { templatedChapterElement = chapterElement; this.SetManifestItem(templatedChapterElement, chapterId); } else if (canAddNavPoint) { var @new = GetManifestItem(chapterId); this.SetManifestItem(@new, chapterId); newChapterElementList.Add(@new); } }); if (!newChapterElementList.Any()) { return; } Console.WriteLine("adding new elements under templated element..."); templatedChapterElement.AddAfterSelf(newChapterElementList.ToArray()); }
public async Task Comment_Content_Length_Longer_Than_MaxLength() { // Setup var validator = new MaxLengthValidator(5); var content = "Hello_Hello"; var context = new PublicationContext(content); // Act var result = await validator.ValidateAsync(context); // Assert Assert.IsFalse(result.Successed); }
public async Task Publication_Content_Length_Equal_MaxLength() { // Setup var validator = new MaxLengthValidator(5); var content = "Hello"; var context = new PublicationContext(content); // Act var result = await validator.ValidateAsync(context); // Assert Assert.IsTrue(result.Successed); }
public async Task Publication_Content_Length_Shorter_Than_MinLength() { // Setup var validator = new MinLengthValidator(5); var content = "Hi"; var context = new PublicationContext(content); // Act var result = await validator.ValidateAsync(context); // Assert Assert.IsFalse(result.Successed); }
internal void SetChapterNavPoints(IEnumerable <XElement> navPoints) { Console.WriteLine("setting navPoint elements for chapters..."); XElement templatedChapterElement = null; var newChapterElementList = new List <XElement>(); _chapterSet.Keys .Select((chapterId, i) => new { chapterId, i }) .ForEachInEnumerable(a => { var chapterId = a.chapterId; var i = a.i; var chapterElement = navPoints.SingleOrDefault(navPoint => { var id = navPoint.Attribute("id").Value; return(chapterId.Equals(id)); }); var canAddNavPoint = (chapterElement == null) && (i > 0); var isFirstChapterIdError = (chapterElement == null) && (i == 0); var isFirstChapterId = (chapterElement != null) && (i == 0); if (isFirstChapterIdError) { PublicationContext.Throw(string.Format("ERROR: cannot find templated element {0}", chapterId)); } else if (isFirstChapterId) { templatedChapterElement = chapterElement; this.SetChapterNavPointText(templatedChapterElement, _chapterSet[chapterId]); } else if (canAddNavPoint) { var @new = GetNavPoint(chapterId); this.SetChapterNavPointText(@new, _chapterSet[chapterId]); newChapterElementList.Add(@new); } }); if (!newChapterElementList.Any()) { return; } Console.WriteLine("adding new elements under templated element..."); templatedChapterElement.AddAfterSelf(newChapterElementList.ToArray()); }
/// <summary> /// Generates an EPUB publication /// in the specified <see cref="PublicationContext"/>. /// </summary> /// <param name="context"></param> public static void GenerateEpub(this PublicationContext context) { if (context == null) { throw new NullReferenceException($"The expected {nameof(PublicationContext)} is not here."); } context.GenerateMeta(); context.GenerateChapters(); context.WriteTitle(); context.WriteToc(); context.WriteCopyright(); context.WriteBiography(); context.WriteDedication(); }
public async Task ContentValidator_ShouldReturnTrue_If_ForbiddenWordsNotFound() { // Setup var validation = new ForbiddenWordsValidator(new[] { "duck" }); var content = "#test text without forbidden word"; var context = new PublicationContext(content); // Act var result = await validation.ValidateAsync(context); // Assert Assert.IsTrue(result.Successed); }
public static void PrintItems(this PublicationContext PublicationContext) { PublicationContext.Database.OpenConnection(); using (var SQLiteConnection = PublicationContext.Database.GetDbConnection() as Microsoft.Data.Sqlite.SqliteConnection) using (var Transaction = SQLiteConnection.BeginTransaction()) { var Publications = PublicationContext .Publications .Include(x => x.Authors) .ThenInclude(x => x.Author) .Include(xy => xy.Projects) .Select(x => x.ToPublicatieFTS()) .ToList(); PublicationContext .ToInsertSqliteCommand(typeof(PublicatieFTS), SQLiteConnection, Transaction) .Run(Publications); Transaction.Commit(); } }
static void Main(string[] args) { DateTime before = DateTime.Now; Console.WriteLine($"Start"); using (var PublicationContext = new PublicationContext { FileName = "PublicationContext.db" }) { PublicationContext.Database.EnsureCreated(); PublicationContext.Database.Migrate(); PublicationContext.Database.OpenConnection(); var number = PublicationContext.ImportBiBXml(); Console.WriteLine($"\rTotal : {number} in {before.SinceThen()} s => {number / before.SinceThen()} / second hiha"); PublicationContext.PrintItems(); } Console.WriteLine($"{before.SinceThen()} s => end select"); }
public BookManager(PublicationContext context, ILogger <BookManager> logger) { _context = context; _Logger = logger; }
public AuthorManager(PublicationContext context, ILogger <AuthorManager> logger) { _context = context; _logger = logger; }
public HomeController(PublicationContext context) { db = context; }
public PublicationsController(PublicationContext context) { this.db = context; }