public async Task <Example> UpdateExample(Guid id, Example request)
        {
            var oldExample = await _exampleRepository.GetByIdAsync(id);

            if (oldExample == null)
            {
                await _notifications.AddNotificationAsync(new DomainNotification("ExampleBusiness", "Example não encontrado."));

                return(await Task.FromResult(request));
            }

            var newExample = Example.ExampleFactory.UpdateExample(oldExample, request.Descricao);

            if (!await IsValidAsync(newExample))
            {
                return(await Task.FromResult(request));
            }

            _exampleRepository.Update(newExample);


            if (await Commit())
            {
                return(await Task.FromResult(newExample));
            }

            return(request);
        }
Example #2
0
        public IActionResult Put(int id, [FromBody] MyModelViewModel viewModel)
        {
            try
            {
                if (viewModel == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                MyModel singleById = _exampleRepository.GetSingle(id);

                if (singleById == null)
                {
                    return(NotFound());
                }

                singleById.Name = viewModel.Name;

                _exampleRepository.Update(singleById);
                int save = _exampleRepository.Save();

                if (save > 0)
                {
                    return(Ok(Mapper.Map <MyModelViewModel>(singleById)));
                }

                return(BadRequest());
            }
            catch (Exception exception)
            {
                //Do something with the exception
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
 public void Put(int id, [FromBody] Example model)
 {
     _exampleRepository.Update(model);
 }
Example #4
0
 public async Task <bool> Update(long id, Example updatedEntity)
 {
     return(await _exampleRepository.Update(id, updatedEntity));
 }
Example #5
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="data">The record passed in.</param>
        /// <returns>The updated record.</returns>
        public ExampleModel Update(ExampleModel data)
        {
            var myData = repository.Update(data);

            return(myData);
        }