Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ReminderDateTime,ReminderTime,Message")] DAL.Reminder reminder)
        {
            if (id != reminder.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(reminder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReminderExists(reminder.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(reminder));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,ReminderDateTime,ReminderTime,Message")] DAL.Reminder reminder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reminder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reminder));
        }
Esempio n. 3
0
        public Task <Reminder> AddReminder(Reminder reminder)
        {
            //if (reminder.ReminderId == 0)
            //{
            //    for (int x = 1; x < 10000; x++)
            //    {
            //        var find = _dbContext.Reminders.Where(c => c.ReminderId== x).FirstOrDefault();
            //        if (find == null)
            //        {
            //            reminder.ReminderId = x;
            //            break;
            //        }
            //    }
            //}
            var added = _dbContext.Reminders.Add(reminder);

            if (_dbContext.SaveChanges() > 0)
            {
                return(Task.FromResult(reminder));
            }
            return(Task.FromResult(new Reminder()));
        }
Esempio n. 4
0
 public Task <bool> RemoveReminder(Reminder reminder)
 {
     _dbContext.Reminders.Remove(reminder);
     return(Task.FromResult(_dbContext.SaveChanges() > 0));
 }
 // This method should be used to update a existing reminder.
 public bool UpdateReminder(Reminder reminder)
 {
     context.Entry <Reminder>(reminder).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     context.SaveChanges();
     return(true);
 }
 //This method should be used to save a new reminder.
 public Reminder CreateReminder(Reminder reminder)
 {
     context.Reminders.Add(reminder);
     context.SaveChanges();
     return(reminder);
 }
 /// <summary>
 /// Method to remove a reminder from the table
 /// </summary>
 /// <param name="reminder">The reminder object that is to be removed</param>
 /// <returns>True if removal was successful</returns>
 public async Task <bool> RemoveReminder(Reminder reminder)
 {
     dbContext.Reminders.Remove(reminder);
     return(await dbContext.SaveChangesAsync() > 0);
 }