public int UpdateProduct(Models.Product product) { //TODO: exception handling Database.Product updateItem = new Database.Product() { Id = product.Id, CategoryId = product.CategoryId, CreatedBy = GetProductByID(product.Id).CreatedBy, CreateDate = GetProductByID(product.Id).CreateDate, LargeImageURL = product.LargeImageURL, LongDescription = product.LongDescription, Name = product.Name, Price = product.Price, Quantity = product.Quantity, ShortDescription = product.ShortDescription, SmallImageURL = product.SmallImageURL, UpdateDate = product.UpdateDate, UpdatedBy = product.UpdatedBy, }; using (var context = new PMSDatabaseEntities()) { context.Entry(updateItem).State = EntityState.Modified; context.SaveChanges(); } return(0); }
/// <summary> /// 转换到数据库使用的集合 /// </summary> /// <param name="values">编辑后的商品匹配数据列表</param> /// <param name="product">商品</param> /// <returns></returns> public static ISet <ProductMatchedData> ToDatabaseSet( this List <ProductMatchedDataForEdit> values, Database.Product product) { if (values == null) { return(new HashSet <ProductMatchedData>()); } long matchOrder = 0; return(new HashSet <ProductMatchedData>(values.Select(v => { // 部分特殊字段需要手动设置字段中 var data = new ProductMatchedData() { Product = product, Conditions = v.Conditions, Affects = v.Affects, Price = v.Affects.GetOrDefault <decimal?>("Price"), PriceCurrency = v.Affects.GetOrDefault <string>("PriceCurrency"), Weight = v.Affects.GetOrDefault <decimal?>("Weight"), Stock = v.Affects.GetOrDefault <long?>("Stock"), MatchOrder = matchOrder++, Remark = v.Affects.GetOrDefault <string>("Remark") }; return data; }))); }
private async Task ReplaceImage(Database.Product product, string imageName, byte[] byteArray) { var path = Path.Combine(Directory.GetCurrentDirectory(), "Data", "Images", "Products", $"{product.ImageLocation}"); try { File.Delete(path); } catch (Exception) { } try { var filename = $"product_{product.Id.ToString()}"; var extension = Path.GetExtension(imageName); var newPath = Path.Combine(Directory.GetCurrentDirectory(), "Data", "Images", "Products", $"{filename}{extension}"); await File.WriteAllBytesAsync(newPath, byteArray); product.ImageLocation = $"{filename}{extension}"; await _context.SaveChangesAsync(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new UserException("Dogodila se greska prilikom izmjene proizvoda. Provjerite podatke"); } }
/// <summary> /// 根据名称查找商品的属性 /// 属性名包含指定的名称时返回该属性 /// </summary> /// <param name="product">商品</param> /// <param name="name">属性名称,可以是翻译之前的</param> /// <returns></returns> public static IEnumerable <ProductToPropertyValue> FindPropertyValuesWhereNameContains( this Database.Product product, string name) { // 商品没有类目时结束查找 if (product.Category == null) { yield break; } // 获取属性名称的所有翻译 var translateManager = Application.Ioc.Resolve <TranslateManager>(); var languages = Application.Ioc.ResolveMany <ILanguage>(); var translatedNames = new HashSet <string>( languages.Select(l => translateManager.Translate(name, l.Name))); // 过滤包含指定名称的属性,并返回属性值 var productCategoryManager = Application.Ioc.Resolve <ProductCategoryManager>(); var propertyNames = product.Category.Properties.ToDictionary(p => p.Id, p => p.Name); foreach (var propertyValue in product.PropertyValues) { var propertyName = propertyValue.Property.Name ?? ""; if (translatedNames.Any(n => propertyName.Contains(n))) { yield return(propertyValue); } } }
/// <summary> /// 获取商品类型的特征 /// </summary> /// <param name="product">商品</param> /// <returns></returns> public static ProductTypeTrait GetTypeTrait(this Database.Product product) { var type = Application.Ioc.ResolveMany <IProductType>() .First(t => t.Type == product.Type).GetType(); return(ProductTypeTrait.For(type)); }
public ProductDialog(Database.Product product, Database.DataModelsDataContext DB) { InitializeComponent(); this.product = product; this.newModel = false; this.DB = DB; }
public ProductDialog(Database.DataModelsDataContext DB) { InitializeComponent(); this.product = new Database.Product(); this.newModel = true; deleteButton.Hide(); this.DB = DB; }
//event handler public void OnInvoiceAdded(Database.Product source, EventArgs e) { this.invoiceList.Add(source); invoiceText.Text = "Products Added To Invoice"; invoiceCount.Text = this.invoiceList.Count().ToString(); if (this.invoiceList.Count() > 0) { viewInvoiceBtn.Show(); } }
/// <summary> /// 获取显示的Html /// </summary> public string GetDisplayHtml(IDatabaseContext context, Database.Product product) { // 获取名称中带品牌的属性并返回该值 // 没有时返回null var value = product.FindPropertyValuesWhereNameContains(Name).FirstOrDefault(); if (value != null) { return(HttpUtils.HtmlEncode(new T(value.PropertyValueName))); } return(null); }
/// <summary> /// 根据属性参数查找商品的属性 /// 属性在属性参数中时返回该属性 /// </summary> /// <param name="product">商品</param> /// <param name="properties">商品属性参数</param> /// <returns></returns> public static IEnumerable <ProductToPropertyValue> FindPropertyValuesFromPropertyParameters( this Database.Product product, IList <ProductMatchParametersExtensions.PropertyParameter> properties) { foreach (var propertyValue in product.PropertyValues) { if (propertyValue.PropertyValue != null && properties.Any(p => p.PropertyId == propertyValue.Property.Id && p.PropertyValueId == propertyValue.PropertyValue.Id)) { yield return(propertyValue); } } }
/// <summary> /// 获取商品概述的Html /// 一般用于后台商品列表页等表格页面中 /// </summary> /// <param name="product">商品</param> /// <param name="truncateSize">商品名称的截取长度</param> /// <returns></returns> public static HtmlString GetSummaryHtml(this Database.Product product, int truncateSize = 25) { var albumManager = Application.Ioc.Resolve <ProductAlbumManager>(); var templateManager = Application.Ioc.Resolve <TemplateManager>(); var imageWebPath = albumManager.GetAlbumImageWebPath( product.Id, null, ProductAlbumImageType.Thumbnail); var html = templateManager.RenderTemplate("shopping.product/tmpl.product_summary.html", new { productId = product.Id, imageWebPath, name = product.Name, nameTruncated = product.Name.TruncateWithSuffix(truncateSize) }); return(new HtmlString(html)); }
/// <summary> /// 获取描述,没有时返回null /// </summary> public string GetDescription(Database.Product product, ProductMatchParameters parameters) { var properties = parameters.GetProperties(); if (properties == null || properties.Count <= 0) { return(null); } var parts = new List <string>(); foreach (var productToPropertyValue in product.FindPropertyValuesFromPropertyParameters(properties)) { parts.Add(string.Format("{0}: {1}", new T(productToPropertyValue.Property.Name), new T(productToPropertyValue.PropertyValueName))); } return(string.Join(" ", parts)); }
/// <summary> /// 获取显示的Html /// </summary> public string GetDisplayHtml(IDatabaseContext context, Database.Product product) { // 获取最小和最大重量 var weights = product.MatchedDatas.Where(d => d.Weight != null).Select(d => d.Weight.Value); var min = weights.Any() ? weights.Min() : 0; var max = weights.Any() ? weights.Max() : 0; // 无重量时不显示,最小和最大相同时显示{min}克,不相同时显示{min}~{max}克 if (min == max && min == 0) { return(null); } else if (min == max) { return(string.Format(new T("{0:F2} gram"), min)); } return(string.Format(new T("{0:F2}~{1:F2} gram"), min, max)); }
public int CreateProduct(Models.Product product) { try { if (product != null) { Database.Product entry = MapProductModelToProductContext(product); _dbContext.Products.Add(entry); _dbContext.SaveChanges(); return(1); } return(0); } catch (Exception ex) { logger.Error(ex); return(1); } }
/// <summary> /// 转换到数据库使用的集合 /// </summary> /// <param name="values">编辑后的商品对应的属性值列表</param> /// <param name="product">商品</param> /// <returns></returns> public static ISet <ProductToPropertyValue> ToDatabaseSet( this List <ProductToPropertyValueForEdit> values, Database.Product product) { if (values == null || product.Category == null) { return(new HashSet <ProductToPropertyValue>()); } return(new HashSet <ProductToPropertyValue>(values.Select(value => { var property = product.Category.Properties.First(p => p.Id == value.propertyId); var propertyValue = property.PropertyValues.FirstOrDefault(p => p.Id == value.propertyValueId); return new ProductToPropertyValue() { Product = product, Property = property, PropertyValue = propertyValue, PropertyValueName = value.name }; }))); }
public int DeleteProduct(int productID) { try { Database.Product product = GetProductByID(productID); if (product != null) { _dbContext.Products.Remove(product); } else { return(1); } _dbContext.SaveChanges(); return(0); } catch (Exception ex) { logger.Error(ex); return(1); } }
private async Task <Database.Product> Map(Database.Product product, ProductUpsertRequest request) { product.Condition = request.Condition != null ? request.Condition : product.Condition; product.Discount = request.Discount != product.Discount ? request.Discount : product.Discount; product.Description = request.Description != null ? request.Description : product.Description; if (request.Image != null) { if (request.Image.Length != 0) { var path = Path.Combine(Directory.GetCurrentDirectory(), "Data", "Images", "Products", $"{product.ImageLocation}"); var image = FindImage(path); if (image != null) { await ReplaceImage(product, request.ImageFileName, request.Image); } } } product.Price = (decimal)request.Price; product.ProductName = request.ProductName != null ? request.ProductName : product.ProductName; await _context.SaveChangesAsync(); return(product); }
public void editProductDialogShow(Database.Product p) { ProductDialogShow(new CustomControls.ProductDialog(p, DB)); }
private void CreateShopTable(IEnumerable <Database.Cart> carts, out double subTotal) { subTotal = new double(); ProductModel model = new ProductModel(); foreach (Database.Cart cart in carts) { //Create HTML elements and fill values with database data Database.Product product = model.GetProduct(cart.ProductID); ImageButton btnImage = new ImageButton { ImageUrl = string.Format("~/Images/Products/{0}", product.Image), PostBackUrl = string.Format("~/Pages/Product.aspx?id={0}", product.ID) }; LinkButton lnkDelete = new LinkButton { PostBackUrl = string.Format("~/Pages/ShoppingCart.aspx?productId={0}", cart.ID), Text = "Delete Item", ID = "del" + cart.ID, }; lnkDelete.Click += Delete_Item; //Fill amount list with numbers 1-20 int[] amount = Enumerable.Range(1, 20).ToArray(); DropDownList ddlAmount = new DropDownList { DataSource = amount, AppendDataBoundItems = true, AutoPostBack = true, ID = cart.ID.ToString() }; ddlAmount.DataBind(); ddlAmount.SelectedValue = cart.Amount.ToString(); ddlAmount.SelectedIndexChanged += ddlAmount_SelectedIndexChanged; //Create table to hold shopping cart details Table table = new Table { CssClass = "CartTable" }; TableRow row1 = new TableRow(); TableRow row2 = new TableRow(); TableCell cell1_1 = new TableCell { RowSpan = 2, Width = 50 }; TableCell cell1_2 = new TableCell { Text = string.Format("<h4>{0}</h4><br />{1}<br/>In Stock", product.Name, "Item No:" + product.ID), HorizontalAlign = HorizontalAlign.Left, Width = 350, }; TableCell cell1_3 = new TableCell { Text = "Unit Price<hr/>" }; TableCell cell1_4 = new TableCell { Text = "Quantity<hr/>" }; TableCell cell1_5 = new TableCell { Text = "Item Total<hr/>" }; TableCell cell1_6 = new TableCell(); TableCell cell2_1 = new TableCell(); TableCell cell2_2 = new TableCell { Text = "£ " + product.Price }; TableCell cell2_3 = new TableCell(); TableCell cell2_4 = new TableCell { Text = "£ " + Math.Round((cart.Amount * product.Price), 2) }; TableCell cell2_5 = new TableCell(); //Set custom controls cell1_1.Controls.Add(btnImage); cell1_6.Controls.Add(lnkDelete); cell2_3.Controls.Add(ddlAmount); //Add rows & cells to table row1.Cells.Add(cell1_1); row1.Cells.Add(cell1_2); row1.Cells.Add(cell1_3); row1.Cells.Add(cell1_4); row1.Cells.Add(cell1_5); row1.Cells.Add(cell1_6); row2.Cells.Add(cell2_1); row2.Cells.Add(cell2_2); row2.Cells.Add(cell2_3); row2.Cells.Add(cell2_4); row2.Cells.Add(cell2_5); table.Rows.Add(row1); table.Rows.Add(row2); pnlShoppingCart.Controls.Add(table); //Add total of current purchased item to subtotal subTotal += (cart.Amount * product.Price); } //Add selected objects to Session Session[User.Identity.GetUserId()] = carts; }
/// <summary> /// 获取显示的Html /// </summary> public string GetDisplayHtml(IDatabaseContext context, Database.Product product) { var seller = product.Seller; return(seller == null ? null : HttpUtils.HtmlEncode(seller.Username)); }
public void AddLabel(int serialNum, byte[] eui, int tester, DateTime date, int station, int site, ushort firmwareVersion, Database.Product product, int hwRevision, int bomRevision) { Labels.Add(new Label(serialNum, eui, tester, date, station, site, firmwareVersion, product, hwRevision, bomRevision)); }