Exemplo n.º 1
0
        public IHttpActionResult UpdateNote(int id, SaveNoteBindingModel noteModel)
        {
            if (!ModelState.IsValid)
            {
                var dfg = BadRequest(ModelState);
                return BadRequest(ModelState);
            }

            var note = this.data.Notes.Find(id);
            if (note == null)
            {
                return BadRequest("No such note!");
            }

            note.NoteText = noteModel.NoteText;

            this.data.Notes.Update(note);
            this.data.SaveChanges();
            return Ok();
        }
Exemplo n.º 2
0
        public IHttpActionResult SaveNote(SaveNoteBindingModel noteModel)
        {
            if (!ModelState.IsValid)
            {
                var dfg = BadRequest(ModelState);
                return BadRequest(ModelState);
            }

            var currentUserId = this.userIdProvider.GetUserId();
            var passwordHash = noteModel.Password;
            var encryptedText = noteModel.NoteText;
            if(noteModel.Password != null)
            {
                passwordHash = this.securityProvider.HashPassword(noteModel.Password);
                encryptedText = this.securityProvider.EncryptText(noteModel.NoteText, passwordHash);
            }

            var note = new Note()
            {
                Date = noteModel.Date,
                DateCreated = DateTime.Now,
                DateModified = DateTime.Now,
                NoteText = encryptedText,
                PasswordHash = passwordHash,
                Type = NoteType.Normal,
                UserId = currentUserId
            };

            this.data.Notes.Add(note);
            this.data.SaveChanges();

            return Ok(note.Id);
        }