Exemplo n.º 1
0
        /// <summary>
        /// This function gets the users points on a particular action
        /// </summary>
        /// <returns></returns>
        public JsonResult GetPointsByAction(int id)
        {
            GigyaResponseData response = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error", statusReason = "0 entries" };
            int points = 0;
            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                {
                    response.errorMessage = "Invalid request";
                    return this.Json(response, JsonRequestBehavior.AllowGet);
                }

            if (!Enum.IsDefined(typeof(AnniversaryPromo), id))
            {
                response.errorMessage = "Value not defined in enumerator.";
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }

            if (!User.Identity.IsAuthenticated)
                response.errorMessage = "Unauthorized user";
            else
            {
                try
                {
                    points = GigyaMethods.GetPointsLogByAction(new Guid(User.Identity.Name), (AnniversaryPromo)id);
                    response.errorCode = 0;
                    response.statusReason = points > 1 || points == 0 ? String.Format("{0} entries", points) : String.Format("{0} entry", points);
                }
                catch (Exception) { response.errorMessage = "Invalid action"; }
            }
            return this.Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This function will add a point depending on the action done.
        /// </summary>
        /// <param name="id">Please base the ids on the Enum Anniversary Promo</param>
        /// <param name="contentId">Id of the episode, show, celebrity</param>
        /// <param name="description">Can be the show name, celebrity name, episode name (show - date)</param>
        /// <returns></returns>
        public JsonResult NotifyAction(FormCollection fc)
        {
            int naId = 0;
            GigyaResponseData response = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error" };
            if (String.IsNullOrEmpty(fc["naId"]) || String.IsNullOrEmpty(fc["naDescription"]))
            {
                response.errorMessage = "Missing parameter";
                return this.Json(null, JsonRequestBehavior.AllowGet);
            }

            naId = Convert.ToInt32(fc["naId"]);
            string naDescription = fc["naDescription"];

            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                {
                    response.errorMessage = "Invalid request";
                    return this.Json(null, JsonRequestBehavior.AllowGet);
                }

            if (!User.Identity.IsAuthenticated)
                response.errorMessage = "Unauthorized user";
            else
            {
                if (!ContextHelper.IsUserPartOfPromo(GlobalConfig.TFCtvFirstYearAnniversaryPromoId, User.Identity.IsAuthenticated ? new Guid(User.Identity.Name) : Guid.Empty))
                    response.errorMessage = "User not in Promo";
                else
                {
                    try
                    {
                        string action = String.Empty;
                        action = ((AnniversaryPromo)naId).ToString();
                        if (!String.IsNullOrEmpty(action))
                        {
                            GigyaActionSingleAttribute actionAttribute = new GigyaActionSingleAttribute();
                            {
                                actionAttribute.description = new List<string> { naDescription };
                            }
                            response = GigyaMethods.NotifyAction(new Guid(User.Identity.Name), action, actionAttribute);
                        }
                    }
                    catch (Exception) { response.errorMessage = "Invalid action"; }
                }
            }
            return this.Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This function gets all the actions log of a user
        /// </summary>
        /// <returns></returns>
        public JsonResult GetVariants(int id)
        {
            GigyaResponseData sourceResponse = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error" };
            GigyaResponseData response = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error" };
            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                {
                    response.errorMessage = "Invalid request";
                    return this.Json(null, JsonRequestBehavior.AllowGet);
                }
            if (!User.Identity.IsAuthenticated)
            {
                response.errorMessage = "Unauthorized user";
                return this.Json(null, JsonRequestBehavior.AllowGet);
            }

            if (!Enum.IsDefined(typeof(AnniversaryPromo), id))
            {
                response.errorMessage = "Value not defined in enumerator.";
                return this.Json(null, JsonRequestBehavior.AllowGet);
            }

            try
            {
                sourceResponse = GigyaMethods.GetVariantIDsbyUser(new Guid(User.Identity.Name), (AnniversaryPromo)id);
                response = GigyaMethods.GetVariantsbyVariantIDs(sourceResponse.actions.Select(s => s.VariantId));
                if (response != null)
                {
                    var finalResponse = from s in sourceResponse.actions
                                        join rs in response.variants on s.VariantId equals rs.variantID
                                        select new { actions = new GigyaCombinedActionsLog() { time = Convert.ToDateTime(s.time.Replace("Z", "")), timeStr = s.time.Replace("Z", ""), points = s.points, description = rs.actionAttributes.description.FirstOrDefault() } };
                    if (finalResponse != null)
                        if (finalResponse.Count() > 0)
                        {
                            var fr = finalResponse.OrderByDescending(f => f.actions.time);
                            return this.Json(fr, JsonRequestBehavior.AllowGet);
                        }
                }
            }
            catch (Exception e) { response.errorMessage = e.Message + "Invalid action"; }
            return this.Json(null, JsonRequestBehavior.AllowGet);
            //return this.Json(response == null ? null : response.variants.Select(r => r.actionAttributes.description), JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This function gets the top users, with the PromoChallengeID hardcoded in the Globalconfig. This can be used for future challenges, provided that the challenge id will be part of the parameters
        /// </summary>
        /// <returns></returns>
        public JsonResult GetTopUsers()
        {
            GigyaResponseData response = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error" };

            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                    response.errorMessage = "Invalid request";
            try
            {
                if (User.Identity.IsAuthenticated)
                    response = GigyaMethods.GetTopUsers(new Guid(User.Identity.Name), GlobalConfig.GigyaPromoChallengeID, 10, true);
                else
                    response = GigyaMethods.GetTopUsers(null, GlobalConfig.GigyaPromoChallengeID, 10, true);
            }
            catch (Exception) { response.errorMessage = "Invalid action"; }
            return this.Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 5
0
        /// <summary>
        /// This function gets all the actions log of a user
        /// </summary>
        /// <returns></returns>
        public JsonResult GetActionsLog(string id)
        {
            GigyaResponseData response = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error" };
            if (!Request.IsLocal && !GlobalConfig.isUAT)
                if (!Request.IsAjaxRequest())
                {
                    response.errorMessage = "Invalid request";
                    return this.Json(response, JsonRequestBehavior.AllowGet);
                }

            if (!User.Identity.IsAuthenticated)
                response.errorMessage = "Unauthorized user";
            else
            {
                try
                {
                    response = GigyaMethods.GetActionsLog(new Guid(String.IsNullOrEmpty(id) ? User.Identity.Name : id));
                    response.actions = response.actions.Where(x => String.Compare(x.challengeID, GlobalConfig.GigyaPromoChallengeID, true) == 0);
                }
                catch (Exception) { response.errorMessage = "Invalid action"; }
            }
            return this.Json(response, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 6
0
        /************* ANNIVERSARY PROMO *********************/
        /// <summary>
        /// This function returns the status of the user in the challenge.
        /// </summary>
        /// <returns></returns>
        public JsonResult GetChallengeStatus()
        {
            GigyaResponseData response = new GigyaResponseData() { errorCode = -1, errorMessage = "Unidentified error" };
            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                {
                    response.errorMessage = "Invalid request";
                    return this.Json(response, JsonRequestBehavior.AllowGet);
                }

            if (!User.Identity.IsAuthenticated)
                response.errorMessage = "Unauthorized user";
            else
            {
                try
                {
                    response = GigyaMethods.GetChallengeStatus(new Guid(User.Identity.Name));
                }
                catch (Exception) { response.errorMessage = "Invalid action"; }
            }
            return this.Json(response, JsonRequestBehavior.AllowGet);
        }