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)); }
public HttpResponseMessage InsertVote(InsertVoteRequest model) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } //get current logged-in user model.VoterId = UserService.GetCurrentUserId(); //insert new row into dbo.PointScore, this creates a log for each vote casted VoteService.VoteInsert(model); //updates overall point score for each username _userProfileService.UpdateUserPointScore(model.UserName, model.NetVote); //updates the review's individual point score if (model.isMedia) { _RatingService.UpdateReviewPointScoreForMedia(model.ContentId, model.NetVote); } else { _RatingService.UpdateReviewPointScore(model.ContentId, model.NetVote); } SystemEventService.AddSystemEvent(new AddSystemEventModel { ActorUserId = model.VoterId, ActorType = ActorType.User, EventType = SystemEventType.UserVote, TargetId = model.ContentId, TargetType = TargetType.Review }); return(Request.CreateResponse(HttpStatusCode.OK, model)); }