Beispiel #1
0
 private void SetDivOrgIds(Coupon c)
 {
     if (regid.HasValue())
     {
         var a = regid.Split('.');
         switch (a[0])
         {
             case "org":
                 c.OrgId = a[1].ToInt();
                 break;
             case "div":
                 c.DivId = a[1].ToInt();
                 break;
         }
     }
 }
Beispiel #2
0
        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document(PageSize.LETTER);
            document.SetMargins(36f, 36f, 33f, 36f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            dc = w.DirectContent;

            var cols = new float[3 * 2 - 1];
            var twid = 0f;
            var t = new PdfPTable(cols.Length);
            for (var i = 0; i < cols.Length; i++)
                if (i % 2 == 1)
                    cols[i] = GAP * 72f;
                else
                    cols[i] = W * 72f;
            foreach (var wid in cols)
                twid += wid;

            t.TotalWidth = twid;
            t.SetWidths(cols);
            t.HorizontalAlignment = Element.ALIGN_CENTER;
            t.LockedWidth = true;
            t.DefaultCell.Border = PdfPCell.NO_BORDER;

            var rnd = new Random();
            var n = 0;
            while (n < 30)
            {
                int rndNext = rnd.Next(1000001, 9999999);
                var c = DbUtil.Db.Coupons.SingleOrDefault(cp => cp.Id == rndNext);
                if (c == null)
                {
                    c = new Coupon
                    {
                        Id = rndNext,
                        Created = DateTime.Now,
                        DivId = divid,
                        OrgId = orgid,
                    };
                    if (divid.HasValue)
                    {
                        DbUtil.Db.Coupons.InsertOnSubmit(c);
                        AddCell(t, c.Division.Name, rndNext);
                    }
                    else if (orgid.HasValue)
                    {
                        DbUtil.Db.Coupons.InsertOnSubmit(c);
                        AddCell(t, c.Organization.OrganizationName, rndNext);
                    }
                    else
                        AddCell(t, "A Test Name", rndNext);
                    n++;
                }
            }
            DbUtil.Db.SubmitChanges();
            document.Add(t);

            document.Close();
            Response.End();
        }
Beispiel #3
0
        public Coupon CreateCoupon()
        {
            string code = couponcode;
            if (!couponcode.HasValue())
            {
                do
                {
                    code = Util.RandomPassword(12);
                }
                while (IsExisting(code));
            }

            var c = new Coupon
            {
                Id = code,
                Created = DateTime.Now,
                Amount = amount,
                Name = name,
                UserId = Util.UserId,
            };
            SetDivOrgIds(c);
            DbUtil.Db.Coupons.InsertOnSubmit(c);
            DbUtil.Db.SubmitChanges();
            couponcode = Util.fmtcoupon(c.Id);

            return c;
        }
Beispiel #4
0
 private void detach_Coupons(Coupon entity)
 {
     this.SendPropertyChanging();
     entity.Division = null;
 }
Beispiel #5
0
 private void attach_Coupons(Coupon entity)
 {
     this.SendPropertyChanging();
     entity.Division = this;
 }
Beispiel #6
0
 private void attach_Coupons(Coupon entity)
 {
     this.SendPropertyChanging();
     entity.Organization = this;
 }
Beispiel #7
0
 private void detach_Coupons(Coupon entity)
 {
     this.SendPropertyChanging();
     entity.User = null;
 }
Beispiel #8
0
 private void attach_Coupons(Coupon entity)
 {
     this.SendPropertyChanging();
     entity.User = this;
 }