public async Task <ActionResult <Fichiers> > PostFichiers(Fichiers fichiers) { _context.Fichiers.Add(fichiers); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFichiers", new { id = fichiers.Id }, fichiers)); }
public async Task <IActionResult> PutFichiers(int id, Fichiers fichiers) { if (id != fichiers.Id) { return(BadRequest()); } _context.Entry(fichiers).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FichiersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult ObtenirPublication(int?id) { PUBLICATION pub = null; try { if (id == null) { throw new ArgumentNullException("id"); } pub = db.GetPublication(id).First(); } catch { TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.idPublicationInvalide); } if (pub != null) { if (User.IsInRole("admin") || ((List <SECTEUR>)Session["lstSect"]).Any(s => s.ID == pub.IDSECTEUR)) { var cd = new ContentDisposition { FileName = pub.NOMFICHIERORIGINAL, Inline = false }; Response.AppendHeader("Content-Disposition", cd.ToString()); try { return(File(IOFile.ReadAllBytes(Fichiers.CheminEnvois(pub.NOMFICHIERSERVEUR)), pub.NOMFICHIERORIGINAL)); } catch (IOException) { TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.publicationErreurFichier); } } else { TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.accesRefuse); } } return(RedirectToAction("Publications", "Sectoriel")); }
public ActionResult AjoutPublication(PUBLICATION envoiPubli) { if (ModelState.IsValid) { try { HttpPostedFileBase fichier = envoiPubli.fichier; string mimetype = fichier.ContentType; string nomOriginal = Fichiers.GetNomOriginal(fichier.FileName); string nomServeur = Fichiers.GetNomServeur(fichier.FileName); fichier.SaveAs(Fichiers.CheminEnvois(nomServeur)); ObjectParameter idNouvPub = new ObjectParameter("idpub", typeof(int)); db.AjouterPublication(envoiPubli.TITRE, envoiPubli.DESCRIPTION, envoiPubli.IDSECTEUR, envoiPubli.IDSUJET, nomOriginal, nomServeur, mimetype, WebSecurity.CurrentUserId, idNouvPub); List <String> motsCles = envoiPubli.TITRE.Split(new Char[] { ' ' }).ToList(); if (!String.IsNullOrEmpty(envoiPubli.motcles)) { motsCles.AddRange(envoiPubli.motcles.Split(new Char[] { ' ' })); } db.UpdateMotsClesPub((int)idNouvPub.Value, MotsCles.TraiterMotsCles(motsCles)); TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.SUCCES, Resources.Publication.publicationAjoutee); return(RedirectToAction("Publications", "Sectoriel")); } catch (Exception ex) { TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.publicationErreur + " (" + ex.GetType() + ")"); } } List <GetSecteurs_Result> listeSecteurs = db.GetSecteursLocalises(Session); List <GetSujetsPublication_Result> listeSujetsPub = db.GetSujetsPublicationLocalises(Session).ToList(); ViewData[Constantes.CLE_SECTEURS] = listeSecteurs; ViewData[Constantes.CLE_SUJETSPUBLICATION] = listeSujetsPub; return(View(envoiPubli)); }
public async Task <IActionResult> Upload(int id) { try { var file = Request.Form.Files[0]; var folderName = Path.Combine("Resources", "Images"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fullPath = Path.Combine(pathToSave, fileName); var dbPath = Path.Combine(folderName, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } var user = _context.StudentTable.FromSqlInterpolated($"SELECT * FROM dbo.student_table").Where(res => res.StudentId == id).FirstOrDefault(); var fichier = new Fichiers(); fichier.Nom = user.FirstName; fichier.Status = user.Type; fichier.NomFichier = fileName; _context.Fichiers.Add(fichier); await _context.SaveChangesAsync(); return(Ok(new { dbPath })); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, $"Internal server error: {ex}")); } }
public ActionResult SupprimerPublication(int?id, string confirmer, string annuler) { if (!String.IsNullOrEmpty(confirmer) && String.IsNullOrEmpty(annuler)) { PUBLICATION pub = null; try { if (id == null) { throw new ArgumentNullException("id"); } pub = db.GetPublication(id).First(); } catch { TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.idPublicationInvalide); } if (pub != null) { db.SupprimerPublication(id); string cheminEnvoi = Fichiers.CheminEnvois(pub.NOMFICHIERSERVEUR); if (IOFile.Exists(cheminEnvoi)) { IOFile.Delete(cheminEnvoi); } TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.SUCCES, Resources.Publication.publicationSupprimee); } } return(RedirectToAction("Publications", "Sectoriel")); }