Beispiel #1
0
        public async Task CreateAsync_NoteReminder()
        {
            var update = new NoteReminderUpdateModel();

            update.Name = "test";

            var identity = new NoteReminderIdentityModel(0);

            var expected = new NoteReminder();

            expected.Name = "test";

            //mock
            var noteDataAccess = new Mock <IDataAccessor <NoteReminder, INoteReminderIdentity, NoteReminderUpdateModel> >();

            noteDataAccess.Setup(x => x.InsertAsync(update)).ReturnsAsync(expected);

            //setup
            var noteServices = new NoteReminderServices(noteDataAccess.Object);
            //action
            var result = await noteServices.CreateAsync(update);

            //result
            result.Should().Be(expected);
        }
 /// <summary>
 /// Sets the note reminder.
 /// </summary>
 /// <param name="reminder">The reminder.</param>
 /// <returns></returns>
 public bool SetNoteReminder(NoteReminder reminder)
 {
     try
     {
         NotesDB.Notes.FirstOrDefault(
             N => N.NoteId == reminder.NoteID && N.UserId == reminder.UserID).ReminderOn = reminder.ReminderOn;
         NotesDB.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #3
0
 public IActionResult SetNoteReminder(NoteReminder Reminder)
 {
     try
     {
         var identity = User.Identity as ClaimsIdentity;
         if (identity != null)
         {
             IEnumerable <Claim> claims = identity.Claims;
             long UserID = Convert.ToInt64(claims.Where(p => p.Type == "UserID").FirstOrDefault()?.Value);
             Reminder.UserID = UserID;
             bool result = notesManagementBL.SetNoteReminder(Reminder).Result;
             return(Ok(new { success = true, Message = "note reminder added" }));
         }
         return(BadRequest(new { success = false, Message = "no user is active please login" }));
     }
     catch (Exception exception)
     {
         return(BadRequest(new { success = false, exception.Message }));
     }
 }
Beispiel #4
0
        public async Task <IActionResult> SetNoteReminder(NoteReminder Reminder, long NoteId)
        {
            try
            {
                var identity = User.Identity as ClaimsIdentity;
                if (identity != null)
                {
                    IEnumerable <Claim> claims = identity.Claims;
                    long UserID = Convert.ToInt64(claims.Where(p => p.Type == "UserId").FirstOrDefault()?.Value);
                    var  result = await this.notesBL.SetNoteReminder(Reminder, UserID, NoteId);

                    return(Ok(new { success = true, Message = "Note reminder added", Data = result }));
                }
                return(BadRequest(new { success = false, Message = "no user is active please login" }));
            }
            catch (Exception exception)
            {
                return(BadRequest(new { success = false, exception.Message }));
            }
        }
Beispiel #5
0
        public async Task <NoteReminder> SetNoteReminder(NoteReminder reminder, long UserId, long NoteId)
        {
            try
            {
                if (reminder.ReminderOn < DateTime.Now)
                {
                    throw new Exception("Time is passed");
                }
                if (reminder.NoteID == default)
                {
                    throw new Exception("NoteID missing");
                }
                var result = await notesRL.SetNoteReminder(reminder, UserId, NoteId);

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #6
0
        public async Task <bool> SetNoteReminder(NoteReminder reminder)
        {
            try
            {
                await redis.RemoveNotesRedisCache(reminder.Id);

                if (reminder.ReminderOn < DateTime.Now)
                {
                    throw new Exception("Time is passed");
                }
                if (reminder.NoteId == default)
                {
                    throw new Exception("NoteID missing");
                }
                return(notesRL.SetNoteReminder(reminder));
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #7
0
        public async Task <NoteReminder> SetNoteReminder(NoteReminder reminder, long UserID, long NoteID)
        {
            try
            {
                notesContext.Notes.FirstOrDefault(
                    N => N.NoteId == NoteID && N.UserId == UserID).Reminder = reminder.ReminderOn;
                NoteReminder NewNote = new NoteReminder
                {
                    UserID     = (long)reminder.UserID,
                    ReminderOn = (DateTime)reminder.ReminderOn,
                    NoteID     = (long)reminder.NoteID,
                };
                await notesContext.SaveChangesAsync();

                return(reminder);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #8
0
        public async Task UpdateAsync_NoteReminder()
        {
            var initial = new NoteReminder();

            initial.Name = "test";
            initial.Date = DateTime.Now;
            initial.Text = "initial";

            var update = new NoteReminderUpdateModel();

            update.Name = "test2";
            update.Date = DateTime.Today;
            update.Text = "update";

            var identity = new NoteReminderIdentityModel(0);

            var expected = new NoteReminder();

            expected.Name = "test2";
            expected.Date = DateTime.Today;
            expected.Text = "update";
            //mock
            var noteDataAccess = new Mock <IDataAccessor <NoteReminder, INoteReminderIdentity, NoteReminderUpdateModel> >();

            noteDataAccess.Setup(x => x.InsertAsync(update)).ReturnsAsync(initial);
            noteDataAccess.Setup(x => x.UpdateAsync(identity, update)).ReturnsAsync(expected);
            //setup
            var noteServices = new NoteReminderServices(noteDataAccess.Object);
            //action
            await noteServices.CreateAsync(update);

            var result = await noteServices.UpdateAsync(identity, update);

            //result
            result.Should().Be(expected);
        }