Пример #1
0
 /// <summary>
 ///  产品展示
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Show(int id)
 {
     var _product = db.Products.Find(id);
     if(_product!=null)
     {
         vProduct product = new vProduct(_product);
         if (CurrentUser != null)
         {
             try
             {
                 BrowseRecord browserecord = new BrowseRecord();
                 string url = Request.Url.ToString();
                 browserecord = db.BrowseRecords.Where(br => br.URL == url && br.UserID == CurrentUser.ID).FirstOrDefault();
                 if (browserecord == null)
                 {
                     BrowseRecord addbrowserecord = new BrowseRecord();
                     addbrowserecord.UserID = CurrentUser.ID;
                     addbrowserecord.URL = url;
                     addbrowserecord.Title = "商品展示——" + product.ProductName;
                     addbrowserecord.Time = DateTime.Now;
                     db.BrowseRecords.Add(addbrowserecord);
                     db.SaveChanges();
                 }
                 else
                 {
                     db.BrowseRecords.Remove(browserecord);
                     BrowseRecord updatebrowserecord = new BrowseRecord();
                     updatebrowserecord.UserID = CurrentUser.ID;
                     updatebrowserecord.URL = url;
                     updatebrowserecord.Title = "商品展示——" + product.ProductName;
                     updatebrowserecord.Time = DateTime.Now;
                     db.BrowseRecords.Add(updatebrowserecord);
                     db.SaveChanges();
                 }
             }
             catch(Exception ex)
             {
                 log.Error(new LogContent("产品展示出错", HttpHelper.GetIPAddress()), ex);
                 return Redirect("/Shared/Info?msg=数据异常,请稍后重试");
             }
         }
         return View(product);
     }
     else
     {
         return Redirect("/Shared/Info?msg=数据异常,请稍后重试");
     }
 }
Пример #2
0
 public ActionResult ProductEdit(vProduct model, int id)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Product product = db.Products.Find(model.ID);
             product.ProductName = model.ProductName;
             product.Description = model.Description;
             product.Price = model.Price;
             product.Begin = model.Begin;
             product.End = model.End;
             product.BusinessID = model.BusinessID;
             product.Time = DateTime.Now;
             product.Integration = model.Integration;
             product.IsShow = model.IsShow;
             product.IsPass = false;
             db.SaveChanges();
             return Redirect("/Business/ProductManager/" + model.BusinessID);
         }
         catch (Exception ex)
         {
             log.Error(new LogContent("修改商品信息出错", HttpHelper.GetIPAddress()), ex);
             ModelState.AddModelError("", "产品信息有误,请审核后重新提交");
         }
     }
     else
     {
         ModelState.AddModelError("", "产品信息异常,请刷新页面,重新提交");
     }
     ViewBag.Product = db.Products.Find(model);
     ViewBag.Bussiness = db.Businesses.Find(model.BusinessID);
     return View();
 }