예제 #1
0
        public async Task <IActionResult> PutCategory(long id, Kategorie kategorie)
        {
            if (id != kategorie.Id)
            {
                return(BadRequest());
            }

            if (!TokenProvider.IsAdmin(User))
            {
                return(Unauthorized());
            }

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

            try
            {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KategorieExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(Ok());
        }
예제 #2
0
        public async Task <ActionResult> DeleteLehrerRaum(long id)
        {
            if (!TokenProvider.IsAdmin(User))
            {
                return(Unauthorized());
            }

            var lehrerRaum = await _context.LehrerRaum.FindAsync(id);

            if (lehrerRaum == null)
            {
                return(NotFound());
            }

            _context.LehrerRaum.Remove(lehrerRaum);
            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #3
0
        public async Task <ActionResult <Fehler> > ReportError(Fehler fehler)
        {
            fehler.Id = default;
            _context.Fehler.Add(fehler);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (FehlerExists(fehler.Id))
                {
                    return(Conflict());
                }

                throw;
            }

            var workplace = _context.Arbeitsplatz.Find(fehler.ArbeitsplatzId);
            var category  = _context.Kategorie.Find(fehler.KategorieId);
            var lehrer    = await _context.LehrerRaum.Where(lr => lr.RaumId == workplace.RaumId).ToListAsync();

            try
            {
                var ok = await SendErrorReportEmail(
                    lehrer.Select(l => new Address(l.Lehrer.Email, l.Lehrer.Name)).ToList(),
                    workplace.Raum.Name, fehler.Titel, category.Name, workplace.Name, fehler.Status);

                if (!ok)
                {
                    return(UnprocessableEntity("Email sending not ok"));
                }
            }
            catch
            {
                return(UnprocessableEntity("Email sending not ok"));
            }

            return(CreatedAtAction("GetFehler", new { id = fehler.Id }, fehler));
        }