Beispiel #1
0
        public IEnumerable <CouponInfo> GetCoupons(CouponModel model = null)
        {
            var roles = DbUtil.Db.CurrentUser.UserRoles.Select(uu => uu.Role.RoleName).ToArray();
            var q     = from c in DbUtil.Db.Coupons
                        let o = c.Organization
                                where o.LimitToRole == null || roles.Contains(o.LimitToRole)
                                where c.DivOrg == model.regidfilter || model.regidfilter == "0" || model.regidfilter == null
                                where c.UserId == model.useridfilter || model.useridfilter == 0
                                select c;

            switch (model.usedfilter)
            {
            case "Used":
                q = q.Where(c => c.Used != null && c.Canceled == null);
                break;

            case "UnUsed":
                q = q.Where(c => c.Used == null && c.Canceled == null);
                break;

            case "Canceled":
                q = q.Where(c => c.Canceled != null);
                break;
            }
            if (model.name.HasValue())
            {
                q = q.Where(c => c.Name.Contains(model.name) || c.Person.Name.Contains(model.name));
            }

            if (model.startdate.HasValue() && model.enddate.HasValue())
            {
                DateTime bd;
                DateTime ed;
                if (DateTime.TryParse(model.startdate, out bd) && DateTime.TryParse(model.enddate, out ed))
                {
                    q = q.Where(c => c.Created.Date >= bd && c.Created.Date <= ed);
                }
            }

            var q2 = from c in q
                     orderby c.Created descending
                     select new CouponInfo
            {
                Amount     = c.Amount,
                Canceled   = c.Canceled,
                Code       = c.Id,
                Created    = c.Created.FormatDateTm(),
                OrgDivName = c.OrgId != null ? c.Organization.OrganizationName : c.Division.Name,
                Used       = c.Used.FormatDateTm(),
                PeopleId   = c.PeopleId,
                Name       = c.Name,
                Person     = c.Person.Name,
                UserId     = c.UserId,
                UserName   = c.User.Name,
                RegAmt     = c.RegAmount
            };

            return(q2.Take(200));
        }
Beispiel #2
0
 public ActionResult Create(CouponModel m)
 {
     if (m.couponcode.HasValue())
         if (CouponModel.IsExisting(m.couponcode))
             return Content("code already exists");
     m.CreateCoupon();
     return View(m);
 }
Beispiel #3
0
 public ActionResult Cancel(string id)
 {
     var c = DbUtil.Db.Coupons.SingleOrDefault(cp => cp.Id == id);
     if (!c.Canceled.HasValue)
     {
         c.Canceled = DateTime.Now;
         DbUtil.Db.SubmitChanges();
     }
     var m = new CouponModel();
     return View("List", m);
 }
Beispiel #4
0
 public CouponExcelResult(CouponModel m)
 {
     this.m = m;
 }
Beispiel #5
0
 public ActionResult List(string submit, CouponModel m)
 {
     if (submit == "Excel")
         return new CouponExcelResult(m);
     return View(m);
 }
Beispiel #6
0
 public ActionResult List()
 {
     var m = new CouponModel();
     return View(m);
 }
Beispiel #7
0
 public ActionResult List(string submit, CouponModel m)
 {
     if (submit == "Excel")
         return m.CouponsAsDataTable().ToExcel("Coupons.xlsx");
     return View(m);
 }