public HttpResponseMessage ConfirmedEmail(Guid Token)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();
            UserTokens thisToken = TokensService.GetById(Token);
            string userId = thisToken.UserId;

            bool confirmed = _userService.ConfirmEmail(userId);

            if (!confirmed)
            {
                ErrorResponse er = new ErrorResponse("We could not Confirm your email at this time.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            bool deleted = TokensService.DeleteToken(Token);

            if (!deleted)
            {
                ErrorResponse er = new ErrorResponse("Your token wasn't deleted.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage UpdateBasic(QAndAUpdateRequest model)
        {
            SuccessResponse response = new SuccessResponse();
            _qAndAService.UpdateBasic(model);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage Enable(int id)
        {
            SuccessResponse response = new SuccessResponse();
            _qAndAService.Enable(id);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage DeleteFaq(int FaqId)
        {
            FaqsService.Delete(FaqId);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage DeleteSiteLink(int type, int ownerId, int ownerType)
        {
            _siteLinksService.Delete(type, ownerId, ownerType);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage Delete(int id)
        {
            _budgetBoxService.Delete(id);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage DeleteReferral(int referralId)
        {
            _referralService.Delete(referralId);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage DeletePageMetaTag(int pageMetaTagId)
        {
            _metaTagsService.Delete(pageMetaTagId);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage DeleteEvent(int eventId)
        {
            _eventsService.Delete(eventId);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage DeleteEvents(DeleteRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();

            _analyticsService.Delete(model);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage PaymentsUpdate(PaymentsUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();

            _paymentsService.Update(model);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage BlockUser(string Handle)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            _userService.BlockUser(Handle);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage Upsert(PlansProgressAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            string UserId = _userService.GetCurrentUserId();
            SuccessResponse response = new SuccessResponse();

            _plansProgressService.Upsert(model, UserId);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage SubscribeUser(MailChimpAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            try
            {
                EmailParameter result = _emailCampaignService.AddSubscriber(model.Email, model.FirstName, model.LastName);

                SuccessResponse response = new SuccessResponse();
                return Request.CreateResponse(HttpStatusCode.OK, response);
            }
            catch (MailChimpAPIException ex)
            {
                var error = ex.MailChimpAPIError;

                if(error.Code == "214")
                {
                    //e-mail already subscribed
                    ErrorResponse er = new ErrorResponse("214");
                    return Request.CreateResponse(HttpStatusCode.BadRequest, er);
                }
                else if (error.Code == "100")
                {
                    //invalid e-mail
                    ErrorResponse er = new ErrorResponse("100");
                    return Request.CreateResponse(HttpStatusCode.BadRequest, er);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e);

                ErrorResponse er = new ErrorResponse("General error occurred.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            ItemResponse<EmailParameter> emailParam = new ItemResponse<EmailParameter>();
            return Request.CreateResponse(emailParam);
        }
        public HttpResponseMessage UpdateVisibility(CommentsUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            string userId = _userService.GetCurrentUserId();

            SuccessResponse response = new SuccessResponse();

            _commentService.UpdateVisibility(model);

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage flagComment(int Id)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            string userId = _userService.GetCurrentUserId();

            //Check if admin code

            bool userIsAdmin = false;
            IdentityUser currentUser = _userService.GetCurrentUser();
            if (currentUser != null)
            {
                List<IdentityUserRole> roles = currentUser.Roles.ToList();
                foreach (var role in roles)
                {
                    if (role.RoleId == _superAdmin || role.RoleId == _admin)
                    {

                        userIsAdmin = true;
                        break;
                    }
                }

            }

            _userService.GetCurrentUser();

            bool UpdateValue = true; // Always True (or 1 on the Proc)
            int FlaggedId = Id; //This needs to be the same as the ID being passed

            SuccessResponse response = new SuccessResponse();

            _commentService.flagComment(Id, UpdateValue, FlaggedId, userIsAdmin);

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage DeleteByOwnerIdOwnerType(bool isDeleted, int ownerId, int ownerType)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            string userId = _userService.GetCurrentUserId();

            SuccessResponse response = new SuccessResponse();

            _commentService.Delete(isDeleted, ownerId, ownerType);

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage UpdateTemplate(CMSTemplateKeyUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();

            _cmsService.UpdateKey(model);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage UpdateUserInfo(UserUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            string userId = _userService.GetCurrentUserId();
            SuccessResponse response = new SuccessResponse();
            _userService.Update(model, userId);
            return Request.CreateResponse(response);
        }
 public HttpResponseMessage DeleteProfilePic(int Id)
 {
     _userService.DeleteProfilePic(Id);
     SuccessResponse response = new SuccessResponse();
     return Request.CreateResponse(HttpStatusCode.OK, response);
 }
        public HttpResponseMessage SetOnboardComplete()
        {
            string userId = _userService.GetCurrentUserId();

            _userService.SetOnboardComplete(userId);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage SendComfirmEmail(VerifyEmailRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            BaseResponse response = null;
            response = new SuccessResponse();

            HttpStatusCode code = HttpStatusCode.OK;

            ApplicationUser userVerification = _userService.GetUser(model.Email);

            if (userVerification == null)
            {
                response = new ErrorResponse("Cannot find a user with that email.");
                code = HttpStatusCode.BadRequest;
            }

            string userId = userVerification.Id;
            TokensRequest request = new TokensRequest();
            request.UserId = userId;
            request.Token = Guid.NewGuid();
            request.TokenTypeId = 2;

            ItemResponse<int> tokenAddResponse = new ItemResponse<int>();
            tokenAddResponse.Item = TokensService.Insert(request, userId);

            if (tokenAddResponse.Item <= 0)
            {
                response = new ErrorResponse("A new token was not inserted.");
                code = HttpStatusCode.BadRequest;
            }

            Guid uniqueId = request.Token;
            EmailRequest emailRequest = new EmailRequest();
            emailRequest.Email = model.Email;
            emailRequest.Subject = "Confirm Email";
            bool emailSent = MailService.ConfirmationEmail(emailRequest, uniqueId);

            if (!emailSent)
            {
                response = new ErrorResponse("The confirmation email failed to send.");
                code = HttpStatusCode.BadRequest;
            }

            return Request.CreateResponse(code, response);
        }
        public HttpResponseMessage UpdateBudget(BudgetBoxUpdateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();

            _budgetBoxService.Update(model);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage UpdateFaqs(FaqsUpdateRequest model, int Id)
        {
            if (!ModelState.IsValid)
            {

                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();

            FaqsService.UpdateFaqs(model, Id);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage forgotPassword(VerifyEmailRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();
            ApplicationUser userVerification = _userService.GetUser(model.Email);

            if (userVerification == null)
            {
                ErrorResponse er = new ErrorResponse("Cannot find a user with that email.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            string userId = userVerification.Id;
            TokensRequest request = new TokensRequest();
            request.UserId = userId;
            request.Token = Guid.NewGuid();
            request.TokenTypeId = 1;

            ItemResponse<int> tokenAddResponse = new ItemResponse<int>();
            tokenAddResponse.Item = TokensService.Insert(request, userId);

            if (tokenAddResponse.Item <= 0)
            {
                ErrorResponse er = new ErrorResponse("A new token was not inserted.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            Guid uniqueId = request.Token;
            EmailRequest emailRequest = new EmailRequest();
            emailRequest.Email = model.Email;
            emailRequest.Subject = "Password Reset";
            bool emailSent = MailService.resetPasswordEmail(emailRequest, uniqueId);

            if (!emailSent)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, "The reset password email failed to send.");
            }

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage UpdateUserBasicDemographics(BasicDemographicsRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            string userId = _userService.GetCurrentUserId();

            UserService.UpdateBasicDemographics(model, userId);

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage Logout()
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            _userService.Logout();

            SuccessResponse response = new SuccessResponse();

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
 public HttpResponseMessage NegateByID(int TagsID)
 {
     SuccessResponse response = new SuccessResponse();
     _tagsService.NegateByID(TagsID);
     return Request.CreateResponse(response);
 }
        public HttpResponseMessage UpdateCustom(QAndAAdvancedStyleUpdateRequest model)
        {
            SuccessResponse response = new SuccessResponse();
            _qAndAService.UpdateCustom(model);

            return Request.CreateResponse(response);
        }
        public HttpResponseMessage PasswordReset(NewPasswordRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();
            UserTokens thisToken = TokensService.GetById(model.ResetToken);
            string userId = thisToken.UserId;
            bool changed = _userService.ChangePassWord(userId, model.ConfirmPassword);

            if (!changed)
            {
                ErrorResponse er = new ErrorResponse("There was something wrong with your password format.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            bool deleted = TokensService.DeleteToken(model.ResetToken);

            if (!deleted)
            {
                ErrorResponse er = new ErrorResponse("Your token wasn't deleted.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            return Request.CreateResponse(response);
        }