public async Task <bool> SalvaEsame(int idStudIscritto, int idModulo, int voto, DateTime?data)
        {
            bool   result = false;
            Modulo m      = await _db.Moduli.FindAsync(idModulo);

            StudenteIscritto studIscr = await _db.StudentiIscritti.FindAsync(idStudIscritto);

            if (m != null && studIscr != null && voto >= 0 && voto <= 100)
            {
                var q1 = await(from studente in _db.Studenti
                               join studenteIscritto in _db.StudentiIscritti on studente.Id equals studenteIscritto.IdStudente
                               join esame in _db.Esami on studenteIscritto.Id equals esame.IdStudenteIscritto
                               where studenteIscritto.Id == idStudIscritto && esame.IdModulo == idModulo
                               select esame).ToListAsync();
                if (q1.Count == 0)
                {
                    _db.Esami.Add(new Esame {
                        IdModulo = idModulo, Voto = voto, IdStudenteIscritto = idStudIscritto, Data = data
                    });
                }
                else
                {
                    q1[0].Voto = voto; q1[0].Data = data;
                }

                await _db.SaveChangesAsync();

                result = true;
            }
            return(result);
        }
Example #2
0
        public async Task <bool> EliminaStudente(Studente s)
        {
            bool             result     = false;
            StudenteIscritto iscrizione = await _db.StudentiIscritti.FirstOrDefaultAsync(x => x.IdStudente == s.Id);

            if (iscrizione == null)
            {
                _db.Studenti.Remove(s);
                await _db.SaveChangesAsync();

                result = true;
            }
            return(result);
        }
Example #3
0
        public async Task <bool> EliminaCorso(Corso c)
        {
            bool   result = false;
            Modulo m      = await _db.Moduli.FirstOrDefaultAsync(x => x.IdCorso == c.Id);

            StudenteIscritto s = await _db.StudentiIscritti.FirstOrDefaultAsync(x => x.IdCorso == c.Id);

            if (m == null && s == null)
            {
                _db.Corsi.Remove(c);
                await _db.SaveChangesAsync();

                result = true;
            }
            return(result);
        }
Example #4
0
        public async Task <bool> EliminaIscrizione(int id)
        {
            bool  result = false;
            Esame e      = await _db.Esami.FirstOrDefaultAsync(x => x.IdStudenteIscritto == id);

            if (e == null)
            {
                StudenteIscritto s = await _db.StudentiIscritti.FindAsync(id);

                _db.StudentiIscritti.Remove(s);
                await _db.SaveChangesAsync();

                result = true;
            }
            return(result);
        }
Example #5
0
        public async Task <bool> SalvaIscrizione(StudenteIscritto s)
        {
            bool  result = false;
            Corso c      = await _db.Corsi.FindAsync(s.IdCorso);

            Studente st = await _db.Studenti.FindAsync(s.IdStudente);

            if (c != null && st != null)
            {
                _db.StudentiIscritti.Add(s);
                await _db.SaveChangesAsync();

                result = true;
            }
            return(result);
        }