예제 #1
0
        public async Task Create([FromForm] ArticleInputModelApi newData)
        {
            await _apiHealper.DoStandartSomething(
                async() =>
            {
                newData.Validate(_apiHealper.StringValidator, _apiHealper.FileValidator, ModelState);
                _apiHealper.ErrorsFromModelState(ModelState);
                if (_errorService.HasError())
                {
                    throw new StopException();
                }

                var userInfo = _apiHealper.CheckAuthorized(Request, _jwtService, true);

                var newArticle = await _articleService.Create(newData.GetModel(), userInfo);
                await _apiHealper.WriteResponseAsync(Response, _articleReturnFactory.GetObjectReturn(newArticle));
            }, Response, _logger);
        }
예제 #2
0
        public async Task Edit([FromForm] ArticleInputModelApi newData)
        {
            //ArticleInputModel newData = null;
            await _apiHealper.DoStandartSomething(
                async() =>
            {
                if (newData.Id == null)
                {
                    ModelState.AddModelError("id_is_required", "не передано id");   //TODO подумать как вынести в общий кусок все такие штуки
                }

                newData.Validate(_apiHealper.StringValidator, _apiHealper.FileValidator, ModelState);
                _apiHealper.ErrorsFromModelState(ModelState);
                if (_errorService.HasError())
                {
                    throw new StopException();
                }

                var userInfo = _apiHealper.CheckAuthorized(Request, _jwtService, true);

                var res = await _articleService.Update(newData.GetModel(), userInfo);
                await _apiHealper.WriteResponseAsync(Response, _articleReturnFactory.GetObjectReturn(res));
            }, Response, _logger);
        }