public ActionResult CompanyBankAccountOpening(int?Id) { try { var inDB = db.CurrentAccount.Where(hasValue => hasValue.PersonId == null && hasValue.CompanyId == null).FirstOrDefault(usr => usr.Id == Id).Equals(1); if (inDB == false) { CompanyRegistrationViewModel companyRegistration = new CompanyRegistrationViewModel(); try { CurrentAccount dbAcc = db.CurrentAccount.Where(model => model.Id == Id).FirstOrDefault(); companyRegistration.CompanyCommonData.AccountNumber = dbAcc.AccountNumber; companyRegistration.CompanyCommonData.EmailAddress = dbAcc.EmailAddress; return(View(companyRegistration)); } catch (Exception) { return(RedirectToAction("Error", "Home")); } } else { return(RedirectToAction("Error", "Home")); } } catch (Exception) { return(RedirectToAction("Error", "Home")); } }
public async Task <IdentityResult> SignUpCompanyAsync(CompanyRegistrationViewModel model, IUrlHelper Url, HttpContext httpContext) { Company company = new Company(); company.CompanyName = model.CompanyName; _context.Companies.Add(company); await _context.SaveChangesAsync(); var user = new EmployeeUser { UserName = model.Email, Email = model.Email, CompanyID = company.ID, PrimaryContact = true }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { company.Team.Employees.Add(user); await _context.SaveChangesAsync(); await _userManager.AddToRoleAsync(user, AppRole.SHIPPER); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: httpContext.Request.Scheme); await _emailSender.SendEmailAsync(model.Email, "Confirm your account", $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); } return(result); }
public IActionResult SignUp(string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; CompanyRegistrationViewModel model = new CompanyRegistrationViewModel(); return(View("SignUp", model)); }
public JsonResult CompanyRegister(CompanyRegistrationViewModel model) { var companyDto = model.MapToCompanyDto(); var response = _companyService.CreateCompanyWithUser(companyDto, EmsResousrce.DefaultCreatedBy); return(Json(response)); }
public async Task <IActionResult> SignUp(CompanyRegistrationViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var result = await userService.SignUpCompanyAsync(model, Url, HttpContext); if (result.Succeeded) { return(RedirectToLocal(returnUrl)); } AddErrors(result); } return(View(model)); }
public static CompanyDto MapToCompanyDto(this CompanyRegistrationViewModel model) { var company = new CompanyDto() { Name = model.CompanyName, Founded = model.Yearfounded, Background = model.Background, Users = new List <UserDto> { new UserDto { FirstName = model.FirstName, LastName = model.LastName, EmailAddress = model.Email, UserAccount = new UserAccountDto { UserName = model.Username, Password = model.Password } } } }; return(company); }
public ActionResult CompanyBankAccountOpening(CompanyRegistrationViewModel model) { // Server side validations // Telephone number validation bool validTelephoneNumber = IsValidTelephoneNumber(model.CompanyCommonData.TelephoneNumber); if (!validTelephoneNumber) { ModelState.AddModelError("Formátum hiba", "A telefonaszám nem megfelelő formátumú!"); } //Validation of Company Tax Number bool validTaxNumber = IsValidTaxNumber(model.TaxNumber); if (!validTaxNumber) { ModelState.AddModelError("Formátum hiba", "Hibás formátumú az adószám!"); } //Validation of Company Registry Number bool validRegistryNumber = IsValidRegistryNumber(model.CompanyRegistryNumber); if (!validRegistryNumber) { ModelState.AddModelError("Formátum hiba", "Hibás formátumú a cégjegyzék szám!"); } try { if (ModelState.IsValid) { // Hashing the password. var salt = Crypto.GenerateSalt(); var savedPasswordHash = Crypto.SHA256(model.CompanyCommonData.Password + salt); //Adding obtained data to database Company newCompany = new Company(); newCompany.Name = model.CompanyCommonData.Name; newCompany.TaxNumber = model.TaxNumber; newCompany.ContactName = model.ContactName; newCompany.RegistryNumber = model.CompanyRegistryNumber; newCompany.TelephoneNumber = model.CompanyCommonData.TelephoneNumber; newCompany.Address = model.CompanyCommonData.Address; // Adding new Company to database db.Company.Add(newCompany); var currentAccount = db.CurrentAccount.FirstOrDefault(currAcc => currAcc.AccountNumber == model.CompanyCommonData.AccountNumber); currentAccount.AccountOpenedDate = DateTime.Now; currentAccount.Password = savedPasswordHash; currentAccount.Salt = salt; currentAccount.Company = newCompany; var tokenManagerEntry = db.TokenManager.FirstOrDefault(token => token.TokenKey == currentAccount.TokenManagerTokenKey); tokenManagerEntry.IsActive = false; tokenManagerEntry.AccountCreated = currentAccount.AccountOpenedDate; tokenManagerEntry.TokenExpiry = null; db.Entry(currentAccount).State = EntityState.Modified; db.Entry(tokenManagerEntry).State = EntityState.Modified; db.SaveChanges(); SessionState.Current.CurrentAccountId = currentAccount.Id; SessionState.Current.CurrentUserName = currentAccount.Company.Name; return(RedirectToAction("Index", "User")); } return(View(model)); } catch (Exception) { return(RedirectToAction("Error", "Home")); } }
public Task <IdentityResult> SignUpCompanyAsync(CompanyRegistrationViewModel model, IUrlHelper url, HttpContext httpContext) { CompaniesSignedUp = +1; return(Task.FromResult(IdentityResult.Success)); }