public async Task <ActionResult> TechnicianRegister(TechnicianRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); await this.UserManager.AddToRoleAsync(user.Id, "Technician"); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { UserId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); TempData["techReg"] = model; return(RedirectToAction("TechnicianHome", "Home")); } AddErrors(result); } return(View(model)); }
public ActionResult TechnicianHome() { //if this is the users first time logging in as a technician, create teachnician and technicianProfile in database //get the technicians user ID var uid = repo.getUserId(); //var uid = User.Identity.GetUserId(); if (TempData["techReg"] != null) { //create instance of registerview model TechnicianRegisterViewModel trvm = new TechnicianRegisterViewModel(); //pass it to a temp variable trvm = (TechnicianRegisterViewModel)TempData["techReg"]; //creaet new technician and technician profile in database for suer //check to see if user has already been added var tech = repo.GetTechByUserId(uid); if (tech == null) { //create technician from viewmodel and add to database Technician model = new Technician() { CompanyName = trvm.CompanyName, CEOFirstName = trvm.CEOFirstName, CEOLastName = trvm.CEOLastName, JobType = trvm.JobType, AspNetUser_Id = uid, ApplicationUser_Id = uid }; repo.PostTech(model); } //get info to load onto page TechnicianProfile profile = new TechnicianProfile(); //get default picture from resources and convert to Image object called defaultPic MemoryStream msNew = new MemoryStream(); Image defaultPic = Resources.DefaultProfilePic; defaultPic.Save(msNew, System.Drawing.Imaging.ImageFormat.Jpeg); //find the technician currently logged in var newtech = repo.GetTechByUserId(uid); //add info to TechnicianProfile object to insert into database profile.techId = newtech.Id; profile.Description = "Add your company's description here"; profile.Rating = "0"; //convert Image object to byteArray profile.TechPicture = msNew.ToArray(); //close stream and save TechnicianProfile to database msNew.Close(); repo.PostTechProfile(profile); return(View(profile)); } else { //if is not the users first time logging in //get tech id of the current user logged in var techid = repo.GetTechIdByUserId(uid); //get the profile associated with the user var profile = repo.GetTechProfileByTechId(techid); return(View(profile)); } }