public async Task <IActionResult> Create(CreateCompanyViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } viewModel.Company.Id = Guid.NewGuid(); _context.Add(viewModel.Company); viewModel.PrimaryContact.Id = Guid.NewGuid(); viewModel.PrimaryContact.CompanyId = viewModel.Company.Id; _context.Add(viewModel.PrimaryContact); var site = new Site { Address = viewModel.Company.Address, CompanyId = viewModel.Company.Id }; _context.Add(site); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(Site site) { if (ModelState.IsValid) { site.Id = Guid.NewGuid(); _context.Add(site); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "CompanyName", site.CompanyId); return(View(site)); }
public async Task <IActionResult> Create([Bind("JobRole,CompanyId,Id,Created,Modified")] Contact contact) { if (ModelState.IsValid) { contact.Id = Guid.NewGuid(); _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "CompanyName", contact.CompanyId); return(View(contact)); }
public async Task <IActionResult> Create([Bind("SiteId,ContractId,ScheduledDateTime,EstimatedDurationMins,ActualDurationMins,EstimatedAppliances,ActualAppliances,TestSlowResult,Id,Created,Modified")] TestSlot testSlot) { if (ModelState.IsValid) { testSlot.Id = Guid.NewGuid(); _context.Add(testSlot); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ContractId"] = new SelectList(_context.Contracts, "Id", "Id", testSlot.ContractId); ViewData["SiteId"] = new SelectList(_context.Sites, "Id", "Id", testSlot.SiteId); return(View(testSlot)); }
public async Task <IActionResult> Create(CreateContractViewModel contractViewModel) { var contract = new Contract { CompanyId = contractViewModel.CompanyId, StartDate = contractViewModel.StartDate, IntervalMonths = contractViewModel.IntervalMonths, Price = contractViewModel.Price, RenewalDate = contractViewModel.StartDate.AddYears(contractViewModel.ContractLengthYears) }; if (ModelState.IsValid) { contract.Id = Guid.NewGuid(); _context.Add(contract); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Companies", new { id = contractViewModel.CompanyId })); } ViewData["CompanyId"] = contractViewModel.CompanyId; return(View(contractViewModel)); }