public async Task <IActionResult> Add(ExampleViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var example = Mapper.Map <Example>(model); using (var transaction = await _context.BeginTransactionAsync()) { try { await _context.AddAsync(example); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); ModelState.AddModelError("SqlContextError", e.Message); return(View(model)); } } return(RedirectToAction("Index")); }
public async Task<IHttpActionResult> Post(JobVacancy job) { await _dbContext.AddAsync(job); await _dbContext.SaveChangesAsync(); return Ok(job); }