コード例 #1
0
ファイル: PostageAppService.cs プロジェクト: LayaneB/Backend
        public async Task <Postage> UpdateAsync(int id, PostageInput postageInput)
        {
            var clientId = _logged.GetClientLoggedId();
            var postage  = await _postageRepository
                           .GetPostageByIdAsync(id)
                           .ConfigureAwait(false);

            if (postage is null)
            {
                throw new Exception("Postagem não encontrada");
            }

            postage.UpdateInfo(postageInput.Text,
                               postageInput.Photo,
                               postageInput.Video);

            await _postageRepository
            .UpdateAsync(id, postage)
            .ConfigureAwait(false);

            return(new Postage(postage.Text,
                               postage.Photo,
                               postage.Video,
                               clientId,
                               DateTime.Now));
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] PostageInput postageInput)
        {
            try
            {
                var postage = await _postageAppService
                              .InsertAsync(postageInput)
                              .ConfigureAwait(false);

                return(Created("", postage));
            }
            catch (ArgumentException arg)
            {
                return(BadRequest(arg.Message));
            }
        }
コード例 #3
0
        public async Task <Postage> InsertAsync(PostageInput input)
        {
            var userId = _logged.GetUserLoggedId();

            var postage = new Postage(input.Text, input.Foto, userId);

            //Validar classe com dados obrigatorios..

            var id = await _postageRepository
                     .InsertAsync(postage)
                     .ConfigureAwait(false);

            postage.SetId(id);

            return(postage);
        }
コード例 #4
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] PostageInput postageInput)
        {
            try
            {
                await _postageAppService
                .UpdateAsync(id, postageInput)
                .ConfigureAwait(false);

                return(Accepted(postageInput));
            }
            catch (ArgumentException arg)
            {
                return(BadRequest(arg.Message));
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }
        }
コード例 #5
0
ファイル: PostageAppService.cs プロジェクト: LayaneB/Backend
        public async Task <Postage> InsertAsync(PostageInput input)
        {
            var clientId = _logged.GetClientLoggedId();

            var postage = new Postage(input.Text,
                                      input.Photo,
                                      input.Video,
                                      clientId,
                                      DateTime.Now);

            //Validar classe com dados obrigatorios..

            var id = await _postageRepository
                     .InsertAsync(postage)
                     .ConfigureAwait(false);

            postage.SetId(id);

            return(postage);
        }
コード例 #6
0
        public async Task <Postage> InsertAsync(PostageInput input)
        {
            var userId = _logged.GetUserLoggedId();

            var postage = new Postage(input.Text, userId, input.Photo);

            if (postage.Text == null || postage.Text == "")
            {
                throw new ArgumentException("Existem dados que são obrigatórios e não foram preenchidos");
            }



            var id = await _postageRepository
                     .InsertAsync(postage)
                     .ConfigureAwait(false);

            postage.SetId(id);

            return(postage);
        }