Example #1
0
 protected void atiAddRemFav_Click(object sender, ImageClickEventArgs e)
 {
     if (this.UserId > 0)
     {   // Is this user Loged in ?
         aqufitEntities       entities = new aqufitEntities();
         User2StreamFavorites rFav     = entities.User2StreamFavorites.FirstOrDefault(f => f.UserKey == this.UserId && f.PortalKey == this.PortalId && f.UserStream.Id == this.RecipeId);
         if (rFav == null)
         {
             Affine.WebService.StreamService service = new WebService.StreamService();
             string ret = service.addStreamToFavorites(this.UserId, this.PortalId, this.RecipeId);
             if (!ret.Contains("success"))
             {
                 litStatus.Text = ret;
             }
             else
             {
                 litStatus.Text = "SUCCESS. Recipe has been added to your favorites.";
             }
         }
         else
         {
             entities.DeleteObject(rFav);
             entities.SaveChanges();
             litStatus.Text = "Boom. Recipe has been removed from your favorites.";
         }
         RadAjaxManager1.ResponseScripts.Add("$('#atiFavContainer').fadeOut('slow');");
     }
     else
     {  // otherwise jump to a login
         RadAjaxManager1.ResponseScripts.Add("self.location.href= Aqufit.Page.LoginUrl + \"?ReturnUrl=\" + self.location.href;");
     }
 }
Example #2
0
 public string addStreamToFavorites(long uid, long pid, long sid)
 {
     try
     {
         aqufitEntities entities = new aqufitEntities();
         UserSettings settings = entities.UserSettings.FirstOrDefault(us => us.UserKey == uid && us.PortalKey == pid);
         UserStream stream = entities.UserStreamSet.FirstOrDefault(s => s.Id == sid);
         User2StreamFavorites u2s = new User2StreamFavorites()
         {
             UserStream = stream,
             UserKey = uid,
             PortalKey = pid,
         };
         entities.AddToUser2StreamFavorites(u2s);
         entities.SaveChanges();
         return "{ 'status':'success' }";
     }
     catch (Exception ex)
     {
         return ex.Message;
     }
 }
Example #3
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                this.IsFavorite = true;
                base.Page_Load(sender, e);
                this.RecipeId = 0;
                if (Request["r"] != null || HttpContext.Current.Items["r"] != null)
                {
                    if (Request["r"] != null)
                    {
                        this.RecipeId = Convert.ToInt64(Request["r"]);
                    }
                    else if (HttpContext.Current.Items["r"] != null)
                    {
                        this.RecipeId = Convert.ToInt64(HttpContext.Current.Items["r"]);
                    }
                }
                if (!Page.IsPostBack && !Page.IsCallback)
                {
                    atiSearchBar.Visible = Settings["ShowSearchBar"] == null ? true : Convert.ToBoolean(Settings["ShowSearchBar"]);
                    ServiceReference service = new ServiceReference("~/DesktopModules/ATI_Base/resources/services/StreamService.asmx");
                    service.InlineScript = true;
                    ScriptManager.GetCurrent(Page).Services.Add(service);
                    if (Request["r"] != null || HttpContext.Current.Items["r"] != null)
                    {
                        atiRecipePanel.Visible   = true;
                        atiRecipe.ShowLogin      = this.UserId <= 0;
                        atiSearchResults.Visible = false;
                        atiRecipe.RecipeId       = Convert.ToString(this.RecipeId);
                        aqufitEntities       entities = new aqufitEntities();
                        User2StreamFavorites rFav     = entities.User2StreamFavorites.FirstOrDefault(f => f.UserKey == this.UserId && f.PortalKey == this.PortalId && f.UserStream.Id == this.RecipeId);
                        this.IsFavorite       = (rFav != null);
                        atiAddRemFav.ImageUrl = this.IsFavorite ? ResolveUrl("~/DesktopModules/ATI_Base/resources/images/remFromFav.png"):ResolveUrl("~/DesktopModules/ATI_Base/resources/images/addToFav.png");
                        imgCorner.Src         = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/corner.png");
                    }
                    else
                    {
                        atiSearchResults.Visible    = true;
                        atiRecipePanel.Visible      = false;
                        atiStreamScript.EditUrl     = ResolveUrl("~/AddRecipe.aspx");
                        atiStreamScript.DefaultTake = Settings["DefaultTake"] != null?Convert.ToInt32(Settings["DefaultTake"]) : 10;

                        // pick out a featured chef
                        aqufitEntities            entities = new aqufitEntities();
                        IQueryable <UserSettings> possible = entities.UserStreamSet.OfType <Recipe>().OrderByDescending(r => r.Date).Select(r => r.UserSetting).Distinct();
                        // radomize 20
                        int    max  = possible.Count() < 20 ? possible.Count() : 20;
                        Random rand = new Random();
                        IQueryable <UserSettings> featureQuery = possible.OrderByDescending(u => u.Id).Skip(rand.Next(max)).Take(1);
                        // Hydrate users metrics
                        featureQuery.Select(m => m.Metrics).ToArray();
                        featureQuery.Select(s => s.UserStreams.OrderByDescending(r => r.Date)).First();
                        UserSettings featured = featureQuery.First();
                        atiFeaturedProfile.Settings = featured;
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }