public async Task <ActionResult> Post([FromBody] MemoViewModel viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);

                var model = _mapper.Map <MemoModel>(viewModel);
                await _service.CreateAsync(model);

                var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok();

                return(Created(String.Concat(Request.Path, "/", 0), result));
            }
            catch (ServiceValidationException e)
            {
                var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }
示例#2
0
        public async Task <ActionResult> SaveMemo(MemoDto memo)
        {
            // pull userid from JWT
            memo.UserLoginId = int.Parse(((ClaimsIdentity)HttpContext.User.Identity)
                                         .FindFirst(ClaimTypes.NameIdentifier).Value);

            var result = await _memoService.CreateAsync(memo);

            return(Ok(result));
        }
示例#3
0
        public async Task <ActionResult> Post([FromBody] CreateMemo command)
        {
            if (User.Identity.IsAuthenticated)
            {
                command.UserId = Guid.Parse(User.Identity.Name);
                command.MemoId = Guid.NewGuid();
                await _memoService.CreateAsync(command.MemoId, command.Name, command.Description, command.UserId);
            }

            return(Created($"memos/{command.MemoId}", null));
        }