Esempio n. 1
0
        public async Task <IActionResult> DeleteReminder(int remId)
        {
            var   username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            Admin admin    = _context.Admins.Where(s => s.username == username).First();
            int   id       = admin.Id;

            Reminder_Admin rd = _context.Reminder_Admins.Where(s => s.Id == remId).First();

            try
            {
                _context.Reminder_Admins.Remove(rd);
                await _context.SaveChangesAsync();

                return(RedirectToAction("ReminderPage"));
            }
            catch (DbUpdateException)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("ReminderPage"));
        }
Esempio n. 2
0
        public async Task <IActionResult> ReminderAdd(Reminder_Admin rd)
        {
            var   username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            Admin admin    = _context.Admins.Where(s => s.username == username).First();
            int   id       = admin.Id;

            ViewBag.id = id;

            try
            {
                _context.Reminder_Admins.Add(rd);
                await _context.SaveChangesAsync();

                return(RedirectToAction("ReminderPage"));
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }


            return(RedirectToAction("ReminderPage"));
        }