public IEnumerable <PromotionInstance> Forward(PromotionInstance pi, IEnumerable <Account> invites, string message)
        {
            if (pi == null)
            {
                throw new ArgumentException("promotion should not be null");
            }

            if (invites == null || invites.Count() == 0)
            {
                throw new ArgumentException("there should be one or more invites");
            }

            // TODO: what is the logic to decide what is the deal that can be forwarded
            var forwards = from i in invites
                           select new PromotionInstance(this.Account, i, pi.Promotion, pi.Deal, message);

            IEnumerable <string> brokenRules;
            var success = this.dataService.PromotionInstance.SaveOrUpdateAll(forwards, out brokenRules);

            if (success)
            {
                this.log.Info("Sucessfully saving {0} promotion forwards for {1}", forwards.Count(), pi.Promotion);
                ExecutePlugins(f => f.Forward(pi, invites, message));
                return(forwards);
            }
            else
            {
                this.log.Debug("Error: Unable to save invitations broken rules {0}", String.Join(",", brokenRules));
                return(null);
            }
        }
        public PromotionInstance Response(PromotionInstance pi, StatusType responseType, string message)
        {
            if (pi.Recipient.Id != this.Account.Id)
            {
                throw new ArgumentException(String.Format("this invitation is not for user {0}", this.Account));
            }

            pi.Status.StatusType = responseType;
            pi.Status.Message    = message;
            pi.CreateDateTime    = DateTime.UtcNow;

            IEnumerable <string> brokenRules;
            var success = this.dataService.PromotionInstance.SaveOrUpdate(pi, out brokenRules);

            if (success)
            {
                this.log.Info("[] - {0} Succesfully saved invitation {1}", Account, pi);
                // TODO: this should not be here, we should decouple facebook stuff
                ExecutePlugins(t => t.Response(pi));
                return(pi);
            }
            else
            {
                this.log.Debug("[] - {0} Unable to create activity {1}. Violated rules {2}", Account, pi, brokenRules.First());
                return(null);
            }
        }
Example #3
0
        public ActionResult Forward(Guid promotionid, string ids, string message)
        {
            this.AccountBase.SetupActionAccount();
            PromotionInstance pi = null;

            bool isForUser = this.AccountBase.PromotionInstanceActions.PromotionInstanceForUserPromotion(promotionid, out pi);

            this.AccountBase.PromotionInstanceActions.Forward(pi, null, message);

            return(View());
        }
 public PromotionInstance Decline(PromotionInstance pi, string message)
 {
     if (this.Account != pi.Recipient)
     {
         return(null);
     }
     else
     {
         return(Response(pi, StatusType.Decline, message));
     }
 }
 private Coupon GenerateCoupon(PromotionInstance pi)
 {
     if (pi.Deal != null)
     {
         var coupon = new Coupon();
         coupon.CouponCode = coupon.GenerateCode(8);
         coupon.Redeemed   = false;
         return(coupon);
     }
     return(null);
 }
Example #6
0
        //public static Permission GetPermissions(InvitationResponse ir, ConnectionType connection)
        //{
        //    var p = new Permission(ir);

        //    if (connection.HasFlag(ConnectionType.Owner)
        //        // connection.HasFlag(ConnectionType.ActivityOwner) -- why do we have activity owner deleting the response for?
        //        )
        //    {
        //        p.value |= PermissionEnum.Delete;
        //    }
        //    return p;
        //}

        public static Permission GetPermissions(PromotionInstance i, ConnectionType connection)
        {
            var p = new Permission(i);

            if (connection.HasFlag(ConnectionType.Owner)
                // connection.HasFlag(ConnectionType.ActivityOwner) -- why do we have activity owner deleting the response for?
                )
            {
                p.value |= PermissionEnum.Delete;
            }

            return(p);
        }
Example #7
0
        public static void PostToOwnWall(PromotionInstance a)
        {
            FacebookClient fc         = new FacebookClient(FacebookWebContext.Current.AccessToken);
            dynamic        parameters = PopulateParametersForEvent(a.Promotion.Event);

            parameters.actions = new
            {
                name = "View on Popr.ly",
                link = "http://popr.ly/Promotion/Invitation/?id=" + a.Id.ToString()
            };
            SetPrivacy(parameters, a.Promotion.Event.Privacy);
            dynamic result = fc.Post("me/feed", parameters);
        }
        public PromotionInstance Accept(PromotionInstance pi, string message)
        {
            if (this.Account != pi.Recipient)
            {
                return(null);
            }
            else
            {
                var c = GenerateCoupon(pi);
                pi.Coupons = pi.Coupons ?? new List <Coupon>();
                pi.Coupons.Add(c);

                return(Response(pi, StatusType.Accept, message));
            }
        }
        public bool PromotionInstanceForUserPromotion(Guid promotionInstanceId, out PromotionInstance pi)
        {
            pi = null;
            // see if we can find the instance
            var x = this.dataService.PromotionInstance.Find(promotionInstanceId);

            if (x != null)
            {
                pi = x;
                if (x.Recipient.FacebookLogon.FacebookId == this.Account.FacebookLogon.FacebookId)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #10
0
        public ActionResult View(Guid promotionid)
        {
            this.AccountBase.SetupActionAccount();
            PromotionInstance pi = null;

            bool isForUser = this.AccountBase.PromotionInstanceActions.PromotionInstanceForUserPromotion(promotionid, out pi);

            // the promotion id might not be for the user. In that case, we'll see if the user has other promotions for that event
            if (isForUser)
            {
                // show model and return
                PromotionViewModel pvm = new PromotionViewModel();
                pvm.Deal  = pi.Deal;
                pvm.Event = pi.Promotion.Event;
                var invited = from t in pi.ForwardedPromotionInstances select t.Recipient;
                pvm.Invited    = new AccountListJson(invited);
                pvm.InviteDate = pi.CreateDateTime;
                pvm.Promotion  = pi.Promotion;
                pvm.Sender     = pi.Sender;
                pvm.Status     = pi.Status.StatusType;
                pvm.Message    = pi.Message;
                return(View());
            }

            if (pi == null)
            {
                var otherInvites = this.AccountBase.PromotionInstanceActions.GetAvailableInvitationsForUser(pi.Promotion.Event.Id);
                if (otherInvites != null)
                {
                    //redirect to the page for the first invite
                    return(RedirectToAction("View", "PromotionController", new { id = otherInvites[0].Id }));
                }

                if (pi.Promotion.Event.Permission.CanView)
                {
                    // redirect to event view
                    return(RedirectToAction("Details", "EventController", new { id = pi.Promotion.Event.Id }));
                }
            }

            // show the error page
            return(RedirectToAction("Error", "Home"));
        }