Пример #1
0
        public IHttpActionResult Update(int?id, UpdateNoteDTO dto)
        {
            if (id == null || dto == null || id != dto.Id)
            {
                return(BadRequest());
            }

            var note = db.Notes.FirstOrDefault(x => x.Id == id && x.AuthorId == UserId);

            if (note == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                note.Title            = dto.Title;
                note.Content          = dto.Content;
                note.ModifivationTime = DateTime.Now;
                db.SaveChanges();
                return(Ok(note.ToNoteDto()));
            }

            return(BadRequest(ModelState));
        }
Пример #2
0
        public async Task <ActionResult <ReturnPrivateNoteDTO> > UpdateNote(UpdateNoteDTO updateNoteDTO)
        {
            var id = _tokenHelper.GetIdByToken(HttpContext.Request.Headers["Authorization"]);

            var note = await _apiHelper.UpdateNote(updateNoteDTO.Message, updateNoteDTO.NoteId, id);

            if (note == null)
            {
                return(BadRequest(new {
                    errors = "Niepoprawne id notatki."
                }));
            }

            return(_mapper.Map <ReturnPrivateNoteDTO>(note));
        }
Пример #3
0
        public IActionResult UpdateNote(int noteId, [FromBody] UpdateNoteDTO updateNoteDTO)
        {
            if (updateNoteDTO == null || noteId != updateNoteDTO.Id)
            {
                return(BadRequest(ModelState));
            }

            var noteObj = _mapper.Map <Note>(updateNoteDTO);

            if (!_noteRepo.UpdateNote(noteObj))
            {
                ModelState.AddModelError("", $"Something went wrong when updating the record {noteObj.Title}");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }
Пример #4
0
        public HttpResponseMessage UpdateNote(UpdateNoteDTO note)
        {
            try
            {
                using (var context = new TodoAppContext())
                {
                    var user = AuthService.getCurrUserInfo(HttpContext.Current.Request.Headers);
                    if (user == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }

                    var c = context.notes.Where(n => n.noteID == note.noteID && n.createdBy == user.userID).FirstOrDefault();
                    if (c == null)
                    {
                        NotFound();
                    }
                    c.title       = note.title;
                    c.description = note.description;
                    c.dueDate     = DateTime.Parse(note.dueDate);
                    c.noteStatus  = Status.TODO;
                    c.noteType    = (Models.Type)note.type;
                    c.colorHex    = note.colorHex;
                    c.remindMe    = (Models.remindMeType)note.remindMe;
                    if (note.tagId != 0)
                    {
                        c.tagID   = note.tagId;
                        c.tagName = context.tags.Where(t => t.tagID == note.tagId).Select(d => d.Name).FirstOrDefault();
                    }
                    context.SaveChanges();
                    var result = context.notes.Where(n => n.createdBy == user.userID).ToList();
                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadGateway, e));
            }
        }