public async Task <IActionResult> PutUsuarioModel(string id, [Bind("UsuarioModel, ImageBase64")] CreateAndUpdateHttpUsuarioModel createUsuarioModel)
        {
            var usuarioModel = createUsuarioModel.UsuarioModel;
            var imageBase64  = createUsuarioModel.ImageBase64;

            if (id != usuarioModel.IdentityUser)
            {
                return(BadRequest());
            }

            try
            {
                _unitOfWork.BeginTransaction();
                await _usuarioServices.UpdateAsync(usuarioModel, imageBase64);

                await _unitOfWork.CommitAsync();
            }
            catch (ModelValidationExceptions e)
            {
                ModelState.AddModelError(e.PropertyName, e.Message);
                return(BadRequest(ModelState));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(NoContent());
        }
Example #2
0
        public async Task UpdateAsync(UsuarioModel usuarioModel, string base64)
        {
            var updateModel = new CreateAndUpdateHttpUsuarioModel
            {
                UsuarioModel = usuarioModel,
                ImageBase64  = base64
            };

            var pathWithId = $"{_projetoHttpOptions.CurrentValue.UsuarioPath}/{usuarioModel.IdentityUser}";

            var httpContent = new StringContent(JsonConvert.SerializeObject(updateModel), Encoding.UTF8, "application/json");

            var httpResponseMessage = await _httpClient.PutAsync(pathWithId, httpContent);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
            }
        }
        public async Task <ActionResult <UsuarioModel> > PostUsuarioModel([Bind("UsuarioModel, ImageBase64")] CreateAndUpdateHttpUsuarioModel createUsuarioModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var usuarioModel = createUsuarioModel.UsuarioModel;
            var imageBase64  = createUsuarioModel.ImageBase64;

            try
            {
                await _usuarioServices.CreateAsync(usuarioModel, imageBase64);
            }
            catch (ModelValidationExceptions e)
            {
                ModelState.AddModelError(e.PropertyName, e.Message);
                return(BadRequest(ModelState));
            }

            return(Ok(createUsuarioModel));
        }