public async Task <IActionResult> Create([Bind("UserId,Name,LastName,Email")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("CreditTypeId,Name,MonthTerm,Interest")] CreditType creditType) { if (ModelState.IsValid) { _context.Add(creditType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(creditType)); }
public async Task <IActionResult> Create([Bind("AffiliateId,Name,LastName,BirthDate,AdmissionDate,JobPosition,NetSalary")] Affiliate affiliate) { if (ModelState.IsValid) { _context.Add(affiliate); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(affiliate)); }
public async Task <IActionResult> Create([Bind("UserTypeId,Type")] UserType userType) { if (ModelState.IsValid) { _context.Add(userType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userType)); }
public async Task <IActionResult> Create(SavingsViewModel model) { if (ModelState.IsValid) { var saving = new Saving { Amount = model.Amount, Type = _context.SavingType.SingleOrDefault(u => u.SavingTypeId == model.SavingTypeId) }; _context.Add(saving); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(CTVModel model) { Random random = new Random(); if (ModelState.IsValid) { var credit = new Credit { Affiliate = _context.Affiliates.FirstOrDefault(a => a.AffiliateId == random.Next(2, 12)), Amount = model.Amount, Purpose = model.Purpose, State = 1, Aproved = false, Type = _context.CreditType.SingleOrDefault(u => u.CreditTypeId == model.CreditTypeId) }; _context.Add(credit); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Delete(int id) { var a = await _aContext.A.FindAsync(id); if (a == null) { return(NotFound($"Object A with Id = {id} not found.")); } _aContext.A.Remove(a); await _aContext.SaveChangesAsync(); return(Ok()); }
private async Task ValidateAndSave() { if (_currentIndex != null) { // Validate var hasErrors = false; if (!_hasId) { _messages.AddLast($"Parameter guid[{_currentIndex}] is not provided."); hasErrors = true; } for (var i = 0; i < _files.Length; i++) { if (_files[i] == null) { _messages.AddLast($"Parameter file{i + 1}[{_currentIndex}] is not provided."); hasErrors = true; } } // Write to DB if (hasErrors) { // Remove created files foreach (var filename in _files) { if (filename == null) { continue; } try { _fileStore.Delete(filename); } catch (Exception ex) { _logger.LogError(ex.Message); } } _messages.AddLast($"Skipping object [{_currentIndex}]. See _messages above to get more information."); } else { try { var a = _aContext.A.Find(_id); if (a == null) // A with the same id does not exist in the DB { await _aContext.A.AddAsync(new A(_id, _files[0], _files[1], _files[2])); } else // A with the same id already exists in the DB { a.File1 = _files[0]; a.File2 = _files[1]; a.File3 = _files[2]; _messages.AddLast($"Object with id = {_id} was already presented in the databse and will be overwritten."); } await _aContext.SaveChangesAsync(); } catch (Exception ex) { _messages.AddLast($"An error occured when saving [{_currentIndex}], id = {_id}. The object was not saved to the database."); _logger.LogError(ex.Message); } } // Reset state _hasId = false; _id = Guid.Empty; for (var i = 0; i < _files.Length; i++) { _files[i] = null; } } }