public void AddEmployer(int userId, RegisterModelEmployer model) { Employer employer = new Employer(); employer.UserId = userId; string imageFile = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/company-avatar.png")); byte[] buffer = File.ReadAllBytes(imageFile); employer.Picture = buffer; employer.Name = model.Name; employer.AdminEmail = model.AdminEmail; employer.EIK = model.EIK; employer.Email = model.Email; employer.Website = model.Website; employer.Address = model.Address; db.Employers.Add(employer); db.SaveChanges(); }
public ActionResult RegisterAsEmployer(RegisterModelEmployer model, string returnUrl) { if (ModelState.IsValid) { // Attempt to register the employer try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); int userId = int.Parse(Membership.GetUser(model.UserName).ProviderUserKey.ToString()); employerManager.AddEmployer(userId, model); var roles = (SimpleRoleProvider)Roles.Provider; roles.AddUsersToRoles(new[] { model.UserName }, new[] { "employer" }); if (returnUrl != null) { return Redirect(returnUrl); } return RedirectToAction("Profile", "Employer"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); Debug.WriteLine(e.Message); } } // If we got this far, something failed, redisplay form return View(model); }