public static List<Classes.Post> GetAllPostsViews()
 {
     var dc = new RNManagementContext();
     var posts = (from xx in dc.Posts
                  select new
                  {
                      xx.CurrentMonthlyViews,
                      xx.PostId,
                      xx.TotalViews,
                      xx.DisabledAutoPosting,
                      xx.DisablePaymentsForPost,
                      xx.Feed
                  }).ToList();
     List<Classes.Post> postss = new List<Classes.Post>();
     for (int i = 0; i < posts.Count; i++)
     {
         Classes.Post p = new Classes.Post();
         p.TotalMonthlyViews = posts[i].CurrentMonthlyViews;
         p.Id = posts[i].PostId;
         p.TotalViews = posts[i].TotalViews;
         p.DisabledAutoPosting = posts[i].DisabledAutoPosting;
         p.DisablePaymentsForPost = posts[i].DisablePaymentsForPost;
         if (posts[i].Feed != null)
         {
             p.FromFeed = true;
             p.FeedName = posts[i].Feed.NameOfSite;
             p.FeedUrl = posts[i].Feed.UrlOfSite;
         }
         postss.Add(p);
     }
     return postss;
 }
    public HttpResponseMessage Put([FromBody]Fund funds, string action)
    {
        try
        {
            //paypal Withdraw
            if (action == "withdrawPP")
            {

                var user = Membership.GetUser(Security.CurrentUser.Identity.Name);
                var localFunds = Fund.GetCurrentFundsInformation((Guid)user.ProviderUserKey);
                if (localFunds.ActiveInUserAccount >= funds.AmountToWithdraw)
                {


                    var mem = SiteCache.GetPublicMemberFull(RDN.Library.Classes.Account.User.GetMemberId());
                    PaymentGateway pg = new PaymentGateway();

                    var f = pg.StartInvoiceWizard()
                        .Initalize(RollinNewsConfig.MERCHANT_ID, "USD", PaymentProvider.Paypal, (PaymentMode)Enum.Parse(typeof(PaymentMode), ConfigurationManager.AppSettings["IsPayPalLive"].ToString()), ChargeTypeEnum.RollinNewsWriterPrePayout)
                        .SetInvoiceId(Guid.NewGuid())
                        .AddWriterPayout(new RDN.Library.Classes.Payment.Classes.Invoice.InvoiceWriterPayout
                        {
                            BasePrice = (decimal)funds.AmountToWithdraw,
                            Name = "Rollin News Payout " + DateTime.UtcNow.ToString("yyyy/MM/dd"),
                            PaymentRequestedDateTime = DateTime.UtcNow,
                            PayoutId = Guid.NewGuid(),
                            UserPaidId = (Guid)user.ProviderUserKey,
                            WhoPaysFees = WhoPaysProcessorFeesEnum.Receiver
                        })
                        .SetInvoiceContactData(new RDN.Library.Classes.Payment.Classes.Invoice.InvoiceContactInfo
                        {
                            Email = user.Email,
                            FirstName = mem.Firstname,
                            LastName = mem.LastName,
                            Phone = mem.PhoneNumber,
                        })
                                            .FinalizeInvoice();
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.NotAcceptable);
                }
            }
            //bitcoinWithdraw
            else if (action == "withdrawBc")
            {

            }
            else if (action == "submitEarnings")
            {
                Security.DemandUserHasRight(Rights.AllowedToSetMonthlyEarnings, false);
                PostRepository repo = new PostRepository();
                var posts = repo.GetPostsAndAuthors();
                List<RDN.Library.Classes.RN.Posts.Classes.Post> PostsTemp = new List<RDN.Library.Classes.RN.Posts.Classes.Post>();
                foreach (var p in posts)
                {
                    try
                    {
                        RDN.Library.Classes.RN.Posts.Classes.Post postTemp = new RDN.Library.Classes.RN.Posts.Classes.Post();
                        postTemp.Id = p.Id;
                        postTemp.AuthorUserId = p.AuthorUserId;
                        PostsTemp.Add(postTemp);
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, GetType());
                    }
                }
                MonthlyStatementsFactory statement = new MonthlyStatementsFactory();
                var state = statement.Initialize(Convert.ToDouble(funds.TotalEarningsForMonth), DateTime.UtcNow)
                    .GetPostsThatHadViews()
                    .SetAuthorsForPosts(PostsTemp)
                    .CalculateAndSavePayouts()
                    .SendEmailsToAuthorsAboutPayouts()
                    .ZeroOutMonthlyViews();


            }
            else
            {
                repository.Update(funds);
            }
            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (UnauthorizedAccessException)
        {
            return Request.CreateResponse(HttpStatusCode.Unauthorized);
        }
        catch (Exception exception)
        {
            ErrorDatabaseManager.AddException(exception, GetType());
            return Request.CreateResponse(HttpStatusCode.InternalServerError);
        }
    }