public ActionResult ViewRDNStore()
        {
            var cart = GetCartForRdnStore();
            var store = GetStoreForRdn();

            var displayStore = new DisplayStore();
            displayStore.ShoppingCart = cart;
            displayStore.ShopName = store.Name;
            //displayStore.StoreItems = store.StoreItems;
            displayStore.MerchantId = store.MerchantId;

            return View(displayStore);
        }
 public DisplayStoreModel(DisplayStore store)
 {
     this.AcceptPaymentsViaPaypal = store.AcceptPaymentsViaPaypal;
     this.AcceptPaymentsViaStripe = store.AcceptPaymentsViaStripe;
     this.AccountStatus = store.AccountStatus;
     this.AmountOnAccount = store.AmountOnAccount;
     this.AutoAcceptPayment = store.AutoAcceptPayment;
     this.AutoShipWhenPaymentIsReceived = store.AutoShipWhenPaymentIsReceived;
     this.Bank = store.Bank;
     this.BankAccount = store.BankAccount;
     this.BetaCode = store.BetaCode;
     this.Created = store.Created;
     this.Currency = store.Currency;
     this.CurrencyCost = store.CurrencyCost;
     this.Description = store.Description;
     this.InternalReference = store.InternalReference;
     this.InternalReferenceType = store.InternalReferenceType;
     this.Invoices = store.Invoices;
     this.IsPublished = store.IsPublished;
     this.IsRDNation = store.IsRDNation;
     this.Location = store.Location;
     this.MerchantId = store.MerchantId;
     this.NumberOfItemsForSale = store.NumberOfItemsForSale;
     this.OrderPayedNotificationEmail = store.OrderPayedNotificationEmail;
     this.OwnerName = store.OwnerName;
     this.PayedFeesToRDN = store.PayedFeesToRDN;
     this.PaypalEmail = store.PaypalEmail;
     this.PayPalEmailAddressForPayments = store.PayPalEmailAddressForPayments;
     this.PrivateManagerId = store.PrivateManagerId;
     this.RDNFixedFee = store.RDNFixedFee;
     this.RDNPercentageFee = store.RDNPercentageFee;
     this.ReturnUrl = store.ReturnUrl;
     this.ShippingNotificationEmail = store.ShippingNotificationEmail;
     this.ShopName = store.ShopName;
     this.ShoppingCart = store.ShoppingCart;
     this.StoreCategories = store.StoreCategories;
     this.StoreItems = store.StoreItems;
     this.StripeConnectKey = store.StripeConnectKey;
     this.StripeConnectToken = store.StripeConnectToken;
     this.StripePublishableKey = store.StripePublishableKey;
     this.StripeRefreshToken = store.StripeRefreshToken;
     this.StripeTokenType = store.StripeTokenType;
     this.StripeUserId = store.StripeUserId;
     this.TaxRate = store.TaxRate;
     this.UserId = store.UserId;
     this.WelcomeMessage = store.WelcomeMessage;
 }
        public ActionResult Shop(string id, string name)
        {
            DisplayStore item = new DisplayStore();
            try
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
                string category = nameValueCollection["category"];

                int cat = 0;
                if (!String.IsNullOrEmpty(category))
                {
                    cat = Convert.ToInt32(category);
                }
                StoreGateway sg = new StoreGateway();
                item = sg.GetPublicStore(new Guid(id), cat);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return View(item);
        }
        public ActionResult StoreHome(Guid? privId, Guid? storeId)
        {
            DisplayStore displayStore = null;
            try
            {
                if (storeId == null)
                {
                    var store = new DisplayStore();
                    //when creating a store, the store is created with the users 
                    //member id or the federation or league id.
                    if (privId == null || privId == new Guid())
                    {
                        privId = RDN.Library.Classes.Account.User.GetMemberId();
                        //check if they already have a store, if they do, we load it.
                        bool hasStore = MemberCache.HasPersonalStoreAlreadyForUser(privId.Value);
                        if (hasStore)
                            return Redirect(Url.Content("~/store/home/" + MemberCache.GetStoreManagerKeysForUrlUser(privId.Value)));
                    }
                    store.InternalReference = privId.Value;
                    NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.Url.Query);
                    string updated = nameValueCollection["u"];

                    if (!String.IsNullOrEmpty(updated) && updated == SiteMessagesEnum.wbc.ToString())
                    {
                        SiteMessage message = new SiteMessage();
                        message.MessageType = SiteMessageType.Error;
                        message.Message = "Wrong Beta Code, Please Try Again.";
                        this.AddMessage(message);
                    }
                    return View(store);
                }
                var sg = new StoreGateway();
                displayStore = sg.GetStoreForManager(storeId, privId, false);
                if (!displayStore.AcceptPaymentsViaStripe && !displayStore.AcceptPaymentsViaPaypal)
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Info;
                    message.Message = "Please Setup a Payment Provider in the Store Settings.";
                    this.AddMessage(message);
                }
                else if (!displayStore.IsPublished)
                {
                    SiteMessage message = new SiteMessage();
                    message.MessageType = SiteMessageType.Info;
                    message.Message = "Your Store Is Not Yet Published. Publish the Store in the Settings.";
                    this.AddMessage(message);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return View(displayStore);
        }
        public ActionResult CreateStore(DisplayStore store)
        {
            try
            {

                var sg = new StoreGateway();
                DisplayStore sto = sg.CreateNewStoreAndMerchantAccount(store.InternalReference);
                var id = RDN.Library.Classes.Account.User.GetMemberId();
                MemberCache.Clear(id);
                MemberCache.ClearApiCache(id);

                return Redirect(Url.Content("~/store/home/" + sto.PrivateManagerId.ToString().Replace("-", "") + "/" + sto.MerchantId.ToString().Replace("-", "")));

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        public static DisplayStore GetRandomPublishedStoreItems(int howMany, Guid merchantId = new Guid())
        {
            DisplayStore store = new DisplayStore();
            try
            {
                var cached = GetCache(HttpContext.Current.Cache);

                if (merchantId == new Guid())
                    store.StoreItems = cached.ShopItems.StoreItems.OrderBy(x => Guid.NewGuid()).Take(howMany).ToList();
                else
                    store.StoreItems = cached.ShopItems.StoreItems.Where(x => x.Store.MerchantId == merchantId).OrderBy(x => Guid.NewGuid()).Take(howMany).ToList();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;
        }
        public DisplayStore CreateNewStoreAndMerchantAccount(Guid internalId)
        {
            DisplayStore store = new DisplayStore();

            try
            {
                var dc = new ManagementContext();
                MerchantInternalReference internalReference = MerchantInternalReference.Member;
                string notificationEmail = String.Empty;
                string ownerName = String.Empty;
                var mem = dc.Members.Where(x => x.MemberId == internalId).FirstOrDefault();
                if (mem != null)
                {
                    internalReference = MerchantInternalReference.Member;
                    if (mem.ContactCard != null && mem.ContactCard.Emails.FirstOrDefault() != null)
                        notificationEmail = mem.ContactCard.Emails.FirstOrDefault().EmailAddress;
                    ownerName = mem.DerbyName;
                }
                var league = dc.Leagues.Where(x => x.LeagueId == internalId).FirstOrDefault();
                if (league != null)
                {
                    internalReference = MerchantInternalReference.League;
                    if (league.ContactCard != null && league.ContactCard.Emails.FirstOrDefault() != null)
                        notificationEmail = league.ContactCard.Emails.FirstOrDefault().EmailAddress;
                    ownerName = league.Name;
                }
                var federation = dc.Federations.Where(x => x.FederationId == internalId).FirstOrDefault();
                if (federation != null)
                {
                    internalReference = MerchantInternalReference.Federation;
                    if (federation.ContactCard != null && federation.ContactCard.Emails.FirstOrDefault() != null)
                        notificationEmail = federation.ContactCard.Emails.FirstOrDefault().EmailAddress;
                    ownerName = federation.Name;
                }

                Merchant merc = MerchantGateway.CreateMerchantAccount(internalId, internalReference, notificationEmail, ownerName);

                store.InternalReference = internalId;
                store.MerchantId = merc.MerchantId;
                store.PrivateManagerId = merc.PrivateManagerId;
                store.ShopName = merc.ShopName;
                store.IsPublished = false;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;

        }
        public DisplayStore GetStoreSettings(Guid merchantId, Guid privateId)
        {
            DisplayStore merc = new DisplayStore();
            try
            {
                var dc = new ManagementContext();
                var store = dc.Merchants.Where(x => x.MerchantId == merchantId && x.PrivateManagerId == privateId).FirstOrDefault();

                if (store != null)
                {
                    merc.AutoShipWhenPaymentIsReceived = store.AutoShipWhenPaymentIsReceived;
                    merc.OrderPayedNotificationEmail = store.OrderPayedNotificationEmail;
                    merc.ShopName = store.ShopName;
                    merc.TaxRate = store.TaxRate;
                    if (store.CurrencyRate != null)
                        merc.Currency = store.CurrencyRate.CurrencyAbbrName;
                    else
                        merc.Currency = "USD";
                    //merc.CurrencyRate = dc.ExchangeRates.Where(x => x.CurrencyAbbrName == store.Currency).FirstOrDefault();
                    merc.ShippingNotificationEmail = store.ShippingNotificationEmail;
                    merc.PayPalEmailAddressForPayments = store.PaypalEmail;
                    //need to make sure we have a paypal email.
                    if (String.IsNullOrEmpty(store.PaypalEmail))
                        merc.AcceptPaymentsViaPaypal = false;
                    else
                        merc.AcceptPaymentsViaPaypal = store.AcceptPaymentsViaPaypal;
                    if (merc.AcceptPaymentsViaStripe || (store.AcceptPaymentsViaPaypal && !String.IsNullOrEmpty(store.PaypalEmail)))
                        merc.IsPublished = store.IsPublished;
                    else
                        merc.IsPublished = false;

                    merc.Description = store.Description;
                    merc.WelcomeMessage = store.WelcomeMessage;
                    merc.InternalReference = store.InternalReference;
                    merc.MerchantId = merchantId;
                    merc.PrivateManagerId = privateId;
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return merc;
        }
        public bool UpdateStoreSettings(DisplayStore store)
        {
            try
            {
                var dc = new ManagementContext();
                var merc = dc.Merchants.Where(x => x.InternalReference == store.InternalReference && x.MerchantId == store.MerchantId && x.PrivateManagerId == store.PrivateManagerId).FirstOrDefault();

                if (merc != null)
                {
                    if (!String.IsNullOrEmpty(merc.OwnerName))
                        merc.OwnerName = merc.OwnerName;
                    else
                        merc.OwnerName = "Shop";
                    merc.InternalReference = merc.InternalReference;
                    merc.PrivateManagerId = merc.PrivateManagerId;
                    merc.MerchantAccountStatus = merc.MerchantAccountStatus;
                    merc.RDNFixedFee = merc.RDNFixedFee;
                    merc.RDNPercentageFee = merc.RDNPercentageFee;
                    merc.AmountOnAccount = merc.AmountOnAccount;
                    merc.PayedFeesToRDN = merc.PayedFeesToRDN;

                    merc.AutoShipWhenPaymentIsReceived = store.AutoShipWhenPaymentIsReceived;
                    merc.OrderPayedNotificationEmail = store.OrderPayedNotificationEmail;
                    merc.ShopName = store.ShopName;
                    merc.TaxRate = store.TaxRate;
                    merc.CurrencyRate = dc.ExchangeRates.Where(x => x.CurrencyAbbrName == store.Currency).FirstOrDefault();
                    merc.ShippingNotificationEmail = store.ShippingNotificationEmail;
                    merc.PaypalEmail = store.PayPalEmailAddressForPayments;
                    //need to make sure we have a paypal email.
                    if (String.IsNullOrEmpty(store.PayPalEmailAddressForPayments))
                        merc.AcceptPaymentsViaPaypal = false;
                    else
                        merc.AcceptPaymentsViaPaypal = store.AcceptPaymentsViaPaypal;
                    if (merc.AcceptPaymentsViaStripe || (store.AcceptPaymentsViaPaypal && !String.IsNullOrEmpty(store.PayPalEmailAddressForPayments)))
                        merc.IsPublished = store.IsPublished;
                    else
                        merc.IsPublished = false;

                    merc.Description = store.Description;
                    merc.WelcomeMessage = store.WelcomeMessage;
                    int c = dc.SaveChanges();
                    return c > 0;
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }
        private static DisplayStore GetDisplayStore(Merchant merchant)
        {
            try
            {
                var store = new DisplayStore();
                store.ShopName = merchant.ShopName;
                store.MerchantId = merchant.MerchantId;
                store.InternalReference = merchant.InternalReference;
                store.PrivateManagerId = merchant.PrivateManagerId;
                store.AccountStatus = (MerchantAccountStatus)merchant.MerchantAccountStatus;
                store.AmountOnAccount = merchant.AmountOnAccount;
                store.AutoAcceptPayment = merchant.AutoAcceptPayment;
                store.AutoShipWhenPaymentIsReceived = merchant.AutoShipWhenPaymentIsReceived;
                store.Bank = merchant.Bank;
                store.BankAccount = merchant.BankAccount;
                if (merchant.CurrencyRate == null)
                {
                    store.Currency = "USD";
                    store.CurrencyCost = 1;
                }
                else
                {
                    store.Currency = merchant.CurrencyRate.CurrencyAbbrName;
                    store.CurrencyCost = merchant.CurrencyRate.CurrencyExchangePerUSD;
                }
                store.IsRDNation = merchant.IsRDNation;
                store.OrderPayedNotificationEmail = merchant.OrderPayedNotificationEmail;
                store.PayedFeesToRDN = merchant.PayedFeesToRDN;
                store.RDNFixedFee = merchant.RDNFixedFee;
                store.RDNPercentageFee = merchant.RDNPercentageFee;
                store.ShippingNotificationEmail = merchant.ShippingNotificationEmail;
                store.TaxRate = merchant.TaxRate;
                store.IsPublished = merchant.IsPublished;
                store.AcceptPaymentsViaPaypal = merchant.AcceptPaymentsViaPaypal;
                store.PayPalEmailAddressForPayments = merchant.PaypalEmail;
                store.AcceptPaymentsViaStripe = merchant.AcceptPaymentsViaStripe;
                store.StripeConnectKey = merchant.StripeConnectKey;
                store.StripeConnectToken = merchant.StripeConnectToken;
                store.Description = merchant.Description;
                store.WelcomeMessage = merchant.WelcomeMessage;
                if (merchant.Locations.FirstOrDefault() != null)
                    store.Location = Location.LocationFactory.DisplayLocation(merchant.Locations.FirstOrDefault());

                foreach (var storeItem in merchant.Items)
                {
                    var item = DisplayStoreItem(storeItem);
                    if (item != null)
                        store.StoreItems.Add(item);
                }
                foreach (var voice in merchant.Invoices.Where(x => x.Items.Count > 0).OrderByDescending(x => x.Created))
                {
                    DisplayInvoice v = DisplayInvoice(voice);
                    store.Invoices.Add(v);
                }
                return store;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }
        public DisplayStore GetPublicStore(Guid merchantId, int category)
        {
            var store = new DisplayStore();
            try
            {
                var mc = new ManagementContext();
                Merchant merchant = null;

                merchant = mc.Merchants.Include("Locations").Include("Items").Where(x => x.MerchantId == merchantId).FirstOrDefault();
                if (merchant == null)
                    return null;

                store.ShopName = merchant.ShopName;
                store.MerchantId = merchant.MerchantId;
                store.InternalReference = merchant.InternalReference;
                store.PrivateManagerId = merchant.PrivateManagerId;
                store.AccountStatus = (MerchantAccountStatus)merchant.MerchantAccountStatus;
                store.AmountOnAccount = merchant.AmountOnAccount;
                store.AutoAcceptPayment = merchant.AutoAcceptPayment;
                store.AutoShipWhenPaymentIsReceived = merchant.AutoShipWhenPaymentIsReceived;
                store.Bank = merchant.Bank;
                store.BankAccount = merchant.BankAccount;
                if (merchant.CurrencyRate == null)
                {
                    store.Currency = "USD";
                    store.CurrencyCost = 1;
                }
                else
                {
                    store.Currency = merchant.CurrencyRate.CurrencyAbbrName;
                    store.CurrencyCost = merchant.CurrencyRate.CurrencyExchangePerUSD;
                }
                store.IsRDNation = merchant.IsRDNation;
                store.OrderPayedNotificationEmail = merchant.OrderPayedNotificationEmail;
                store.PayedFeesToRDN = merchant.PayedFeesToRDN;
                store.RDNFixedFee = merchant.RDNFixedFee;
                store.RDNPercentageFee = merchant.RDNPercentageFee;
                store.ShippingNotificationEmail = merchant.ShippingNotificationEmail;
                store.TaxRate = merchant.TaxRate;
                store.IsPublished = merchant.IsPublished;
                store.Description = merchant.Description;
                store.WelcomeMessage = merchant.WelcomeMessage;
                store.StripePublishableKey = merchant.StripePublishableKey;
                store.AcceptPaymentsViaStripe = merchant.AcceptPaymentsViaStripe;
                store.AcceptPaymentsViaPaypal = merchant.AcceptPaymentsViaPaypal;
                if (merchant.Locations.FirstOrDefault() != null)
                    store.Location = Location.LocationFactory.DisplayLocation(merchant.Locations.FirstOrDefault());


                var items = merchant.Items.Where(x => x.IsPublished == true);
                try
                {
                    if (category > 0)
                        items = items.Where(x => x.Category != null).Where(x => x.Category.StoreItemCategoryId == category);
                }
                catch (Exception exception)
                {
                    ErrorDatabaseManager.AddException(exception, exception.GetType());
                }
                foreach (var storeItem in items)
                {
                    var item = DisplayStoreItem(storeItem);
                    if (item != null)
                    {
                        store.StoreItems.Add(item);

                    }
                }
                foreach (var storeItem in merchant.Items.GroupBy(x => x.Category))
                {
                    if (storeItem.Key != null)
                    {
                        var cat = store.StoreCategories.Where(x => x.StoreItemCategoryId == storeItem.Key.StoreItemCategoryId).FirstOrDefault();
                        if (cat == null && storeItem != null && storeItem.Key != null)
                        {
                            StoreCategory c = new StoreCategory();
                            c.Name = storeItem.Key.Name;
                            c.StoreItemCategoryId = storeItem.Key.StoreItemCategoryId;
                            store.StoreCategories.Add(c);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;
        }
        public DisplayStore GetAllPublishedStoreItems()
        {

            var store = new DisplayStore();
            try
            {
                var mc = new ManagementContext();
                var items = mc.StoreItems.Include("Photos").Include("Category").Include("Merchant").Where(x => x.IsPublished && x.Merchant.IsPublished).ToList();

                foreach (var storeItem in items)
                {
                    var item = DisplayStoreItem(storeItem);
                    if (item != null)
                        store.StoreItems.Add(item);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;
        }
        public List<DisplayStore> GetPublicShops(int page, int count)
        {
            var stores = new List<DisplayStore>();
            try
            {
                var mc = new ManagementContext();
                var shops = mc.Merchants.Where(x => x.IsPublished && x.Items.Select(y => y.IsPublished).Count() > 0).OrderBy(x => Guid.NewGuid()).Skip(page * count).Take(count);

                foreach (var shop in shops)
                {
                    var s = new DisplayStore();
                    s.MerchantId = shop.MerchantId;
                    s.ShopName = shop.ShopName;
                    s.OwnerName = shop.OwnerName;
                    s.Description = shop.Description;

                    foreach (var storeItem in shop.Items.Where(x => x.IsPublished))
                    {
                        var item = DisplayStoreItem(storeItem);
                        if (item != null)
                            s.StoreItems.Add(item);
                    }
                    stores.Add(s);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return stores;
        }
示例#14
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        try
        {
            bool shouldThrow404 = false;
            CommentView1.Visible = ShowCommentsForm;
            //disqus_box.Visible = ShowDisqusForm;

            var requestId = Request.QueryString["id"];
            Guid id;

            if ((!Utils.StringIsNullOrWhitespace(requestId)) && requestId.TryParse(out id))
            {
                Post post = Post.ApplicablePosts.Find(p => p.Id == id);
                if (post != null)
                {
                    if ((!HttpContext.Current.User.Identity.IsAuthenticated && !post.IsPublished) && !Security.IsAuthorizedTo(Rights.ViewUnpublishedPosts))
                    {


                        Response.Redirect(Utils.RelativeWebRoot, false);
                        Server.Transfer(Utils.RelativeWebRoot + "default.aspx");

                    }
                    else
                    {
                        //author Posts.
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.Author == post.Author && x.IsPublished).Take(3));
                        //lowests viewed posts of month
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished).OrderBy(x => x.TotalMonthsViews).Take(3));
                        //same tagged posts.
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished && x.Tags.Intersect(post.Tags).Any()).Take(5));
                        //same category
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished && x.Categories.Select(z => z.Title).Intersect(post.Categories.Select(y => y.Title)).Any()).Take(5));
                        //highest viewed posts of month
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished).OrderByDescending(x => x.TotalMonthsViews).Take(3));
                        //highest viewed posts of year
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished).OrderByDescending(x => x.TotalViews).Take(2));
                        //lowest viewed posts of year
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished).OrderBy(x => x.TotalViews).Take(5));
                        //all other posts.
                        RecommendedPosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished).OrderBy(x => Guid.NewGuid()).Take(100));
                        //order the posts.
                        RecommendedPosts = RecommendedPosts.DistinctBy(x => x.Id).OrderByDescending(x => x.DateCreated).ToList();

                        YouMayLikePosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished && x.Tags.Intersect(post.Tags).Any()).Take(10));
                        YouMayLikePosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished && x.Categories.Select(z => z.Title).Intersect(post.Categories.Select(y => y.Title)).Any()).Take(10));

                        if (YouMayLikePosts.Where(x => x.Id == post.Id).FirstOrDefault() != null)
                            YouMayLikePosts.Remove(YouMayLikePosts.Where(x => x.Id == post.Id).FirstOrDefault());

                        if (YouMayLikePosts.Count < 8)
                            YouMayLikePosts.AddRange(Post.ApplicablePosts.FindAll(x => x.IsPublished).OrderBy(x => Guid.NewGuid()).Take(8 - YouMayLikePosts.Count));

                        if (YouMayLikePosts.Count > 8)
                            YouMayLikePosts = YouMayLikePosts.Take(8).ToList();

                        StoreItem = SiteCache.GetRandomPublishedStoreItems(2);

                        Member = RDN.Library.Cache.SiteCache.GetPublicMemberFull(post.Author);
                        if (Member != null)
                        {
                            post.AuthorDerbyName = Member.DerbyName;
                            post.AuthorDerbyId = Member.MemberId;
                        }
                        this.Post = post;
                      

                        // SEO redirct, discussion #446011
                        int idx = Request.RawUrl.IndexOf("?");
                        var rawUrl = idx > 0 ? Request.RawUrl.Substring(0, idx) : Request.RawUrl;
                        if (rawUrl != post.RelativeLink.ToString())
                        {
                            Response.Clear();
                            Response.StatusCode = 301;
                            Response.AppendHeader("location", post.RelativeLink.ToString());
                            Response.End();
                        }

                        var settings = BlogSettings.Instance;
                        string encodedPostTitle = Server.HtmlEncode(Post.Title);
                        string path = Utils.ApplicationRelativeWebRoot + "themes/" + BlogSettings.Instance.GetThemeWithAdjustments(null) + "/PostView.ascx";

                        PostViewBase postView = (PostViewBase)LoadControl(path);
                        postView.Post = Post;
                        postView.ID = Post.Id.ToString().Replace("-", string.Empty);
                        postView.Location = ServingLocation.SinglePost;
                        pwPost.Controls.Add(postView);

                        if (!Network.IsSearchBot(HttpContext.Current.Request.UserAgent) && (HttpContext.Current.User.Identity.Name != post.Author) && post.IsVisibleToPublic && !IsPostBack)
                            PostManager.AddViewToPost(id);

                        CommentView1.Post = Post;

                        Page.Title = encodedPostTitle;
                        AddMetaKeywords();
                        AddMetaDescription();
                        //base.AddMetaTag("author", Server.HtmlEncode(Post.AuthorProfile == null ? Post.Author : Post.AuthorProfile.FullName));

                        //List<Post> visiblePosts = Post.Posts.FindAll(delegate(Post p) { return p.IsVisible; });
                        //if (visiblePosts.Count > 0)
                        //{
                        //    AddGenericLink("last", visiblePosts[0].Title, visiblePosts[0].RelativeLink);
                        //    AddGenericLink("first", visiblePosts[visiblePosts.Count - 1].Title, visiblePosts[visiblePosts.Count - 1].RelativeLink);
                        //}

                        //InitNavigationLinks();

                        phRDF.Visible = false;

                        base.AddGenericLink("application/rss+xml", "alternate", encodedPostTitle + " (RSS)", postView.CommentFeed + "?format=ATOM");
                        base.AddGenericLink("application/rss+xml", "alternate", encodedPostTitle + " (ATOM)", postView.CommentFeed + "?format=ATOM");

                        if (BlogSettings.Instance.EnablePingBackReceive)
                        {
                            Response.AppendHeader("x-pingback", "http://" + Request.Url.Authority + Utils.RelativeWebRoot + "pingback.axd");
                        }


                        HtmlGenericControl newControl = new HtmlGenericControl("meta");
                        newControl.Attributes["property"] = "og:title";
                        newControl.Attributes["content"] = post.Title;
                        Page.Header.Controls.Add(newControl);

                        HtmlGenericControl newControl2 = new HtmlGenericControl("meta");
                        newControl2.Attributes["property"] = "og:type";
                        newControl2.Attributes["content"] = "website";
                        Page.Header.Controls.Add(newControl2);

                        HtmlGenericControl newControl3 = new HtmlGenericControl("meta");
                        newControl3.Attributes["property"] = "og:image";
                        if (!String.IsNullOrEmpty(post.InitialImageUrl) && post.InitialImageUrl.Contains("http://"))
                            newControl3.Attributes["content"] = post.InitialImageUrl;
                        else
                            newControl3.Attributes["content"] = post.BaseHost.TrimEnd(new[] { '/' }) + post.InitialImageUrl;
                        Page.Header.Controls.Add(newControl3);

                        HtmlGenericControl newControl9 = new HtmlGenericControl("meta");
                        newControl9.Attributes["property"] = "og:image";
                        if (!String.IsNullOrEmpty(post.MainImageUrl) &&  post.MainImageUrl.Contains("http://"))
                            newControl9.Attributes["content"] = post.MainImageUrl;
                        else
                            newControl9.Attributes["content"] = post.BaseHost.TrimEnd(new[] { '/' }) + post.MainImageUrl;
                        Page.Header.Controls.Add(newControl9);

                        HtmlGenericControl newControl4 = new HtmlGenericControl("meta");
                        newControl4.Attributes["property"] = "og:url";
                        newControl4.Attributes["content"] = post.BaseHost.TrimEnd(new[] { '/' }) + post.RelativeOrAbsoluteLink;
                        Page.Header.Controls.Add(newControl4);

                        HtmlGenericControl newControl5 = new HtmlGenericControl("meta");
                        newControl5.Attributes["property"] = "og:site_name";
                        newControl5.Attributes["content"] = System.Configuration.ConfigurationManager.AppSettings["SiteName"];
                        Page.Header.Controls.Add(newControl5);

                        HtmlGenericControl newControl6 = new HtmlGenericControl("meta");
                        newControl6.Attributes["property"] = "fb:app_id";
                        newControl6.Attributes["content"] = System.Configuration.ConfigurationManager.AppSettings["FacebookAppId"];
                        Page.Header.Controls.Add(newControl6);


                    }

                }

            }

            else
            {
                shouldThrow404 = true;
            }

            if (shouldThrow404)
            {
                Response.Redirect(Utils.RelativeWebRoot + "error404.aspx", true);
            }
        }
        catch (ThreadAbortException)
        { }
        catch (Exception exception)
        {
            ErrorDatabaseManager.AddException(exception, exception.GetType());
        }
    }