public async Task <IActionResult> Edit(int id, [Bind("CountryId,Name,Code")] Country country) { if (id != country.CountryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(country); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(country.CountryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <IActionResult> Edit(int id, [Bind("StateId,Name,Code,CountryId")] State state) { if (id != state.StateId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(state); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StateExists(state.StateId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "Name", state.CountryId); return(View(state)); }
public async Task <IActionResult> Edit(int id, [Bind("SalesRepresentativeId,Fullname,Employecode")] SalesRepresentative salesRepresentative) { if (id != salesRepresentative.SalesRepresentativeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(salesRepresentative); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalesRepresentativeExists(salesRepresentative.SalesRepresentativeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(salesRepresentative)); }
public async Task <IActionResult> Edit(int id, [Bind("ClientId,Nit,Fullname,Address,Phone,CountryId,StateId,CityId,CreditLimit,AvailableCredit,VisitsPercentage")] Client client) { if (id != client.ClientId) { return(NotFound()); } if (ModelState.IsValid) { try { client.Nit = Client.EncryptString(client.Nit, key); _context.Update(client); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(client.ClientId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.Cities, "CityId", "Name", client.CityId); ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "Name", client.CountryId); ViewData["StateId"] = new SelectList(_context.States, "StateId", "Name", client.StateId); return(View(client)); }
public async Task <IActionResult> Create([Bind("VisitId,Date,ClientId,SalesRepresentativeId,Net,Description")] Visit visit) { if (ModelState.IsValid) { //Informacion client var client = await _context.Clients.Include(v => v.Visits).Where(v => v.ClientId == visit.ClientId).FirstOrDefaultAsync(); client.AvailableCredit = (client.AvailableCredit - visit.Net); client.VisitsPercentage = (client.AvailableCredit * 100) / client.CreditLimit; visit.VisitTotal = visit.Net * client.VisitsPercentage; _context.Update(client); _context.Add(visit); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(_context.Clients, "ClientId", "Fullname", visit.ClientId); ViewData["SalesRepresentativeId"] = new SelectList(_context.SalesRepresentatives, "SalesRepresentativeId", "Fullname", visit.SalesRepresentativeId); return(View(visit)); }