public ResultModel AddSKU(int pid, int valueid, int isdefaultprice, decimal price) { using (brnshopEntities context = new brnshopEntities()) { try { var sku = context.bsp_productskus.SingleOrDefault(t => t.pid == pid && t.attrvalueid == valueid); if (sku != null) { return(ResultModel.Fail("该规格SKU已经存在")); } var attrvalue = context.bsp_attributevalues.SingleOrDefault(t => t.attrvalueid == valueid); bsp_productskus newsku = new bsp_productskus(); newsku.pid = pid; newsku.attrid = attrvalue.attrid; newsku.attrvalueid = valueid; newsku.inputattr = attrvalue.attrname; newsku.inputvalue = attrvalue.attrvalue; newsku.isdefaultprice = isdefaultprice; newsku.price = price; context.bsp_productskus.Add(newsku); context.SaveChanges(); ProductCache.InitProductList(); return(ResultModel.Success("", newsku.recordid)); } catch (Exception ex) { Logger._.Error(ex); return(ResultModel.Error(ex.ToString())); } } }
/// <summary> /// 更新sku信息 /// </summary> /// <param name="skuguid"></param> /// <param name="isdefaultprice"></param> /// <param name="price"></param> /// <param name="stock"></param> /// <returns></returns> public ResultModel UpdateSku(string skuguid, int isdefaultprice, decimal price, int stock) { price = isdefaultprice == 1 ? -1 : price; string sql = $@"UPDATE dbo.bsp_productskus SET isdefaultprice = {isdefaultprice},price = {price},stock = {stock} WHERE skuguid = '{skuguid}'"; var r = SqlManager.ExecuteNonQuery(AppConfig.ConnectionString, new SqlCommand(sql)); if (r) { ProductCache.InitProductList(); return(ResultModel.Success("修改成功")); } return(ResultModel.Fail("数据库操作失败,请联系管理员")); }
public static void InitAll() { ProductCache productCache = new ProductCache(); productCache.Init(); BoxCache boxCache = new BoxCache(); boxCache.Init(); BannerCache bannerCache = new BannerCache(); bannerCache.Init(); BusinessCache businessCache = new BusinessCache(); businessCache.InitBusinessCache(); }
public ResultModel DeleteSKU(int pid, int valueid) { using (brnshopEntities context = new brnshopEntities()) { try { var sku = context.bsp_productskus.SingleOrDefault(t => t.pid == pid && t.attrvalueid == valueid); if (sku == null) { return(ResultModel.Fail("该规格SKU已经删除")); } context.bsp_productskus.Remove(sku); context.SaveChanges(); ProductCache.InitProductList(); return(ResultModel.Success()); } catch (Exception ex) { Logger._.Error(ex); return(ResultModel.Error(ex.ToString())); } } }