示例#1
0
        public async Task <IActionResult> Create([FromBody] BookmarkDto bookmarkDto)
        {
            var userId = int.Parse(this.User.Identity.Name);

            var bookmark = new Bookmark().PopulateWith(bookmarkDto);

            bookmark.CreatedById  = userId;
            bookmark.ModifiedById = userId;

            BookmarkDto dto = null;

            try
            {
                // save
                bookmark = await _bookmarksRepository.Create(bookmark);

                dto = GetDtoById(bookmark.Id);
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }

            await _hubContext.SendMessage(new HubMessage
            {
                Action = HUBMESSAGE_BOOKMARK_CREATED,
                Data   = new Dictionary <string, object>
                {
                    { "bookmark", dto }
                }
            });

            return(Ok(dto));
        }