public async Task <IActionResult> Create(CreateEmployerViewModel model) { var user1 = _userManager.GetUserName(User); var user = new ApplicationUser() { Email = HttpContext.User.Identity.Name }; var user2 = new ApplicationUser() { UserName = user1, Email = user1 }; var u = user; var u2 = user2; var newEmployer = new Search_Work.Models.ArreaDatabase.Employer(); newEmployer.Id = Guid.NewGuid(); newEmployer.AccountUser = user; //Create Role // await _userManager.AddToRoleAsync(u, "Employer"); await _userManager.AddToRoleAsync(u2, "Employer"); // await _userManager.AddToRoleAsync(user, "Employer"); db.Employers.Add(newEmployer); await db.SaveChangesAsync(); return(RedirectToAction(nameof(PageIsExistCompany), new { empId = newEmployer.Id })); }
public async Task <IActionResult> Create([Bind("Id,Name,CityId,Requirements,Description,PhoneNumber,Email,Site,Facebook,Adress")] Company company, IFormFile Image, Guid?Id) { var emp = _context.Employers.Include(e => e.Company).ThenInclude(c => c.City) .Include(e => e.AccountUser).FirstOrDefault(e => e.Id == Id); //if (ModelState.IsValid) { company.Id = Guid.NewGuid(); var files = HttpContext.Request.Form.Files; if (Image != null) { string name = Image.FileName; string path = $"/files/{name}"; string serverPath = $"{_environment.WebRootPath}{path}"; FileStream fs = new FileStream(serverPath, FileMode.Create, FileAccess.Write); await Image.CopyToAsync(fs); fs.Close(); company.CompanyLogoUrl = path; } company.Employers.Add(emp); _context.Add(company); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Id", company.CityId); return(View(company)); }
public async Task <IActionResult> Create([Bind("Id,LastName,Name,Surname,Sex,Birthday,CityId,Country,Region,Street,ApartmentNumber,PhoneNumber,Email,Skype,Facebook,FamilyStatusId, ChildrenId")] Search_Work.Models.ArreaDatabase.Candidate candidate, IFormFile Image) { if (ModelState.IsValid) { candidate.Id = Guid.NewGuid(); if (Image != null) { string name = Image.FileName; string path = $"/files/{name}"; string serverPath = $"{_environment.WebRootPath}{path}"; FileStream fs = new FileStream(serverPath, FileMode.Create, FileAccess.Write); await Image.CopyToAsync(fs); fs.Close(); candidate.Avatar = path; } _context.Add(candidate); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Edit), new { id = candidate.Id })); } ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", candidate.CityId); ViewData["FamilyStatusId"] = new SelectList(_context.FamilyStatuses, "Id", "Name"); ViewData["ChildrenId"] = new SelectList(_context.Childrens, "Id", "Name"); return(View(candidate)); }
public async Task <IActionResult> Create([Bind("Id,Name")] City city) { if (ModelState.IsValid) { city.Id = Guid.NewGuid(); _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Create([Bind("Id,Name,CompanyLogoUrl,CityId,Requirements,Description,PhoneNumber,Email,Site,Facebook,Adress")] Company company) { if (ModelState.IsValid) { company.Id = Guid.NewGuid(); _context.Add(company); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Id", company.CityId); return(View(company)); }
public async Task <IActionResult> DeleteUser(string userId) { var user = await _userManager.FindByIdAsync(userId); if (user != null) { var cand = _context.Candidates.FirstOrDefault(i => i.AccountUser == user); var emp = _context.Employers.FirstOrDefault(i => i.AccountUser == user); if (cand != null) { _context.Candidates.Remove(cand); } else if (emp != null) { _context.Employers.Remove(emp); } var result = await _userManager.DeleteAsync(user); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(UserList))); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); // ----------------------------------------------------- //Create Role if (user.Email == "*****@*****.**") { await _userManager.AddToRoleAsync(user, "Admin"); return(RedirectToLocal(returnUrl)); } //else // await _userManager.AddToRoleAsync(user, "User"); if (model.IsCandidate) { await _userManager.AddToRoleAsync(user, "Candidate"); var newCandidate = new Candidate(); newCandidate.Id = Guid.NewGuid(); newCandidate.AccountUser = user; user.Candidate = newCandidate; _context.Candidates.Add(newCandidate); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(CandidatesController.Create), "Candidates")); } else { await _userManager.AddToRoleAsync(user, "Employer"); var newEmployer = new Employer(); newEmployer.Id = Guid.NewGuid(); newEmployer.AccountUser = user; user.Employer = newEmployer; _context.Employers.Add(newEmployer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(EmployersController.PageIsExistCompany), "Employers", new { Id = newEmployer.Id })); } // return RedirectToLocal(returnUrl); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }