public EntityResult UpdateCountry(CountryViewModel countryModel) { try { if (countryModel == null) { throw new ArgumentNullException("countryModel"); } var currentCountry = _unitOfWork.CountryRepository.GetByID(countryModel.CountryId); if (currentCountry == null) { throw new ArgumentException("countryModel"); } var country = countryModel.ToCountry(); var result = ValidateCountry(country); if (result != null && result.Count > 0) { return(EntityResult.Failed(result.ToArray())); } _unitOfWork.CountryRepository.Update(country); _unitOfWork.Save(); return(EntityResult.Success); } catch (Exception ex) { _logger.Error(ex, ex.Message); throw; } }
public async Task <IActionResult> Create([Bind("Name")] CountryViewModel vm) { if (ModelState.IsValid) { var Country = vm.ToCountry(); var createOperation = await _bo.CreateAsync(Country); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } return(OperationSuccess("The record was successfuly created")); } return(View(vm)); }