Exemplo n.º 1
0
        public Dashboard CreateDashboardModel(ApplicationDbContext dbContext, ApplicationUser user, List <Promotion> couponPromotions, List <SocialSharing> socialPromotions)
        {
            Dashboard model = new Dashboard();

            if (couponPromotions != null && couponPromotions.Count() > 0)
            {
                Promotion activePromo_Coupon = (from x in couponPromotions
                                                where x.ActivePromotion == true
                                                select x).SingleOrDefault();
                if (activePromo_Coupon != null)
                {
                    SetActiveCouponDetails(dbContext, model, activePromo_Coupon);
                }

                List <Promotion> inactivePromos_Coupons = (from x in couponPromotions
                                                           where x.ActivePromotion != true
                                                           orderby x.CreationDate descending
                                                           select x).ToList();
                if (inactivePromos_Coupons != null)
                {
                    SetInactivePromoDetails(model, inactivePromos_Coupons);
                }
            }

            if (socialPromotions != null && socialPromotions.Count() > 0)
            {
                SocialSharing activePromo_Social = (from x in socialPromotions
                                                    where x.ActivePromotion == true
                                                    select x).SingleOrDefault();

                if (activePromo_Social != null)
                {
                    SetActiveSocialDetails(dbContext, model, activePromo_Social);
                }

                List <SocialSharing> inactivePromo_Social = (from x in socialPromotions
                                                             where x.ActivePromotion != true
                                                             select x).ToList();

                if (inactivePromo_Social != null)
                {
                    SetInactiveSocialDetails(model, inactivePromo_Social);
                }
            }


            model.ActivePromoScript   = user.UserPromoScript;
            model.CurrentSubscription = user.SubscriptionPlan;

            model.DashboardMessage = GetDashboardMessage(user);
            model.AccountWarning   = user.AccountSuspended || user.MonthlyPromotionLimitReached;

            return(model);
        }
Exemplo n.º 2
0
        public SocialSharing GetSocialModel(string promoId)
        {
            var social = new SocialSharing();

            if (!String.IsNullOrEmpty(promoId))
            {
                //Edit existing promotion
                social = (from x in _dbContext.SocialSharing where x.Id == promoId select x).FirstOrDefault();
            }
            else
            {
                social.SideOfScreen = "left";
            }

            return(social);
        }
