public async Task <ActionResult> Register(RegisterServiceUser model) { bool userExists = await _context.ServiceUsers.AnyAsync(u => u.EmailAddress.Equals(model.Email.Trim(), StringComparison.InvariantCultureIgnoreCase)); if (userExists) { ModelState.AddModelError("Email", "Email already exists! Please use another email address."); } if (ModelState.IsValid) { var user = new ServiceUser() { UserName = model.UserName, EmailAddress = model.Email, ApiKey = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()), Password = accProc.GeneratePasswordHash(model.Password), IsApproved = false, FromDate = DateTime.Now }; user.ToDate = user.FromDate; _context.ServiceUsers.Add(user); _context.SaveChanges(); Session["userid"] = user.UserId.ToString(); Session["role"] = user.UserRole; Session["username"] = user.UserName; return(RedirectToAction("Details", new { id = user.UserId })); } return(View(model)); }
/// <summary> /// The ServiceUserSummary instance provided must contain only the UserName, a bool to notify if the user has lifetime license, license expiration date and email address. /// For lifetime license the ToDate is equal to the FromDate otherwise if no ExpirationDate is provided the license is issued for one year. /// </summary> public ServiceUser CreateNewUser(ServiceUser sUser) { try { //save to database using (var context = new RoboBrailleDataContext()) { context.ServiceUsers.Add(sUser); context.SaveChanges(); } return(sUser); } catch (Exception dbEx) { return(null); } }