public async Task <IActionResult> Create([Bind("ContactID,FirstName,LastName,JobTitle,CellPhone,WorkPhone,Email,Active,Notes,CompanyID")] Contact contact, string[] selectedOptions) { //Get the URL with the last filter, sort and page parameters ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Contacts"); //ViewData["returnURL"] = returnURL; try { // Adding the multi select categories if (selectedOptions != null) { foreach (var category in selectedOptions) { var categoryToAdd = new ContactCategories { ContactID = contact.ContactID, CategoriesID = int.Parse(category) }; contact.ContactCategories.Add(categoryToAdd); } } if (ModelState.IsValid) { _context.Add(contact); await _context.SaveChangesAsync(); //if(String.IsNullOrEmpty(returnURL)) //{ // return RedirectToAction(nameof(Index), new { CType = CType }); //} //else //{ // return Redirect(returnURL); //} return(Redirect(ViewData["returnURL"].ToString())); } ViewData["CompanyID"] = new SelectList(_context.Companies, "CompanyID", "Name", contact.CompanyID); return(View(contact)); } catch (RetryLimitExceededException) // Multiple tries { ModelState.AddModelError("", "Ineffectual save changes after multiple attempts. Try again. If the problem persists, please contact your system administrator."); } return(View(contact)); }
public async Task <IActionResult> Create([Bind("CompanyID,Name,Location,CreditCheck,DateChecked,BillingTermID,CurrencyID,Phone,Website,BillingAddress1,BillingAddress2,BillingProvinceID,BillingPostalCode,BillingCountryID,ShippingAddress1,ShippingAddress2,ShippingProvinceID,ShippingPostalCode,ShippingCountryID,Customer,CustomerTypeID,Vendor,VendorTypeID,Contractor,ContractorTypeID,Active,Notes")] Company company, string CType, string companyTypes) { //Get the URL with the last filter, sort and page parameters ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Companies"); //ViewData["returnURL"] = returnURL; try { UpdateCompanyTypes(companyTypes, company); if (ModelState.IsValid) { _context.Add(company); await _context.SaveChangesAsync(); //If no referrer then go back to index //if (String.IsNullOrEmpty(returnURL)) //{ // return RedirectToAction(nameof(Index), new { CType = CType }); //} //else //{ // return Redirect(returnURL); //} //return RedirectToAction("Details", new { company.CompanyID }); return(Redirect(ViewData["returnURL"].ToString())); } } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator."); } catch (Exception) { ModelState.AddModelError("", "Unable to create new record."); } return(View(company)); }
public async Task <IActionResult> Create( [Bind("FirstName,LastName,JobPositionID,EmploymentTypeID,EmployeeAddress1,EmployeeAddress2,EmployeeProvinceID,EmployeePostalCode,EmployeeCountryID,CellPhone,WorkPhone,Email,DOB,Wage,Expense,DateJoined,KeyFob,EmergencyContactName,EmergencyContactPhone,Active,Notes,UserId")] Employee employee, string userPassword, string userRepeatPassword, bool isUser) { //Get the URL with the last filter, sort and page parameters ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "Employees"); if (ModelState.IsValid) { try { if (isUser) { employee.UserId = await HandleIdentityCreation(employee.Email, userPassword, userRepeatPassword); } if (!(isUser && string.IsNullOrEmpty(employee.UserId))) { _context.Add(employee); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(Redirect(ViewData["returnURL"].ToString())); } } catch (Exception e) { _context.HandleDatabaseException(e, ModelState); } } ViewData["EmployeeCountryID"] = GetCountriesSelectList(employee.EmployeeCountryID); ViewData["EmployeeProvinceID"] = GetProvincesSelectList(employee.EmployeeProvinceID); ViewData["EmploymentTypeID"] = GetEmploymentTypesSelectList(employee.EmploymentTypeID); ViewData["JobPositionID"] = GetPositionsSelectList(employee.JobPositionID); return(View(employee)); }