public async Task <CommandResult> AddAsync(Country country) { CommandResult commandResult; Stopwatch watch = Stopwatch.StartNew(); try { if (!await CanAddAsync(country, true)) { commandResult = CommandResult.BadRequest("Registro não pode ser salvo, existem erros."); } else { country = await CountryRepository.AddAsync(country); commandResult = await CommitAsync(_commandName, country.Action); if (commandResult.Success) { commandResult.Data = country; } } } catch (Exception ex) { commandResult = CommandResult.InternalServerError($"Ocorreu um erro ao salvar."); } watch.Stop(); commandResult.ElapsedTime = watch.ElapsedMilliseconds; return(commandResult); }
public async Task <ActionResult> Create(Country country) { if (ModelState.IsValid) { await _repository.AddAsync(country); //db.Countries.Add(country); //await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(country)); }