public ActionResult UpdateCoupon(UniqueCoupon model) { var coupon = _couponService.GetById(model.Id); if (coupon != null) { coupon.Code = model.Code; coupon.Expiration = model.Expiration; coupon.MaxRedemptions = model.MaxRedemptions; coupon.UsedRedemptions = model.UsedRedemptions; coupon.Valid = model.Valid; _couponService.SaveCoupons(new List <UniqueCoupon> { coupon }); } return(new ContentResult { Content = model.PromotionId.ToString() }); }
public UniqueCoupon GetById(long id) { try { return(_cache.ReadThrough(GetCouponCacheKey(id), () => { UniqueCoupon coupon = null; var connectionString = _connectionHandler.Commerce.ConnectionString; using (var connection = new SqlConnection(connectionString)) { connection.Open(); var command = new SqlCommand { Connection = connection, CommandType = CommandType.StoredProcedure, CommandText = "UniqueCoupons_GetById" }; command.Parameters.Add(new SqlParameter("@Id", id)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { coupon = GetUniqueCoupon(reader); } } } return coupon; }, ReadStrategy.Wait)); } catch (Exception exn) { _logger.Error(exn.Message, exn); } return(null); }