public async Task <IActionResult> PutAdministrateur(int id, Administrateur administrateur)
        {
            if (id != administrateur.Id)
            {
                return(BadRequest());
            }

            _context.Entry(administrateur).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdministrateurExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAffectation(int id, int id2, Affectation affectation)
        {
            if (id != affectation.IdFiliere && id2 != affectation.IdMatiere)
            {
                return(BadRequest());
            }

            _context.Entry(affectation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AffectationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <IActionResult> PutFiliere(int id, Filiere filiere)
        {
            if (id != filiere.Id)
            {
                return(BadRequest());
            }

            _context.Entry(filiere).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FiliereExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
        public async Task <IActionResult> PutEnseignant(int id, Enseignant enseignant)
        {
            if (id != enseignant.Id)
            {
                return(BadRequest());
            }

            _context.Entry(enseignant).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EnseignantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        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.Utilisateur.FromSqlInterpolated($"SELECT * FROM dbo.Utilisateur").Where(res => res.Id == id).FirstOrDefault();
                    var fichier = new Fichiers();
                    fichier.Nom        = user.Nom;
                    fichier.Status     = user.Status;
                    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}"));
            }
        }