예제 #1
0
 public ActionResult Delete(int id)
 {
     try
     {
         ExchangGiftsBLL bll = new ExchangGiftsBLL();
         ExchangGifts u = bll.Find(id);
         bll.Remove(u);
         bll.SaveChanges();
         return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
     }
     catch
     {
         return Json(new { result = "error" }, JsonRequestBehavior.AllowGet);
     }
 }
예제 #2
0
 public ActionResult Create(ExchangGifts eGift)
 {
     try
     {
         HttpPostedFileBase file = Request.Files[0];
         if (file.ContentLength > 0)
         {
             string fileName = Path.GetFileName(file.FileName);
             file.SaveAs(Request.MapPath("/Filters/" + fileName));
             eGift.EG_Photo = fileName;
         }
         ExchangGiftsBLL bll = new ExchangGiftsBLL();
         eGift.S_ID = (Session["user"] as Users).S_ID;
         eGift.EG_ExchangNum = 0;
         bll.Add(eGift);
         bll.SaveChanges();
         return Content("ok");
     }
     catch
     {
         return Content("error");
     }
 }
예제 #3
0
 public ActionResult Edit(ExchangGifts eGift)
 {
     try
     {
         HttpPostedFileBase file = Request.Files[0];
         string[] cols;
         if (file.ContentLength > 0)
         {
             string fileName = Path.GetFileName(file.FileName);
             file.SaveAs(Request.MapPath("/Filters/" + fileName));
             eGift.EG_Photo = fileName;
             cols = new string[] { "EG_GiftName", "EG_Photo", "EG_Point", "EG_Number", "EG_Remark" };
         }
         else
         {
             cols = new string[] { "EG_GiftName", "EG_Point", "EG_Number", "EG_Remark" };
         }
         ExchangGiftsBLL bll = new ExchangGiftsBLL();
         bll.Edit(eGift, cols);
         bll.SaveChanges();
         return Content("ok");
     }
     catch
     {
         return Content("error");
     }
 }
예제 #4
0
 /// <summary>
 /// 礼品管理数据显示
 /// </summary>
 public ActionResult GiftInfo()
 {
     int pageSize = 0, pageIndex = 0;
     if (Request.Form["rows"] != null)
     {
         pageSize = Convert.ToInt32(Request.Form["rows"]);
     }
     if (Request.Form["page"] != null)
     {
         pageIndex = Convert.ToInt32(Request.Form["page"]);
     }
     Users u = Session["user"] as Users;
     int totalRow; var pagelist = new ExchangGiftsBLL().GetGifts(pageIndex, pageSize, (int)u.S_ID, out totalRow);
     return Json(new { total = totalRow, rows = pagelist }, JsonRequestBehavior.AllowGet);
 }
예제 #5
0
        public ActionResult ExchangeInfo()
        {
            string row = Request.Form["rows"];
            Users user = Session["user"] as Users;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            List<ExchangLogs> logList = serializer.Deserialize<List<ExchangLogs>>(row);
            List<ExchangGifts> giftList = serializer.Deserialize<List<ExchangGifts>>(row);
            try
            {
                ExchangLogs el = new ExchangLogs(); MemCardsBLL mcBll = new MemCardsBLL();
                ExchangLogsBLL elBll = new ExchangLogsBLL(); ExchangGiftsBLL exBll = new ExchangGiftsBLL();
                //事务处理,优点:确保数据统一完整;缺点:锁表
                using (TransactionScope ts = new TransactionScope())
                {
                    string idorm = Request.Form["idorm"];
                    MemCards mc = mcBll.SelectWhere(s => s.MC_CardID == idorm || s.MC_Mobile == idorm).FirstOrDefault();
                    double percent = (double)mc.CardLevels.CL_Percent;
                    double sum = 0; int total = (int)mc.MC_Point;
                    for (int i = 0; i < logList.Count; i++)
                    {
                        int point = Convert.ToInt32(giftList[i].EG_Point);
                        int number = Convert.ToInt32(logList[i].EL_Number);

                        //添加兑换记录表
                        el.S_ID = user.S_ID;
                        el.U_ID = user.U_ID;
                        el.MC_ID = mc.MC_ID;
                        el.MC_CardID = idorm;
                        el.MC_Name = mc.MC_Name;
                        el.EG_ID = giftList[i].EG_ID;
                        el.EG_GiftCode = logList[i].EG_GiftCode;
                        el.EG_GiftName = logList[i].EG_GiftName;
                        el.EL_Number = number;
                        el.EL_Point = point * number;
                        el.EL_CreateTime = DateTime.Now;
                        elBll.Add(el);
                        sum += (double)point * number * percent;
                        //更新礼品表
                        int eId = Convert.ToInt32(logList[i].EG_ID);
                        ExchangGifts eGift = exBll.SelectWhere(m => m.EG_ID == eId).FirstOrDefault();
                        eGift.EG_ExchangNum = number + eGift.EG_ExchangNum;
                    }
                    if (total >= Math.Ceiling(sum))
                    {
                        //更新会员表
                        int subpoint = (int)(mc.MC_Point - sum);
                        mc.MC_Point = subpoint;
                        //保存
                        mcBll.SaveChanges();
                        elBll.SaveChanges();
                        exBll.SaveChanges();
                        ts.Complete();
                        return Json(new { result = "ok", data = subpoint });
                    }
                    return Json(new { result = "no", data = "可兑换积分不足" + Math.Ceiling(sum) + "!" });
                }
            }
            catch
            {
                return Json(new { result = "error" });
            }
        }