コード例 #1
0
ファイル: DeckController.cs プロジェクト: DaneArt/MyDeckAPI
        public async Task <IActionResult> Insert([FromBody] System.Text.Json.JsonElement value)
        {
            try
            {
                Deck deck = JsonConvert.DeserializeObject <Deck>(value.GetRawText());


                await deckRepository.Insert(deck);

                await userDeckRepository.Insert(
                    new UserDeck { User_Id = Guid.Parse(deck.Author), Deck_Id = deck.Deck_Id });

                deckRepository.Save();

                logger.LogInformation("------------> Deck/s have been added <------------");
                return(Ok());
            }
            catch (Exception ex)
            {
                logger.LogWarning("------------> An error has occurred <------------ \n" + ex.Message);
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Subscribe(string deckId, string userId)
        {
            try
            {
                var content = new UserDeck
                {
                    Deck_Id = Guid.Parse(deckId),
                    User_Id = Guid.Parse(userId),
                };

                await db.Insert(content);

                db.Save();

                logger.LogInformation("------------> Userdeck/s have been added <------------");
                return(Ok());
            }
            catch (Exception ex)
            {
                logger.LogWarning("------------> An error has occurred <------------ \n" + ex.Message);
                return(BadRequest(ex.Message));
            }
        }