public async Task <IActionResult> SaveClient(Client client) { if (ModelState.IsValid) { if (client.Id == null) { _context.Clients.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Client")); } var clientInDb = await _context.Clients.FindAsync(client.Id); await TryUpdateModelAsync <Client>( clientInDb, "", c => c.Name, c => c.Email, c => c.Street, c => c.City, c => c.Postal_code, c => c.Province, c => c.Country ); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Client")); } return(View("ClientForm")); }
public async Task <IActionResult> SaveEditInvoice(int InvoiceId, int clientId, DateTime dateOfIssue, DateTime dueDate, bool paid, float taxRate) { var InvoiceInDb = await _context .Invoices.FindAsync(InvoiceId); if (InvoiceInDb == null) { return(NotFound()); } await TryUpdateModelAsync <Invoice>( InvoiceInDb, "", i => i.DateOfIssue, i => i.DueDate, i => i.Paid, i => i.TaxRate ); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); //ViewBag.InvoiceId = InvoiceInDb.Id; //return RedirectToAction("InvoiceDetail", new { id = InvoiceInDb.Id }); }
public async Task <IActionResult> Signup(SignupAttempt signupattempt) { ViewBag.ErrorMsg = ""; if (ModelState.IsValid) { if (_context.Users.Count() > 0) { //Ensure this signup info hasn't already been saved to the DB. var user = _context.Users .FirstOrDefault(s => s.EmailAddress == signupattempt.EmailAddress); if (user != null) { ViewBag.ErrorMsg = "User with this email already exists"; return(View(signupattempt)); } } var newUser = new User() { FirstName = signupattempt.FirstName, LastName = signupattempt.LastName, EmailAddress = signupattempt.EmailAddress, Password = signupattempt.Password }; //save to db _context.Users.Add(newUser); await _context.SaveChangesAsync(); return(Login()); } return(View(signupattempt)); }
public async Task <IActionResult> Update(User user) { var userInDb = await _context.Users.FirstOrDefaultAsync(u => u.EmailAddress == user.EmailAddress); await TryUpdateModelAsync <User>( userInDb, "", u => u.FirstName, u => u.LastName, u => u.EmailAddress ); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "User")); }