public async Task <NoteResponse> UploadImage(int noteID, string userID, IFormFile file) { try { var note = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID).FirstOrDefault(); if (note != null && note.IsTrash == false) { UploadImage imageUpload = new UploadImage(this.applicationSetting.APIkey, this.applicationSetting.APISecret, this.applicationSetting.CloudName); var url = imageUpload.Upload(file); note.Image = url; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); await this.authenticationContext.SaveChangesAsync(); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } else { return(null); } } catch (Exception e) { throw new Exception(e.Message); } }
public IList <NoteResponse> GetPinNotes(string userID) { try { //get all notes var data = this.authenticationContext.Note.Where(s => s.UserID == userID && s.IsPin == true); //initialize list var list = new List <NoteResponse>(); //checking whether data is null or not if (data != null) { foreach (var note in data) { NoteResponse notes = this.GetNoteResponse(userID, note); list.Add(notes); } return(list); } else { return(null); } } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <NoteResponse> ChangeColor(ColorModel color, int noteID, string userID) { try { //geting note var note = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID).FirstOrDefault(); //checking whether note is null or not if (note != null) { //color is null or not note.Color = color.color; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); await this.authenticationContext.SaveChangesAsync(); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } else { throw new Exception("Note is not Found"); } } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <NoteResponse> IsPin(IsPinModel isPin, int noteID, string userID) { try { var note = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID).FirstOrDefault(); //check whether data is null or not if (note != null) { note.IsTrash = isPin.isPin; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); await this.authenticationContext.SaveChangesAsync(); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } else { throw new Exception("Matching Data Not found"); } } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <NoteResponse> RestoreNotes(int noteID, string userID) { try { //get the all the notes var note = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID && s.IsTrash == true).FirstOrDefault(); //checking data is null or not if (note != null) { note.IsTrash = false; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } else { return(null); } } catch (Exception e) { throw new Exception(e.Message); } }
public IActionResult Create([FromBody] CreateNoteRequest noteRequest) { if (noteRequest == null) { return(BadRequest()); } if (string.IsNullOrEmpty(noteRequest.Id)) { noteRequest.Id = Guid.NewGuid().ToString(); } var note = new Note { Id = noteRequest.Id, Tag = noteRequest.Tag, Title = noteRequest.Title, Post = noteRequest.Post, UserId = HttpContext.GetUserId() }; this._noteService.Create(note); var baseUrl = HttpContext.Request.Scheme + "://" + HttpContext.Request.Host.ToUriComponent(); var locationUri = baseUrl + "/" + ApiRoutes.Notes.Get.Replace("{noteId}", noteRequest.Id); var response = new NoteResponse { Id = note.Id, Tag = note.Tag, Title = note.Title, Post = note.Post }; return(Created(locationUri, response)); }
public async Task <NoteResponse> IsArchieve(IsArchieveModel isArchieve, int noteID, string userID) { try { //get all the notes var note = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID).FirstOrDefault(); //check whether the data is null ornot if (note != null) { note.IsArchive = isArchieve.IsArchieve; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); await this.authenticationContext.SaveChangesAsync(); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } //data not found else { throw new Exception("data not found"); } } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Displays the notes. /// </summary> /// <param name="userID">The user identifier.</param> /// <returns> /// returns the list of note /// </returns> /// <exception cref="Exception"> exception message</exception> public IList <NoteResponse> DisplayNotes(string userID) { try { // get all notes of user var data = this.authenticationContext.Note.Where(s => s.UserID == userID); var list = new List <NoteResponse>(); // check whether user have notes or not if (data != null) { // iterates the loop for each note foreach (var note in data) { NoteResponse notes = this.GetNoteResponse(userID, note); list.Add(notes); } // returns the list return(list); } else { return(null); } } catch (Exception exception) { throw new Exception(exception.Message); } }
public async Task <NoteResponse> RemoveReminder(int noteID, string userID) { try { var note = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID).FirstOrDefault(); if (note != null) { note.Reminder = null; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); await this.authenticationContext.SaveChangesAsync(); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } else { return(null); } } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <NoteResponse> GetNote(int noteId) { var userId = CurrentlyLoggedUser.Id; Note note = _context.Set <Note>().Where(n => n.Id == noteId && n.User.Id == userId).FirstOrDefault(); NoteResponse response = _mapper.Map <Note, NoteResponse>(note); return(response); }
public async Task <IActionResult> GetNote([FromRoute] int noteId) { NoteResponse response = await _noteService.GetNote(noteId); if (response == null) { return(BadRequest()); } return(Ok(response)); }
public async Task <IActionResult> EditModalAsync(Guid NoteUID) { NoteResponse _Response = await __NoteManager.GetByUIDAsync(NoteUID); if (_Response == null) { return(Json(new { error = $"{GlobalConstants.ERROR_ACTION_PREFIX} find {ENTITY_NAME}." })); } return(PartialView("_EditNote", __Mapper.Map <NoteViewModel>(_Response))); }
public List <NoteResponse> GetNotesForGroup(int groupId, int issuerId) { var notes = _notesRepository.GetNotesForGroup(groupId, issuerId); var noteResponses = new List <NoteResponse>(); foreach (NoteEntity note in notes) { var noteResponse = new NoteResponse(note); noteResponses.Add(noteResponse); } return(noteResponses); }
public IEnumerable <NoteResponse> AddNote(Note note) { var user = users.FirstOrDefault(x => x.Email == note.Email); note.Id = notes.Max(x => x.Id) + 1; var response = new NoteResponse { Latitude = note.Latitude, Longitude = note.Longitude, Email = user.Email, FullName = $"{user.FirstName}, {user.LastName}" }; notes.Add(response); return(notes); }
private NoteResponse GetNoteResponse(string userID, NoteModel note) { try { // get labels for Note var labelList = this.authenticationContext.NoteLabel.Where(s => s.UserID == userID && s.NoteID == note.NoteID); // creating list for label var labels = new List <LabelResponse>(); // iteartes the loop for each label for note foreach (var data in labelList) { // get the label info var label = new LabelResponse() { ID = data.LabelID, Label = data.Label, }; // add the label info into label list labels.Add(label); } // get the required values of note var notes = new NoteResponse() { NoteID = note.NoteID, Title = note.Title, Description = note.Description, Color = note.Color, Image = note.Image, IsArchive = note.IsArchive, IsPin = note.IsPin, IsTrash = note.IsTrash, Reminder = note.Reminder, Labels = labels }; // return the note info return(notes); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <NoteResponse> GetAsync(UIDRequest request) { NoteResponse _Response = new NoteResponse(); if (request.UID == Guid.Empty) { _Response.Success = false; _Response.ErrorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} retrieve {ENTITY_NAME}."; } NoteEntity _NoteEntity = await __NoteRepository.GetAsync(request.UID); if (_NoteEntity == null) { _Response.Success = false; _Response.ErrorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} retrieve {ENTITY_NAME}."; } return(_NoteEntity.ToResponse() ?? _Response); }
public IActionResult Post(NoteRequest value) { try { _logger.LogInformation($"QUERY: Id: {value.UserId}, Body: {value.Body}."); IEnumerable <Note> foundNotes = null; if (value.UserId != 0 && value.Body.Any()) { foundNotes = _repository.QueryNotes(x => x.UserId == value.UserId && x.Body.Contains(value.Body)).ToList(); } if (value.UserId != 0 && !value.Body.Any()) { foundNotes = _repository.QueryNotes(x => x.UserId == value.UserId).ToList(); } if (value.UserId == 0 && value.Body.Any()) { foundNotes = _repository.QueryNotes(x => x.Body.Contains(value.Body)).ToList(); } var noteResponse = new NoteResponse { Notes = foundNotes }; return(Ok(noteResponse)); } catch (Exception ex) { _logger.LogError($"ERROR:{ex}."); var response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An exception occurred, see log.") }; return(StatusCode(500, response)); } }
/// <summary> /// Gets the note. /// </summary> /// <param name="noteID">The note identifier.</param> /// <param name="userID">The user identifier.</param> /// <returns> /// returns the operation result /// </returns> /// <exception cref="Exception"> exception message</exception> public async Task <NoteResponse> GetNote(int noteID, string userID) { try { // get all notes of user var data = this.authenticationContext.Note.Where(s => s.UserID == userID && s.NoteID == noteID).FirstOrDefault(); // check whether user have notes or not if (data != null) { NoteResponse note = this.GetNoteResponse(userID, data); return(note); } else { return(null); } } catch (Exception exception) { throw new Exception(exception.Message); } }
public async Task <NoteResponse> BulkRestore(string userID) { try { var note = this.authenticationContext.Note.Where(s => s.UserID == s.UserID && s.IsTrash == s.IsTrash).FirstOrDefault(); if (note != null) { note.IsTrash = false; note.ModifiedDate = DateTime.Now; this.authenticationContext.Note.Update(note); NoteResponse data = this.GetNoteResponse(userID, note); return(data); } else { return(null); } } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Creates the note. /// </summary> /// <param name="requestNote">The request note.</param> /// <param name="userID">The user identifier.</param> /// <returns> returns true or false indicating operation is successful or not</returns> /// <exception cref="Exception"> exception message</exception> public async Task <NoteResponse> CreateNote(NoteRequest requestNote, string userID) { try { // check whether user enter all the required data or not if (requestNote != null) { // set the user entered values var data = new NoteRequest() { Title = requestNote.Title, Description = requestNote.Description, Reminder = requestNote.Reminder, Collaborator = requestNote.Collaborator, Color = requestNote.Color, Image = requestNote.Image, IsArchive = requestNote.IsArchive, IsPin = requestNote.IsPin, IsTrash = requestNote.IsTrash, }; if (data.Collaborator != null) { var noteInfo = new NoteModel() { UserID = userID, Title = data.Title, Description = data.Description, Collaborators = data.Collaborator, Color = data.Color, Reminder = data.Reminder, Image = data.Image, IsArchive = data.IsArchive, IsPin = data.IsPin, IsTrash = data.IsTrash, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; // add new note in tabel this.authenticationContext.Note.Add(noteInfo); // save the changes in database await this.authenticationContext.SaveChangesAsync(); var user = this.authenticationContext.UserDataTable.Where(s => s.Email == noteInfo.UserID); var colaborator = new ColaboratorModel() { UserID = userID, NoteID = noteInfo.NoteID, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; this.authenticationContext.Colaborator.Add(colaborator); await this.authenticationContext.SaveChangesAsync(); NoteResponse nr = this.GetNoteResponse(userID, noteInfo); return(nr); } else { var noteInfo = new NoteModel() { UserID = userID, Title = data.Title, Description = data.Description, Collaborators = data.Collaborator, Color = data.Color, Reminder = data.Reminder, Image = data.Image, IsArchive = data.IsArchive, IsPin = data.IsPin, IsTrash = data.IsTrash, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; this.authenticationContext.Note.Add(noteInfo); await this.authenticationContext.SaveChangesAsync(); NoteResponse nr = this.GetNoteResponse(userID, noteInfo); return(nr); } } else { throw new Exception("Note is not created"); } } catch (Exception exception) { throw new Exception(exception.Message); } }