示例#1
0
        public async Task <IActionResult> UpdateNote([FromBody] NotesRequestModel notesModel1, int noteId)
        {
            try
            {
                var    user = HttpContext.User;
                bool   status;
                string message;
                if (user.HasClaim(c => c.Type == "TokenType"))
                {
                    if (user.Claims.FirstOrDefault(c => c.Type == "TokenType").Value == "Login")
                    {
                        int userId = Convert.ToInt32(user.Claims.FirstOrDefault(c => c.Type == "Id").Value);
                        NoteResponseModel notesModel = await this._notesBusiness.UpdateNotes(notesModel1, noteId, userId);

                        if (notesModel != null)
                        {
                            status  = true;
                            message = "Note updated";
                            return(this.Ok(new { status, message, notesModel }));
                        }
                    }
                }

                status  = false;
                message = "Note not updated";
                return(this.NotFound(new { status, message }));
            }
            catch (Exception e)
            {
                return(this.BadRequest(new { e.Message }));
            }
        }
示例#2
0
        // [Route("AddNotes")]
        public async Task <IActionResult> AddNotes([FromBody] NotesRequestModel notesModel)
        {
            try
            {
                var               user = HttpContext.User;
                bool              status;
                string            message;
                NoteResponseModel model = new NoteResponseModel();
                if (user.HasClaim(c => c.Type == "TokenType"))
                {
                    if (user.Claims.FirstOrDefault(c => c.Type == "TokenType").Value == "Login")
                    {
                        int userId = Convert.ToInt32(user.Claims.FirstOrDefault(c => c.Type == "Id").Value);
                        var data   = await this._notesBusiness.AddNotes(notesModel, userId);

                        if (data != null)
                        {
                            status  = true;
                            message = "Note created";
                            return(this.Ok(new { status, message, data }));
                        }
                    }
                }

                status  = false;
                message = "Note not created";
                return(this.BadRequest(new { status, message }));
            }
            catch (Exception e)
            {
                return(this.BadRequest(new { e.Message }));
            }
        }
示例#3
0
 public async Task <NoteResponseModel> UpdateNotes(NotesRequestModel notesModel, int noteId, int userId)
 {
     if (notesModel != null)
     {
         return(await _notesRepository.UpdateNotes(notesModel, noteId, userId));
     }
     else
     {
         return(null);
     }
 }
示例#4
0
 public async Task <NoteResponseModel> AddNotes(NotesRequestModel notesModel, int userId)
 {
     try
     {
         if (notesModel != null && userId != 0)
         {
             return(await this._notesRepository.AddNotes(notesModel, userId));
         }
         else
         {
             return(null);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        public async Task <ActionResult <PaginatedResult <NoteModel> > > GetNotesAsync([FromQuery] NotesRequestModel model)
        {
            var userId = HttpContext.GetSessionUserId();

            var queryModel = _mapper.Map <NoteQueryModel>(model);

            var notes = await _noteService.GetNotesAsync(
                queryModel, userId);

            return(Ok(notes));
        }