public ActionResult <ItemResponse <int> > Add(FAQAddRequest model)
        {
            ObjectResult result = null;

            int userId = _authService.GetCurrentUserId();

            try
            {
                int id = _service.Add(model, userId);
                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };

                result = Created201(response);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                ErrorResponse response = new ErrorResponse(ex.Message);

                result = StatusCode(500, response);
            }

            return(result);
        }
 public IActionResult Create([FromForm] FAQ faq)
 {
     try
     {
         faq.FAQTranslates = JsonSerializer.Deserialize <ICollection <FAQTranslate> >(faq.Translates);
         if (!ModelState.IsValid)
         {
             return(StatusCode(StatusCodes.Status500InternalServerError, new Response
             {
                 Status = "Error",
                 Messages = new Message[] {
                     new Message {
                         Lang_id = 1,
                         MessageLang = "Model state isn't valid!"
                     },
                     new Message {
                         Lang_id = 2,
                         MessageLang = "Состояние модели недействительно!"
                     },
                     new Message {
                         Lang_id = 3,
                         MessageLang = "Model vəziyyəti etibarsızdır!"
                     }
                 }
             }));
         }
         _faqContext.Add(faq);
         foreach (FAQTranslate item in faq.FAQTranslates)
         {
             item.FAQId = faq.Id;
             _faqTranslateContext.Add(item);
         }
         return(Ok());
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
Beispiel #3
0
 public async Task <IActionResult> Add([FromBody] AddFAQModel model)
 {
     return(await MakeActionCallAsync(async() => await _service.Add(model)));
 }