Exemplo n.º 1
0
        public async Task <ResponseNoteModel> AddUserNoteTask(ResponseNoteModel note)
        {
            try
            {
                if (note.Labels != null)
                {
                    note.Labels = note.Labels.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
                }
                if (note.Collaborators != null)
                {
                    note.Collaborators = note.Collaborators.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
                }
                if (note.IsTrash || note.IsArchive)
                {
                    note.IsPin = false;
                }
                await redis.RemoveNotesRedisCache(note.UserID);

                return(NotesManagementRL.AddUserNote(note));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
 public ResponseNoteModel AddUserNote(ResponseNoteModel note)
 {
     try
     {
         var NewNote = new Note
         {
             UserId          = note.UserID,
             NoteId          = note.NoteId,
             Title           = note.Title,
             Body            = note.Body,
             Color           = note.Color,
             Image           = note.Image,
             Reminder        = note.Reminder,
             IsPin           = note.isPin,
             IsArchieve      = note.isArchieve,
             IsTrash         = note.isTrash,
             CreatedOn       = DateTime.Now,
             ModificaionTime = null,
         };
         notesContext.Notes.Add(NewNote);
         notesContext.SaveChanges();
         return(note);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        public async Task <ResponseNoteModel> pin(long UserID, long noteID)
        {
            try
            {
                var note = this.notesContext.Notes.Where(n => n.NoteId == noteID && n.IsArchieve == false && n.IsTrash == false).SingleOrDefault();
                if (note != null)
                {
                    if (note.IsPin == true)
                    {
                        note.IsPin = false;
                        ResponseNoteModel NewNote = new ResponseNoteModel
                        {
                            UserID     = (long)note.UserId,
                            NoteId     = note.NoteId,
                            Title      = note.Title,
                            Body       = note.Body,
                            Color      = note.Color,
                            Image      = note.Image,
                            Reminder   = (DateTime)note.Reminder,
                            isPin      = (bool)note.IsPin,
                            isArchieve = (bool)note.IsArchieve,
                            isTrash    = (bool)note.IsTrash,
                        };

                        await this.notesContext.SaveChangesAsync();

                        return(NewNote);
                    }
                    else
                    {
                        note.IsPin = true;
                        ResponseNoteModel NewNote = new ResponseNoteModel
                        {
                            UserID     = (long)note.UserId,
                            NoteId     = note.NoteId,
                            Title      = note.Title,
                            Body       = note.Body,
                            Color      = note.Color,
                            Image      = note.Image,
                            Reminder   = (DateTime)note.Reminder,
                            isPin      = (bool)note.IsPin,
                            isArchieve = (bool)note.IsArchieve,
                            isTrash    = (bool)note.IsTrash,
                        };

                        await this.notesContext.SaveChangesAsync();

                        return(NewNote);
                    }
                }
                else
                {
                    throw new NoteException(NoteException.ExceptionType.NOTES_NOT_EXIST, "Note does not exist");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public IActionResult DeleteNote(long noteId)
        {
            try
            {
                if (User.Identity is ClaimsIdentity identity)
                {
                    IEnumerable <Claim> claims = identity.Claims;
                    long   UserID = Convert.ToInt64(claims.Where(p => p.Type == "UserId").FirstOrDefault()?.Value);
                    string Email  = claims.Where(p => p.Type == "Email").FirstOrDefault()?.Value;

                    ResponseNoteModel result = notesBL.DeleteNote(UserID, noteId).Result;
                    if (result == null)
                    {
                        return(Ok(new { success = true, user = Email, Message = "Note deleted sucessfully", Note = result }));
                    }
                    else
                    {
                        return(Ok(new { success = true, user = Email, Message = "Note is added to trash", Note = result }));
                    }
                }
                return(BadRequest(new { success = false, Message = "no user is active please login" }));
            }
            catch (Exception exception)
            {
                return(BadRequest(new { success = false, exception.Message }));
            }
        }
Exemplo n.º 5
0
        public async Task <ResponseNoteModel> DeleteNote(long UserID, long noteID)
        {
            try
            {
                await redis.RemoveNotesRedisCache(UserID);

                ResponseNoteModel result = notesRL.DeleteNote(UserID, noteID);
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task <ResponseNoteModel> UpdateNote(ResponseNoteModel note)
        {
            try
            {
                await redis.RemoveNotesRedisCache(note.UserID);

                if (note.isTrash || note.isArchieve)
                {
                    note.isPin = false;
                }
                return(notesRL.UpdateNote(note));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 7
0
        public ResponseNoteModel DeleteNote(long UserID, long noteID)
        {
            try
            {
                var note = notesContext.Notes.Find(noteID);


                if (notesContext.Notes.Any(n => n.NoteId == noteID && n.UserId == UserID))
                {
                    if (note.IsTrash == true)
                    {
                        notesContext.Entry(note).State = EntityState.Deleted;
                        notesContext.SaveChanges();

                        return(null);
                    }
                    else
                    {
                        note.IsTrash = true;
                        ResponseNoteModel NewNote = new ResponseNoteModel
                        {
                            UserID     = (long)note.UserId,
                            NoteId     = note.NoteId,
                            Title      = note.Title,
                            Body       = note.Body,
                            Color      = note.Color,
                            Image      = note.Image,
                            Reminder   = (DateTime)note.Reminder,
                            isPin      = (bool)note.IsPin,
                            isArchieve = (bool)note.IsArchieve,
                            isTrash    = (bool)note.IsTrash,
                        };
                        notesContext.SaveChanges();
                        return(NewNote);
                    }
                }
                else
                {
                    throw new NoteException(NoteException.ExceptionType.WRONG_NOTEID, "Note Id does not exist");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 8
0
        public ResponseNoteModel UpdateNote(ResponseNoteModel Note)
        {
            try
            {
                var UpdateNote = notesContext.Notes.FirstOrDefault(N => N.NoteId == Note.NoteId && N.UserId == Note.UserID);
                if (UpdateNote != null)
                {
                    UpdateNote.Title           = Note.Title;
                    UpdateNote.Body            = Note.Body;
                    UpdateNote.Reminder        = Note.Reminder;
                    UpdateNote.Color           = Note.Color;
                    UpdateNote.Image           = Note.Image;
                    UpdateNote.IsArchieve      = Note.isArchieve;
                    UpdateNote.IsPin           = Note.isPin;
                    UpdateNote.IsTrash         = Note.isTrash;
                    UpdateNote.CreatedOn       = Note.CreateonTime;
                    UpdateNote.ModificaionTime = DateTime.Now;
                }
                notesContext.SaveChanges();
                var NewResponseNote = notesContext.Notes.Where(N => N.NoteId == Note.NoteId).Select(N =>
                                                                                                    new ResponseNoteModel
                {
                    UserID = (long)N.UserId,
                    NoteId = N.NoteId,
                    Title  = N.Title,
                    Body   = N.Body,
                    Color  = N.Color,

                    Image      = N.Image,
                    Reminder   = (DateTime)N.Reminder,
                    isPin      = (bool)N.IsPin,
                    isArchieve = (bool)N.IsArchieve,

                    isTrash          = (bool)N.IsTrash,
                    CreateonTime     = (DateTime)N.CreatedOn,
                    ModificationTime = (DateTime)N.ModificaionTime,
                }
                                                                                                    ).ToList().First();
                return(NewResponseNote);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 9
0
 public IActionResult AddUserNote(ResponseNoteModel Note)
 {
     try
     {
         if (User.Identity is ClaimsIdentity identity)
         {
             IEnumerable <Claim> claims = identity.Claims;
             long UserID = Convert.ToInt64(claims.Where(p => p.Type == "UserID").FirstOrDefault()?.Value);
             Note.UserID = UserID;
             ResponseNoteModel result = notesManagementBL.AddUserNote(Note);
             return(Ok(new { success = true, Note = result }));
         }
         return(BadRequest(new { success = false, Message = "no user is active please login" }));
     }
     catch (Exception exception)
     {
         return(BadRequest(new { success = false, exception.Message }));
     }
 }
Exemplo n.º 10
0
 public IActionResult UpdateNote(ResponseNoteModel Note)
 {
     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);
             Note.UserID = UserID;
             ResponseNoteModel result = notesBL.UpdateNote(Note).Result;
             return(Ok(new { success = true, Message = "note updated", Note = result }));
         }
         return(BadRequest(new { success = false, Message = "no user is active please login" }));
     }
     catch (Exception exception)
     {
         return(BadRequest(new { success = false, exception.Message }));
     }
 }
Exemplo n.º 11
0
        public async Task <ResponseNoteModel> UploadImage(IFormFile file, long UserID, long noteID)
        {
            var        note         = this.notesContext.Notes.Where(t => t.NoteId == noteID).SingleOrDefault();
            var        stream       = file.OpenReadStream();
            var        name         = file.FileName;
            Account    account      = new Account("devjs8e7v", "217619793785761", "t8nmfVwKgMJciXM8dP_B2C5UK90");
            Cloudinary cloudinary   = new Cloudinary(account);
            var        uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(name, stream)
            };
            ImageUploadResult uploadResult = cloudinary.Upload(uploadParams);

            note.Image = uploadResult.Url.ToString();
            try
            {
                ResponseNoteModel NewNote = new ResponseNoteModel
                {
                    UserID     = (long)note.UserId,
                    NoteId     = note.NoteId,
                    Title      = note.Title,
                    Body       = note.Body,
                    Color      = note.Color,
                    Image      = note.Image,
                    Reminder   = (DateTime)note.Reminder,
                    isPin      = (bool)note.IsPin,
                    isArchieve = (bool)note.IsArchieve,
                    isTrash    = (bool)note.IsTrash,
                };
                await notesContext.SaveChangesAsync();

                return(NewNote);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 12
0
 public ResponseNoteModel AddUserNote(ResponseNoteModel note)
 {
     return(AddUserNoteTask(note).Result);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Adds the user note.
        /// </summary>
        /// <param name="note">The note.</param>
        /// <returns></returns>
        public ResponseNoteModel AddUserNote(ResponseNoteModel note)
        {
            try
            {
                var NewNote = new Note
                {
                    UserId          = note.UserID,
                    Title           = note.Title,
                    Text            = note.Text,
                    ReminderOn      = note.ReminderOn,
                    BackgroundColor = note.BackgroundColor,
                    BackgroundImage = note.BackgroundImage,
                    IsArchive       = note.IsArchive,
                    IsPin           = note.IsPin,
                    IsTrash         = note.IsTrash,
                };
                NotesDB.Notes.Add(NewNote);
                NotesDB.SaveChanges();

                if (note.Labels != null)
                {
                    note.Labels.ToList().ForEach(L =>
                                                 NotesDB.Set <Label>().AddIfNotExists(new Label {
                        UserId = NewNote.UserId, LabelName = L
                    }, x => x.LabelName.Equals(L)));
                    NotesDB.SaveChanges();
                    note.Labels.ToList().ForEach(L => NotesDB.NoteLabels.Add(
                                                     new NoteLabel
                    {
                        NoteId  = NewNote.NoteId,
                        LabelId = NotesDB.Labels.FirstOrDefault(a => a.LabelName == L).LabelId
                    }));
                }
                if (note.Collaborators != null)
                {
                    note.Collaborators.ToList().ForEach(C =>
                                                        NotesDB.Collaborators.Add(
                                                            new Collaborator {
                        UserId = NewNote.UserId, NoteId = NewNote.NoteId, CollaboratorEmail = C
                    }));
                    NotesDB.SaveChanges();
                }
                var NewResponseNote = new ResponseNoteModel
                {
                    UserID          = (long)NewNote.UserId,
                    NoteID          = NewNote.NoteId,
                    Title           = NewNote.Title,
                    Text            = NewNote.Text,
                    CreatedOn       = NewNote.CreatedOn,
                    ReminderOn      = NewNote.ReminderOn,
                    BackgroundColor = NewNote.BackgroundColor,
                    BackgroundImage = NewNote.BackgroundImage,
                    IsArchive       = NewNote.IsArchive,
                    IsPin           = NewNote.IsPin,
                    IsTrash         = NewNote.IsTrash,
                    Labels          = NewNote.NoteLabels.Select(N => N.Label.LabelName).ToList(),
                    Collaborators   = NewNote.Collaborators.Select(C => C.CollaboratorEmail).ToList()
                };
                return(NewResponseNote);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Updates the existing note.
 /// </summary>
 /// <param name="Note">The note.</param>
 /// <returns></returns>
 public ResponseNoteModel UpdateNote(ResponseNoteModel Note)
 {
     try
     {
         if (NotesDB.NoteLabels.Any(n => n.NoteId == Note.NoteID && n.UserId == Note.UserID))
         {
             NotesDB.NoteLabels.RemoveRange(NotesDB.NoteLabels.Where(N => N.NoteId == Note.NoteID));
         }
         NotesDB.SaveChanges();
         var UpdateNote = NotesDB.Notes.FirstOrDefault(N => N.NoteId == Note.NoteID && N.UserId == Note.UserID);
         if (UpdateNote != null)
         {
             UpdateNote.Title           = Note.Title;
             UpdateNote.Text            = Note.Text;
             UpdateNote.ReminderOn      = Note.ReminderOn;
             UpdateNote.BackgroundColor = Note.BackgroundColor;
             UpdateNote.BackgroundImage = Note.BackgroundImage;
             UpdateNote.IsArchive       = Note.IsArchive;
             UpdateNote.IsPin           = Note.IsPin;
             UpdateNote.IsTrash         = Note.IsTrash;
         }
         NotesDB.SaveChanges();
         if (Note.Labels != null)
         {
             Note.Labels.ToList().ForEach(L =>
                                          NotesDB.Set <Label>().AddIfNotExists(new Label {
                 UserId = Note.UserID, LabelName = L
             }, x => x.LabelName.Equals(L)));
             NotesDB.SaveChanges();
             Note.Labels.ToList().ForEach(L =>
                                          NotesDB.NoteLabels.Add(
                                              new NoteLabel
             {
                 UserId  = Note.UserID,
                 NoteId  = Note.NoteID,
                 LabelId = NotesDB.Labels.FirstOrDefault(a => a.LabelName == L).LabelId
             }));;
         }
         NotesDB.Collaborators.RemoveRange(NotesDB.Collaborators.Where(L => L.NoteId == Note.NoteID).ToList());
         NotesDB.SaveChanges();
         if (Note.Collaborators != null)
         {
             Note.Collaborators.ToList().ForEach(C =>
                                                 NotesDB.Collaborators.Add(
                                                     new Collaborator {
                 UserId = Note.UserID, NoteId = Note.NoteID, CollaboratorEmail = C
             }));
             NotesDB.SaveChanges();
         }
         var NewResponseNote = NotesDB.Notes.Where(N => N.NoteId == Note.NoteID).Select(N =>
                                                                                        new ResponseNoteModel
         {
             UserID          = (long)N.UserId,
             NoteID          = N.NoteId,
             Title           = N.Title,
             Text            = N.Text,
             CreatedOn       = N.CreatedOn,
             ReminderOn      = N.ReminderOn,
             BackgroundColor = N.BackgroundColor,
             BackgroundImage = N.BackgroundImage,
             IsArchive       = N.IsArchive,
             IsPin           = N.IsPin,
             IsTrash         = N.IsTrash,
             Labels          = N.NoteLabels.Select(N => N.Label.LabelName).ToList(),
             Collaborators   = N.Collaborators.Select(C => C.CollaboratorEmail).ToList()
         }
                                                                                        ).ToList().First();
         return(NewResponseNote);
     }
     catch (Exception)
     {
         throw;
     }
 }