示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _repository.UpdateAsync(CommonExample);

            try
            {
                await _repository.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_repository.CommonExampleExists(CommonExample.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <ExampleUpdateResponse> UpdateAsync(int id, ExampleUpdateRequest request) => await ExecuteAsync(async() =>
        {
            var response = new ExampleUpdateResponse();
            var example  = await _exampleRepository.GetByIdAsync(id, false).ConfigureAwait(false);
            if (example != null)
            {
                //Changing property
                example.Update(request.Age, request.Name);

                //Validate
                example.Validate(example, new ExampleValidator());
                if (!example.Valid)
                {
                    _notification.AddNotifications(example.ValidationResult);
                    return(response);
                }

                await _exampleRepository.UpdateAsync(example).ConfigureAwait(false);
            }
            else
            {
                throw new NotFoundException();
            }
            return(response);
        });
示例#3
0
        public async Task <ActionResult> Put([FromBody] Example example)
        {
            try
            {
                await exampleRepository.UpdateAsync(example);

                return(Ok());
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Failed to udpate Example");
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve examples"));
            }
        }
示例#4
0
        public async Task <IResult> UpdateAsync(Example example)
        {
            var updated = await _exampleRepository.GetAsync(i => i.Id == example.Id);

            if (updated != null)
            {
                updated.Title       = example.Title;
                updated.Description = example.Description;
                await _exampleRepository.UpdateAsync(updated);

                return(new SuccessResult("Örnek Veri Başarıyla Güncellenmiştir."));
            }

            else
            {
                return(new ErrorResult($"{example.Id} Id'sine sahip Örnek Veri Bulunamadığı için güncelleme işlemi başarısız oldu."));
            }
        }
示例#5
0
 public async Task <int> UpdateExampleModelAsync(ExampleModel model)
 {
     return(await _repository.UpdateAsync(model));
 }