public ActionResult Edit(int id = 0) { CouponDetailDto coupon = new CouponDetailDto(); if (id > 0) { coupon = _couponService.Get(id).ToCouponDetailDto(); if (coupon != null) { } } return(View(coupon)); }
public ActionResult Edit(CouponDetailDto dto) { string errorMsg = "优惠券保存失败"; bool result = false; Coupon model = model = dto.ToCoupon(); model.MinFee = dto.MinFee * 100; model.RebateFee = dto.RebateFee * 100; try { if (dto.Id > 0) { model.UpdateTime = DateTime.Now; var propertyNames = dto.GetType().GetProperties().Select(p => p.Name).ToList(); result = _couponService.Update(model, p => propertyNames.Contains(p.Name)); } else { model.CreateTime = model.UpdateTime = DateTime.Now; model.Creator = "admin"; model.Status = 1; model.Sort = 0; model.IsDeleted = 0; long newId = _couponService.Insert(model); result = newId > 0; } } catch (Exception ex) { LogHelper.Error("Coupon/Edit [post] Error", ex); return(Json(new { res = false, msg = "网络连接错误" })); } if (result) { errorMsg = "优惠券保存成功"; } return(Json(new { res = result, msg = errorMsg })); }
public static Coupon ToCoupon(this CouponDetailDto dto) { return(dto != null?Mapper.Map <CouponDetailDto, Coupon>(dto) : null); }