Example #1
0
 public static decimal PromocodeAdd(PromocodeResponse pr)
 {
     if (pr.type >= 0)
     {
         Job j = Job.Session();
         j.Promocode = pr;
         Job.Update(j);
     }
     return(Job.AmountTotal());
 }
Example #2
0
        public PromocodeResponse PromocodeGet(string pc_name)
        {
            PromocodeResponse pr = new PromocodeResponse();
            PromoCode         p  = PromocodeGetObj(pc_name);
            int errorCode        = 0;

            if (string.IsNullOrWhiteSpace(p.Name))
            {
                errorCode = -1; // not available
            }
            if (p.UsageCurrent >= p.UsageLimit && p.UsageLimit >= 0)
            {
                errorCode = -2;//'promotion run out
            }
            if (errorCode == 0 && p.UserRestriction == 1 && ClientCompletedJobs() < 1)
            {
                if (p.DateEnd > 0)
                {
                    errorCode = -5;//' end date is exceeded
                }
                else
                {
                    errorCode = -3;//' only for existing customers
                }
            }
            if (errorCode == 0 && DateStart < 0)
            {
                errorCode = -4;//' start date is later
            }
            if (errorCode == 0 && DateEnd > 0)
            {
                errorCode = -5;//' end date is exceeded
            }
            pr.name = p.Name;
            if (errorCode == 0)
            {
                pr.type      = p.DiscountType;
                pr.value     = p.DiscountValue;
                pr.appliesTo = p.AppliesTo;
            }
            else
            {
                pr.type = errorCode;
            }

            return(pr);
        }