public async Task <IActionResult> PutLead(string id, Lead lead) { if (id != lead.Id) { return(BadRequest()); } var company = await _context.Companies.FirstOrDefaultAsync(c => c.Id == lead.CompanyId); company.ContactId = lead.Id; _context.Entry(lead).State = EntityState.Modified; _context.Entry(company).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LeadExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProduct(string id, Product product) { if (id != product.Id) { return(BadRequest()); } _context.Entry(product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCompany(string id, Company company) { if (id != company.Id) { return(BadRequest()); } _context.Entry(company).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(string id, [Bind("Id,FirstName,LastName,PhoneNumber,Email,Address,CompanyId,Gender")] Lead lead) { if (id != lead.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var oldCompany = await _context.Companies.FirstOrDefaultAsync(c => c.ContactId == lead.Id); if (oldCompany != null) { oldCompany.ContactId = null; _context.Entry(oldCompany).State = EntityState.Modified; } var company = await _context.Companies.FirstOrDefaultAsync(c => c.Id == lead.CompanyId); if (company != null) { company.ContactId = lead.Id; _context.Entry(company).State = EntityState.Modified; } _context.Entry(lead).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LeadExists(lead.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", lead.CompanyId); var leadGender = new LeadGender(); ViewData["GenderName"] = new SelectList((IEnumerable)leadGender.AllGender, "Key", "Value"); return(View(lead)); }