public SKUModel ConvertSkuBDToSkuModel(Sku sku) { var u = AccountAdminModelBuilder.BuildOneUser(WebSecurity.CurrentUserName); var skuModel = GetEmptySku(); if (sku != null) { skuModel.id = sku.id; skuModel.name = sku.name; skuModel.price = sku.price; if (u != null && u.Discount > 0) { skuModel.priceAct = sku.priceAct - ((sku.priceAct / 100) * u.Discount); } else { skuModel.priceAct = sku.priceAct; } skuModel.priceAct = sku.priceAct; skuModel.description = sku.description; if (sku.brand!=null) { skuModel.brandId = sku.brand.id; skuModel.brandName = sku.brand.name; } if (sku.smalPhoto!=null) { skuModel.smalPhotoId = sku.smalPhoto.id; skuModel.smalPhotoPath = string.Format("{0}/{1}",imagesPath.GetImagesPath(), sku.smalPhoto.path); } skuModel.listCategory = sku.listCategory; skuModel.listSpecification = sku.listSpecification; skuModel.listPhoto = sku.listPhoto.Select(im => new PhotoBig() { id = im.id, name = im.name, path = string.Format("{0}/{1}", imagesPath.GetImagesPath(), im.path),skuId = im.skuId}).ToList(); } return skuModel; }
public Sku GetSkuById(long id) { var result = new Sku(); try { dbService.Run(db => { result = db.GetRepository<Sku>().TryOne(id); }); } catch (Exception err) { logger.Error(err.Message); } return result; }
public bool AddSku(Sku sku) { bool result = false; try { dbService.Run(db => { db.GetRepository<Sku>().Add(sku); }); result = true; } catch (Exception err) { result = false; logger.Error(err.Message); } return result; }
public long AddOrUpdateSKU(Sku sku) { long result = 0; try { dbService.Run(db => { var SkuDB = db.GetRepository<Sku>().TryOne(sku.id); if (SkuDB == null) { result= db.GetRepository<Sku>().Add(sku).id; } else { SkuDB.name = sku.name; SkuDB.brand = sku.brand; SkuDB.description = sku.description; SkuDB.price = sku.price; SkuDB.priceAct = sku.priceAct; //SkuDB.smalPhoto = sku.smalPhoto; SkuDB.listCategory = sku.listCategory; SkuDB.listComment = sku.listComment; SkuDB.listPhoto = sku.listPhoto; SkuDB.listSpecification = sku.listSpecification; db.GetRepository<Sku>().Update(SkuDB); result = sku.id; } }); } catch (Exception err) { result = 0; logger.Error(err.Message); } return result; }