public UserNoteResponseData AddlabelsToNote(int userID, int noteID, AddLabelNoteRequest addLabelNote) { try { List <NotesLabel> labels = _context.NotesLabels.Where(notes => notes.NotesId == noteID).ToList(); if (labels != null && labels.Count != 0) { _context.NotesLabels.RemoveRange(labels); _context.SaveChanges(); } if (addLabelNote.Label.Count > 0) { List <NotesLabelRequest> labelRequests = addLabelNote.Label; foreach (NotesLabelRequest labelRequest in labelRequests) { LabelInfo labelInfo = _context.Labels. Where(labeled => labeled.UserID == userID && labeled.LabelID == labelRequest.LabelId). FirstOrDefault <LabelInfo>(); if (labelRequest.LabelId > 0 && labelInfo != null) { var data = new NotesLabel { LabelId = labelRequest.LabelId, NotesId = noteID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; _context.NotesLabels.Add(data); _context.SaveChanges(); } } } var notesinfo = _context.UserNotes. Where(note => note.NotesId == noteID && note.UserId == userID). First <UserNotesInfo>(); List <LabelResponseData> labelsData = _context.NotesLabels. Where(note => note.NotesId == notesinfo.NotesId). Join(_context.Labels, noteLabel => noteLabel.LabelId, label => label.LabelID, (noteLabel, label) => new LabelResponseData { LabelID = noteLabel.LabelId, LabelName = label.LabelName, }). ToList(); UserNoteResponseData noteResponseData = new UserNoteResponseData() { NoteId = notesinfo.NotesId, Title = notesinfo.Title, Description = notesinfo.Description, Color = notesinfo.Color, Image = notesinfo.Image, Pin = notesinfo.Pin, Archived = notesinfo.Archived, Trash = notesinfo.Trash, Reminder = notesinfo.Reminder, Labels = labelsData }; return(noteResponseData); } catch (Exception ex) { throw new Exception(ex.Message); } }
void ReleaseDesignerOutlets() { if (CategoryLabel != null) { CategoryLabel.Dispose(); CategoryLabel = null; } if (DescriptionLabel != null) { DescriptionLabel.Dispose(); DescriptionLabel = null; } if (ImageView != null) { ImageView.Dispose(); ImageView = null; } if (IsSoldLabel != null) { IsSoldLabel.Dispose(); IsSoldLabel = null; } if (LocationLabel != null) { LocationLabel.Dispose(); LocationLabel = null; } if (NotesLabel != null) { NotesLabel.Dispose(); NotesLabel = null; } if (PriceLabel != null) { PriceLabel.Dispose(); PriceLabel = null; } if (PurchaseDateLabel != null) { PurchaseDateLabel.Dispose(); PurchaseDateLabel = null; } if (QuantityLabel != null) { QuantityLabel.Dispose(); QuantityLabel = null; } if (SerialNumberLabel != null) { SerialNumberLabel.Dispose(); SerialNumberLabel = null; } if (NameLabel != null) { NameLabel.Dispose(); NameLabel = null; } }
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); } }