public PublicationModel Get(int id) { var entity = _publicationRepository.Get(id); entity.File = _publicationFileRepository.Get(entity.FileId); return(PublicationFactory.Create(entity)); }
public void Add(PublicationModel model) { var entity = PublicationFactory.Create(model); _publicationRepository.Add(entity); model.Id = entity.Id; }
private void btn_Supprimer_Click(object sender, EventArgs e) { string confirmValue = Request.Form["confirm_delete"]; if (confirmValue == "Oui") { Button button = (Button)sender; int id = Convert.ToInt32(button.Attributes["data-id"]); Category category = cf.GetCategoryById(id); try { //Supprimer l'image string FileToDelete = Server.MapPath(category.pictureUrl); File.Delete(FileToDelete); //Supprimer les publications de la catégorie PublicationFactory pf = new PublicationFactory(cnnStr); Publication[] publicationsASupprimer = pf.GetAllByCategoryId(id); if (publicationsASupprimer.Length > 0) { string[] IDsToString = new string[publicationsASupprimer.Length]; string[] PDFs = new string[publicationsASupprimer.Length]; for (int i = 0; i < publicationsASupprimer.Length; i++) { IDsToString[i] = publicationsASupprimer[i].publicationId.ToString(); PDFs[i] = publicationsASupprimer[i].url; } pf.DeleteByArray(IDsToString); //Supprimer les PDFs for (int j = 0; j < publicationsASupprimer.Length; j++) { string PDFtoDelete = Server.MapPath(PDFs[j]); File.Delete(PDFtoDelete); } } //Supprime de la BD (deletionDate) cf.delete(id); } finally { Response.Redirect(Request.RawUrl); } } }
public void TestGetEntriesFrom() { var data = File.OpenText(TestFilePath + "DefaultBook.bib").ReadToEnd(); string s = ""; var coll = Parser.GetEntriesFrom(data, out s); var publicationCollection = new List <Publication>(); foreach (var v in coll) { Publication p = PublicationFactory.MakePublication(v); p.Owner = "johnny"; publicationCollection.Add(p); } var defaultBookInstance = ObjectBuilder.NewDefaultBook(); Assert.IsTrue(publicationCollection[0].Equals(defaultBookInstance)); }
public ActionResult UploadFile() { var f = Request.Files[0]; if (f == null) { ViewData["Message"] = ErrorMessages.FileIsNull; return(View()); } if (!(f.ContentLength > 0)) { ViewData["Message"] = ErrorMessages.FileContentLengthError; return(View()); } var stream = f.InputStream; if (!stream.CanRead) { ViewData["Message"] = ErrorMessages.CannotReadStream; return(View()); } var buffer = new byte[f.ContentLength]; var ms = new MemoryStream(); while (true) { var read = stream.Read(buffer, 0, buffer.Length); if (!(read <= 0)) { ms.Write(buffer, 0, read); } else { break; } } var arr = ms.ToArray(); var fileContent = new StringBuilder(); foreach (var b in arr) { fileContent.Append((char)b); } string errorString; var k = Parser.GetEntriesFrom(fileContent.ToString(), out errorString); var publicationCollection = new List <Publication>(); foreach (var l in k) { try { var p = PublicationFactory.MakePublication(l); if (p != null) { publicationCollection.Add(p); } } catch (Exception e) { errorString += "<br/><br/>" + e + "<br/><br/>"; } } var successCounter = 0; var failureCounter = 0; foreach (var l in publicationCollection) { try { l.Owner = HttpContext.User.Identity.Name; l.SaveOrUpdateInDatabase(); successCounter++; } catch (InvalidEntryException e) { ViewData["data"] += "<br/><br/>" + l.CiteKey + " Failed because the entry was invalid: " + e.ToString(); failureCounter++; } catch (GenericADOException) { ViewData["data"] += l.CiteKey + " Failed because the entry could not be inserted. Check that the fields' lengths do not exceed 255 characters (1500 for 'abstract')" + "<br/><br/>"; failureCounter++; } catch (Exception e) { ViewData["Message"] += "<br/><br/>" + l.CiteKey + " Failed because of an exception:" + e.Message; failureCounter++; } } ViewData["Message"] += "<br/><br/><br/>Successfully added " + successCounter + " items and failed to add " + failureCounter + " items."; return(View()); }
public ActionResult ImportEntries() { var f = Request.Form.AllKeys; string requiredKey = ""; foreach (string s in f) { if (s.Contains("EntryTextBox")) { // found key, get value and begin processing: requiredKey = s; break; } } IEnumerable <Dictionary <string, string> > entries; string errorString; if (!String.IsNullOrEmpty(requiredKey)) { entries = Parser.GetEntriesFrom(Request.Form[requiredKey], out errorString); } else { ViewData["data"] = "Error in form - 'EntryTextBox' field not found. (Will only ever see this if the form's field names change)."; return(View()); } IList <Publication> publications = new List <Publication>(); foreach (Dictionary <string, string> dictionary in entries) { var p = PublicationFactory.MakePublication(dictionary); if (p != null) { publications.Add(p); } } var successCounter = 0; var failureCounter = 0; foreach (var l in publications) { try { l.Owner = HttpContext.User.Identity.Name; l.SaveOrUpdateInDatabase(); successCounter++; } catch (InvalidEntryException e) { ViewData["data"] += l.CiteKey + " Failed because the entry was invalid: " + e.ToString() + "<br/><br/>"; failureCounter++; } catch (GenericADOException) { ViewData["data"] += l.CiteKey + " Failed because the entry could not be inserted. Check that the fields' lengths do not exceed 255 characters (1500 for 'abstract')" + "<br/><br/>"; failureCounter++; } catch (Exception e) { ViewData["data"] += l.CiteKey + " Failed because of an unexpected exception: " + e.Message + "<br/><br/>"; failureCounter++; } } ViewData["data"] += "Successfully added " + successCounter + " items and failed to add " + failureCounter + " items." + ((errorString.Length == 0) ? "" : "The parser encountered some errors: " + errorString) + "<br/><br/>"; return(View()); }