public IActionResult EditPartnerInUser(List <PartnerUserViewModel> model, string userId) { List <int> partnerId = _hotelRepository.GetUsersPartners().Where(p => p.UserID == userId).Select(t => t.PartnerModelID).ToList(); if (ModelState.IsValid) { foreach (var item in model) { if (item.IsSelected == true && !(partnerId.Contains(Int32.Parse(item.PartnerId)))) { var userpartner = new UserPartnerModel { PartnerModelID = Int32.Parse(item.PartnerId), UserID = userId }; _hotelRepository.UploadMatchUserPartner(userpartner); } else if (item.IsSelected == false && (partnerId.Contains(Int32.Parse(item.PartnerId)))) { var id = _hotelRepository.GetUsersPartners().Where(p => p.PartnerModelID == Int32.Parse(item.PartnerId) && p.UserID == userId).Select(a => a.Id).FirstOrDefault(); _hotelRepository.RemoveMatchUserPartner(id); } else { continue; } } return(RedirectToAction("Edit", new { Id = userId })); } return(RedirectToAction("Edit", new { Id = userId })); }
public async Task <IActionResult> Register(UserViewModel model) { var userpartner = new UserPartnerModel(); if (ModelState.IsValid) { var user = new IdentityUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); //userpartner.PartnerModelID = model.PartnersId.FirstOrDefault(); //userpartner.UserID = user.Id; //_hotelRepository.UploadMatchUserPartner(userpartner); if (result.Succeeded) { var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme, "ankieta.grecos.pl"); await _emailService.SendAsync(model.Email, "Confirm email", $"<a href=\"{confirmationLink}\">Confirm Email</a>", true); if (_signInManager.IsSignedIn(User) && User.IsInRole("Admin")) { return(RedirectToAction("Index", "Account")); } ViewBag.ErrorTitle = "Registration successful"; return(View("Error")); //await _signInManager.SignInAsync(user, isPersistent: false); //return RedirectToAction("Index", "Home"); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } AddViewBag(); return(View()); }
//Zapisuję do bazy powiązanie między użytkowiniem a partnerem public void UploadMatchUserPartner(UserPartnerModel userPartner) { _context.Update(userPartner); _context.SaveChanges(); }