コード例 #1
0
 public IActionResult CreateNote([FromForm] UserNoteRequest userNoteData)
 {
     try
     {
         var idClaim = HttpContext.User.Claims.FirstOrDefault(id => id.Type.Equals("id", StringComparison.InvariantCultureIgnoreCase));
         int userId  = Convert.ToInt32(idClaim.Value);
         UserNoteResponseData data = _userNoteBusiness.CreateNote(userId, userNoteData);
         bool   success            = false;
         string message;
         if (userNoteData == null)
         {
             message = "Try again";
             return(Ok(new { success, message }));
         }
         else
         {
             success = true;
             message = "Notes Created Successfully";
             return(Ok(new { success, message, data }));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(new { ex.Message }));
     }
 }
コード例 #2
0
        public UserNoteResponseData CreateNote(int userID, UserNoteRequest userNoteData)
        {
            try
            {
                UserNotesInfo userNote = new UserNotesInfo()
                {
                    UserId       = userID,
                    Title        = userNoteData.Title,
                    Description  = userNoteData.Description,
                    Color        = userNoteData.Color,
                    Image        = userNoteData.Image,
                    Pin          = userNoteData.Pin,
                    Archived     = userNoteData.Archived,
                    Trash        = userNoteData.Trash,
                    Reminder     = userNoteData.Reminder,
                    CreatedDate  = DateTime.Now,
                    ModifiedDate = DateTime.Now
                };
                _context.UserNotes.Add(userNote);
                _context.SaveChanges();

                if (userNoteData.Label != null && userNoteData.Label.Count != 0)
                {
                    List <NotesLabelRequest> labelRequests = userNoteData.Label;
                    foreach (NotesLabelRequest labelRequest in labelRequests)
                    {
                        LabelInfo labelInfo = _context.Labels.
                                              Where(label => label.UserID == userID && label.LabelID == labelRequest.LabelId).
                                              FirstOrDefault <LabelInfo>();

                        if (labelRequest.LabelId > 0 && labelInfo != null)
                        {
                            var data = new NotesLabel
                            {
                                LabelId      = labelRequest.LabelId,
                                NotesId      = userNote.NotesId,
                                CreatedDate  = DateTime.Now,
                                ModifiedDate = DateTime.Now
                            };
                            _context.NotesLabels.Add(data);
                            _context.SaveChanges();
                        }
                    }
                }
                if (userNoteData.Collaborators != null && userNoteData.Collaborators.Count != 0)
                {
                    List <CollaboratorRequest> collaboratorss = userNoteData.Collaborators;
                    foreach (CollaboratorRequest collaborator in collaboratorss)
                    {
                        if (collaborator.UserID != 0)
                        {
                            CollaboratorInfo userNotes = new CollaboratorInfo()
                            {
                                UserID       = collaborator.UserID,
                                NoteID       = userNote.NotesId,
                                CreatedDate  = DateTime.Now,
                                ModifiedDate = DateTime.Now,
                            };
                            _context.Collaborators.Add(userNotes);
                            _context.SaveChanges();
                        }
                    }
                }

                List <LabelResponseData> labelsData = _context.NotesLabels.
                                                      Where(note => note.NotesId == userNote.NotesId).
                                                      Join(_context.Labels,
                                                           labbelledNote => labbelledNote.LabelId,
                                                           label => label.LabelID,
                                                           (labbelledNote, label) => new LabelResponseData
                {
                    LabelID   = labbelledNote.LabelId,
                    LabelName = label.LabelName,
                }).
                                                      ToList();
                List <CollaboratorResponseData> collabsData = _context.Collaborators.
                                                              Where(noted => noted.NoteID == userNote.NotesId).
                                                              Join(_context.Users,
                                                                   noteLabel => noteLabel.UserID,
                                                                   label => label.ID,
                                                                   (noteLabel, label) => new CollaboratorResponseData
                {
                    UserID = noteLabel.UserID,
                    Email  = label.Email
                }).
                                                              ToList();
                var noteResponseData = new UserNoteResponseData()
                {
                    NoteId        = userNote.NotesId,
                    Title         = userNote.Title,
                    Description   = userNote.Description,
                    Color         = userNote.Color,
                    Image         = userNote.Image,
                    Pin           = userNote.Pin,
                    Archived      = userNote.Archived,
                    Reminder      = userNote.Reminder,
                    Trash         = userNote.Trash,
                    Labels        = labelsData,
                    Collaborators = collabsData
                };

                return(noteResponseData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #3
0
        public UserNoteResponseData CreateNote(int userID, UserNoteRequest userNotes)
        {
            UserNoteResponseData userNoteResponseData = _userNoteRepository.CreateNote(userID, userNotes);

            return(userNoteResponseData);
        }