public int CreateProfile(string userId, CreateUserProfileJsonData model) // post { int _id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.UserProfile_InsertNewUser" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@firstName", model.firstName); paramCollection.AddWithValue("@lastName", model.lastName); paramCollection.AddWithValue("@profileContent", model.profileContent); paramCollection.AddWithValue("@tagLine", model.tagLine); paramCollection.AddWithValue("@userName", model.userName); paramCollection.AddWithValue("@userID", userId); SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection param) { int.TryParse(param["@Id"].Value.ToString(), out _id); } ); return(_id); }
public HttpResponseMessage PostRegistration(PostRegistrationRequest model) { IdentityUser newUserRegistration; if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } // When model is valid, CreateUser will post email and pw to database try { newUserRegistration = UserService.CreateUser(model.Email, model.Password, model.Username); CreateUserProfileJsonData NewUserProfile = new CreateUserProfileJsonData(); NewUserProfile.userName = model.Username; _userProfileService.CreateProfile(newUserRegistration.Id, NewUserProfile); } catch (IdentityResultException) // Display error code and message if user was not created { var ExceptionError = new ErrorResponse("Failed to register new user. (server side)"); return(Request.CreateResponse(HttpStatusCode.BadRequest, ExceptionError)); } // Insert new user's id into token table and generate new token string UserId = newUserRegistration.Id; Guid NewToken = _IUserTokenService.Insert(UserId); // Pass new user's email and token into emailservice for activation link try { string NewUserEmail = newUserRegistration.Email; UserEmailService.SendProfileEmail(NewToken, NewUserEmail); } catch (NotImplementedException) { var ExceptionError = new ErrorResponse("Failed to send activation email to new user"); return(Request.CreateResponse(HttpStatusCode.BadRequest, ExceptionError)); } SystemEventService.AddSystemEvent(new AddSystemEventModel { ActorUserId = UserId, ActorType = ActorType.User, EventType = SystemEventType.UserRegistration }); return(Request.CreateResponse(HttpStatusCode.OK, model)); }