public JsonResult Add(AddOpportunityForm form) { var customer = _context.Customers.Include(x => x.Opportunities).Single(x => x.Id == form.CustomerId); var opportunity = Mapper.Map <Opportunity>(form); customer.Opportunities.Add(opportunity); _context.SaveChanges(); var model = Mapper.Map <CustomerOpportunityViewModel>(opportunity); return(BetterJson(model)); }
public JsonResult Add(AddOpportunityForm form) { var customer = _context.Customers.Include(x => x.Opportunities).Single(x => x.Id == form.CustomerId); var opportunity = Mapper.Map<Opportunity>(form); customer.Opportunities.Add(opportunity); _context.SaveChanges(); var model = Mapper.Map<CustomerOpportunityViewModel>(opportunity); return BetterJson(model); }