public JsonResult Add(AddRiskForm form) { var customer = _context.Customers.Include(x => x.Risks).Single(x => x.Id == form.CustomerId); var risk = Mapper.Map<Risk>(form); customer.Risks.Add(risk); _context.SaveChanges(); var model = Mapper.Map<CustomerRiskViewModel>(risk); return BetterJson(model); }
public JsonResult Add(AddRiskForm form) { var customer = _context.Customers.Include(x => x.Risks).Single(x => x.Id == form.CustomerId); var risk = Mapper.Map <Risk>(form); customer.Risks.Add(risk); _context.SaveChanges(); var model = Mapper.Map <CustomerRiskViewModel>(risk); return(BetterJson(model)); }