예제 #1
0
        public IActionResult Create([FromForm] NoteCreateRequest request)
        {
            try
            {
                var userId = _authenticationService.GetAuthenticatedUserId(User);
                var tag    = (NoteTag)Enum.ToObject(typeof(NoteTag), request.Tag);

                var noteId = _noteService.Create(request.LectureId, request.Name, request.Description, tag, request.Document, userId);
                return(new ObjectResult(new
                {
                    StatusCode = ResponseConstants.Success,
                    NoteId = noteId
                }));
            }
            catch (Exception)
            {
                return(new ObjectResult(new Result {
                    StatusCode = ResponseConstants.Unknown
                }));
            }
        }
예제 #2
0
        public async Task <IActionResult> PostNote(NoteCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(400));
            }

            int identityClaimNum = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var dto = _mapper.Map <NoteCreateDTO>(request);

            dto.DateCreated = DateTime.Now;
            dto.OwnerId     = identityClaimNum;

            if (await _manager.CreateNote(dto))
            {
                return(StatusCode(201));
            }

            throw new Exception();
        }