/// <summary> /// 如果新值不为空就覆盖旧的值 /// </summary> /// <param name="oldEntity"></param> /// <param name="newEntity"></param> /// <param name="newValue"></param> /// <param name="setValue"></param> private void OverrideIfNotNullNotWhiteSpace(Data.Product oldEntity, Data.Product newEntity, Func <Data.Product, String> newValue, Action <Data.Product, String> setValue) { if (!String.IsNullOrWhiteSpace(newValue(newEntity))) { setValue(oldEntity, newValue(newEntity)); } }
public void UpdateSearchIndex(Data.Product entity) { if (entity != null) { AliyunHelper.UpdateIndexDoc(new ProductAliyunIndexer(), new Dictionary <string, object>[] { new Dictionary <string, object> { { TableKey, entity.pid }, { name, entity.name }, { enname, entity.enName }, { description, entity.description }, { endescription, entity.enDescription }, { size, entity.size }, { ensize, entity.enSize }, { color, entity.color }, { encolor, entity.enColor }, { material, entity.material }, { enmaterial, entity.enMaterial }, { technique, entity.technique }, { entechnique, entity.enTechnique }, { minquantity, entity.minQuantity }, { deliveryday, entity.deliveryDay }, { keywords, entity.keywords }, { enkeywords, entity.enKeywords }, { unitprice, entity.unitPrice }, { imagepath, entity.imagePath }, { classno, entity.classNo }, { sortno, entity.sortNo }, { createuid, entity.createUid }, { created, entity.created }, { updated, entity.updated }, { enabled, entity.enabled }, { updater, entity.updater ?? 0 }, { viewcount, entity.viewCount ?? 0 }, } }); } }
static Data.Product GetProduct(Dictionary <string, string> dic) { Data.Product entity = new Data.Product(); entity.pid = TryGetDictValue(dic, TableKey).To <long>(); entity.name = TryGetDictValue(dic, name); entity.enName = TryGetDictValue(dic, enname); entity.description = TryGetDictValue(dic, description); entity.enDescription = TryGetDictValue(dic, endescription); entity.size = TryGetDictValue(dic, size); entity.enSize = TryGetDictValue(dic, ensize); entity.color = TryGetDictValue(dic, color); entity.enColor = TryGetDictValue(dic, encolor); entity.material = TryGetDictValue(dic, material); entity.enMaterial = TryGetDictValue(dic, enmaterial); entity.technique = TryGetDictValue(dic, technique); entity.enTechnique = TryGetDictValue(dic, entechnique); entity.minQuantity = TryGetDictValue(dic, minquantity).To <int>(); entity.deliveryDay = TryGetDictValue(dic, deliveryday).To <int>(); entity.keywords = TryGetDictValue(dic, keywords); entity.enKeywords = TryGetDictValue(dic, enkeywords); entity.unitPrice = TryGetDictValue(dic, unitprice).To <decimal>(); entity.imagePath = TryGetDictValue(dic, imagepath); entity.classNo = TryGetDictValue(dic, classno); entity.sortNo = TryGetDictValue(dic, sortno).To <int>(); entity.createUid = TryGetDictValue(dic, createuid).To <long>(); entity.created = FieldHelper.ToDateTime(TryGetDictValue(dic, created).To <int>()); entity.updated = FieldHelper.ToDateTime(TryGetDictValue(dic, updated).To <int>()); entity.enabled = TryGetDictValue(dic, enabled).To <bool>(); entity.updater = TryGetDictValue(dic, updater).To <long>(); entity.viewCount = TryGetDictValue(dic, viewcount).To <int>(); return(entity); }
void VeriryEntity(Data.Product newProduct) { ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.name, "", "产品名称不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.description, "", "产品详细说明不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.size, "", "产品尺寸不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.color, "", "产品颜色不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.material, "", "产品材质不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.technique, "", "产品工艺不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.keywords, "", "产品关键词不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.imagePath, "", "产品图片不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(newProduct.classNo, "", "产品分类编号不能为空"); ExceptionHelper.ThrowIfTrue(newProduct.minQuantity <= 0, "", "产品起订量必须大于0"); ExceptionHelper.ThrowIfTrue(newProduct.deliveryDay < 0, "", "产品发货日必须大于或等于0"); ExceptionHelper.ThrowIfTrue(newProduct.unitPrice <= 0, "", "产品单价必须大于0"); ExceptionHelper.ThrowIfTrue(newProduct.updater <= 0, "", "没有传入更新者的userID"); }
public ActionResult BatchEditList(string pids) { pids = pids ?? String.Empty; var pidsArr = pids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(d => d.To<long>()).ToArray(); Product[] items; if (pidsArr.Any()) { var products = _ProductManager.GetProductList(new ProductListArgs { Pids = pidsArr }); items = products.OrderByDescending(n => n.sortNo) .ThenByDescending(n => n.created) .Select(p => p).ToArray(); return Json(items, JsonRequestBehavior.AllowGet); } else { items = new Product[0]; } return Json(items); }
static Data.Product GetProduct(Dictionary<string, string> dic) { Data.Product entity = new Data.Product(); entity.pid = TryGetDictValue(dic, TableKey).To<long>(); entity.name = TryGetDictValue(dic, name); entity.enName = TryGetDictValue(dic, enname); entity.description = TryGetDictValue(dic, description); entity.enDescription = TryGetDictValue(dic, endescription); entity.size = TryGetDictValue(dic, size); entity.enSize = TryGetDictValue(dic, ensize); entity.color = TryGetDictValue(dic, color); entity.enColor = TryGetDictValue(dic, encolor); entity.material = TryGetDictValue(dic, material); entity.enMaterial = TryGetDictValue(dic, enmaterial); entity.technique = TryGetDictValue(dic, technique); entity.enTechnique = TryGetDictValue(dic, entechnique); entity.minQuantity = TryGetDictValue(dic, minquantity).To<int>(); entity.deliveryDay = TryGetDictValue(dic, deliveryday).To<int>(); entity.keywords = TryGetDictValue(dic, keywords); entity.enKeywords = TryGetDictValue(dic, enkeywords); entity.unitPrice = TryGetDictValue(dic, unitprice).To<decimal>(); entity.imagePath = TryGetDictValue(dic, imagepath); entity.classNo = TryGetDictValue(dic, classno); entity.sortNo = TryGetDictValue(dic, sortno).To<int>(); entity.createUid = TryGetDictValue(dic, createuid).To<long>(); entity.created = FieldHelper.ToDateTime(TryGetDictValue(dic, created).To<int>()); entity.updated = FieldHelper.ToDateTime(TryGetDictValue(dic, updated).To<int>()); entity.enabled = TryGetDictValue(dic, enabled).To<bool>(); entity.updater = TryGetDictValue(dic, updater).To<long>(); entity.viewCount = TryGetDictValue(dic, viewcount).To<int>(); return entity; }