Exemplo n.º 3
0
        public string GetAsync(string clientID)
        {
            try
            {
                using (_DbContext)
                {
                    ApplicationUser appUser = _DbContext.Users.Where(u => u.Id == clientID).FirstOrDefault();
                    if (appUser == null)
                    {
                        return("ERROR, Unknown user found within Oso script.");
                    }

                    if (!_SubscriptionService.SubscriptionWithinTrafficLimit(appUser, _DbContext) || appUser.AccountSuspended)
                    {
                        return("ERROR, issue found with OsOEasyPromo account, please check account status at OsoEasyPromo.com!");
                    }

                    //Coupon Promotion
                    Promotion couponPromotion = _DbContext.Promotion
                                                .Where(c => c.ApplicationUser.Id == clientID && c.ActivePromotion == true).FirstOrDefault();
                    if (couponPromotion != null && !_PromoService.ActivePromoExpired(couponPromotion.EndDate))
                    {
                        //Task the update to stats out?
                        //https://stackoverflow.com/questions/1018610/simplest-way-to-do-a-fire-and-forget-method-in-c
                        _PromoService.UpdatePromotionStats(couponPromotion, _DbContext);
                        return(_MainJS.GetMainCouponJS(clientID, couponPromotion));
                    }

                    //Social Sharing Promotion
                    SocialSharing socialPromotion = _DbContext.SocialSharing
                                                    .Where(c => c.ApplicationUser.Id == clientID && c.ActivePromotion == true).FirstOrDefault();
                    if (socialPromotion != null)
                    {
                        return(_MainJS.GetMainSocialHTML(socialPromotion));
                    }
                }

                return("WARNING, no active promotion found");
            }
            catch (Exception ex)
            {
                return("ERROR, unknown exception occurred getting promotion.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// String builder building HTML based off of MailHTML.html file
        /// </summary>
        public string GetMainSocialHTML(SocialSharing socialPromotion)
        {
            var html = new StringBuilder();

            var sideOfScreen = socialPromotion.SideOfScreen == "right" ? "right:0px;" : "left:0px;";

            html.Append("<div style='position:fixed;z-index:99 !important;" + sideOfScreen + "top: 45%;'" + "id='OsoEasyPromo.com_SocialPromotion'>");

            //Facebook
            if (socialPromotion.UseFacebook)
            {
                html.Append(GetSocialHTMLLine(_Facebook, socialPromotion.FacebookURL, socialPromotion.FacebookImageName));
            }

            //Twitter
            if (socialPromotion.UseTwitter)
            {
                html.Append(GetSocialHTMLLine(_Twitter, socialPromotion.TwitterURL, socialPromotion.TwitterImageName));
            }

            //Instagram
            if (socialPromotion.UseInstagram)
            {
                html.Append(GetSocialHTMLLine(_Instagram, socialPromotion.InstagramURL, socialPromotion.InstagramImageName));
            }

            //Linkedin
            if (socialPromotion.UseLinkedin)
            {
                html.Append(GetSocialHTMLLine(_Linkedin, socialPromotion.LinkedinURL, socialPromotion.LinkedinImageName));
            }

            //Pinterest
            if (socialPromotion.UsePinterest)
            {
                html.Append(GetSocialHTMLLine(_Pinterest, socialPromotion.PinterestURL, socialPromotion.PinterestImageName));
            }

            //Closing div tag
            html.Append("</div>");

            return(html.ToString());
        }
Exemplo n.º 5
0
        private string FindActivePromoId()
        {
            Promotion activePromo_Coupon = (from x in _dbContext.Promotion
                                            where x.ActivePromotion == true
                                            select x).SingleOrDefault();

            if (activePromo_Coupon != null)
            {
                return(activePromo_Coupon.Id);
            }

            SocialSharing activePromo_Social = (from x in _dbContext.SocialSharing
                                                where x.ActivePromotion == true
                                                select x).SingleOrDefault();

            if (activePromo_Social != null)
            {
                return(activePromo_Social.Id);
            }

            return("");
        }
Exemplo n.º 6
0
        public async Task <IActionResult> SaveSocial([FromBody] SocialSharing socialModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_dbContext)
                    {
                        if (!string.IsNullOrEmpty(socialModel.Id))
                        {
                            //Update existing promotion
                            _dbContext.Entry(_dbContext.SocialSharing.Find(socialModel.Id)).CurrentValues.SetValues(socialModel);
                        }
                        else
                        {
                            //Create new promotion
                            ApplicationUser appUser = await _common.GetCurrentUserAsync(HttpContext);

                            socialModel.ApplicationUser = appUser;
                            _dbContext.SocialSharing.Add(socialModel);
                        }

                        _dbContext.SaveChanges();
                    }
                }
                else
                {
                    //todo log that user is trying to bypass UI JS validation
                }
            }
            catch (Exception ex)
            {
                //todo handle exception
            }

            return(RedirectToAction("Dashboard", "Dashboard", new { area = "Dashboard" }));
        }
Exemplo n.º 7
0
        public JsonResult GetSocialData()
        {
            SocialSharing socialModel = GetSocialModel(HttpContext.Session.GetString("promoId"));

            return(Json(socialModel));
        }
Exemplo n.º 8
0
 private void SetActiveSocialDetails(ApplicationDbContext dbContext, Dashboard model, SocialSharing activePromo)
 {
     model.ActivePromoName = activePromo.Title;
     model.ActivePromoId   = activePromo.Id;
     model.ActivePromoType = Common.PromoType_Social;
 }