Пример #1
0
        public async Task <IActionResult> Update([FromBody] NoteContract contract)
        {
            try
            {
                var note          = contract.Note;
                var itemForUpdate = await _noteRepository.FindByIdAsync(note.Id);

                if (itemForUpdate == null)
                {
                    return(BadRequest("Item not found"));
                }
                var curentUser = await _userManager.FindByEmailAsync(HttpContext.User.Identity.Name);

                itemForUpdate.UserId      = curentUser.Id;
                itemForUpdate.Name        = note.Name;
                itemForUpdate.Description = note.Description;
                itemForUpdate.ModifiedAt  = DateTime.Now;
                itemForUpdate.Position    = note.Position;

                await _noteRepository.UpdateAsync(itemForUpdate);

                return(Ok(itemForUpdate));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
Пример #2
0
        public async Task <IActionResult> Create([FromBody] NoteContract contract)
        {
            try
            {
                var note       = contract.Note;
                var curentUser = await _userManager.FindByEmailAsync(HttpContext.User.Identity.Name);

                note.UserId = curentUser.Id;
                await _noteRepository.CreateAsync(note);

                return(Ok(note));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }