public static ProductOverviewDto convertOverview(Products products) { int id = products.Id; string name = products.Name; float price = 0; string image = ""; string code = products.Code; if (products.Price == null) { price = 0; } else { price = (float)products.Price; } IList <ProductDetails> IProdDetails = ProductDetailDAO.getAllProductDetailByTypeId(id, CONST.STATUS.P_IMAGE); if (IProdDetails != null) { List <ProductDetails> prodDetails = IProdDetails.ToList(); if (prodDetails.Count > 0) { image = prodDetails.ElementAt(0).Contents; } } ProductOverviewDto prodDto = new ProductOverviewDto(id, name, image, price, code); return(prodDto); }
public static ProductDto ConvertToProductDto(Products products) { //var prodDto = Mapper.Map<Products, ProductDto>(products); ProductDto productDto = new ProductDto(); productDto.Id = products.Id; float price = 0; string image = ""; if (products.Price == null) { price = 0; } else { price = (float)products.Price; } IList <ProductDetails> IProdDetails = ProductDetailDAO.getAllProductDetailByTypeId(products.Id, CONST.STATUS.P_IMAGE); if (IProdDetails != null) { List <ProductDetails> prodDetails = IProdDetails.ToList(); if (prodDetails.Count > 0) { image = prodDetails.ElementAt(0).Contents; } } productDto.Name = products.Name; productDto.Code = products.Code; productDto.Description = products.Description; productDto.Price = price; productDto.Image = image; Categories newCat = CategoryDAO.getCategoryById(products.Category.CategoryId); productDto.Category = new CategoryDto() { CategoryId = newCat.CategoryId, name = newCat.Name }; return(productDto); }
public static ProductsForManageDto ConvertToProductsForManageDto(Products products) { var productDto = new ProductsForManageDto(); productDto.Id = products.Id; float price; string image = ""; if (products.Price == null) { price = 0; } else { price = (float)products.Price; } IList <ProductDetails> IProdDetails = ProductDetailDAO.getAllProductDetailByTypeId(products.Id, CONST.STATUS.P_IMAGE); if (IProdDetails != null) { List <ProductDetails> prodDetails = IProdDetails.ToList(); if (prodDetails.Count > 0) { image = prodDetails.ElementAt(0).Contents; } } productDto.Name = products.Name; productDto.Code = products.Code; productDto.Description = products.Description; productDto.Price = price; productDto.Image = image; productDto.IsActive = products.Status.Id; productDto.CategoryId = products.Category.CategoryId; productDto.Quantity = products.Quantity; return(productDto); }