Пример #1
0
        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;
        }
Пример #2
0
        public bool AddNewProduct(ProductDto productDto)
        {
            try
            {
                if (productDto == null) return false;
                Products product = new Products();
                product = Common.ConvertToProduct(productDto);
                ProductDAO.Execute(product, Entity.PRODUCT, ExecuteType.ADD);
                List<Products> prodList = ProductDAO.getNewestProduct(1).ToList();
                product = prodList.ElementAt(0);
                if (product.Code == null || product.Code == "")
                {
                    product.Code = product.Id.ToString();

                    ProductDAO.Execute(product, Entity.PRODUCT, ExecuteType.UPDATE);
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Пример #3
0
        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;
        }
Пример #4
0
        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;
        }
Пример #5
0
        public static Products ConvertToProduct(ProductDto prodDto)
        {
            Products product = new Products();
            product.Category = CategoryDAO.getCategoryById(prodDto.CategoryId);
            if (prodDto.Code == null || prodDto.Code == "")
                product.Code = null;
            else product.Code = prodDto.Code;
            product.CreatedDate = DateTime.Now;
            product.Description = prodDto.Description;
            product.Name = prodDto.Name;
            product.Price = prodDto.Price;
            product.Status = StatusDAO.getStatusById(CONST.STATUS.ACTIVE);

            ProductDetails productDetail = new ProductDetails();
            productDetail.ProductTypeId = StatusDAO.getStatusById(CONST.STATUS.P_IMAGE);
            productDetail.Status = StatusDAO.getStatusById(CONST.STATUS.ACTIVE);
            productDetail.CreatedDate = DateTime.Now;
            productDetail.Contents = prodDto.Image;
            productDetail.Product = product;

            product.ProductDetails.Add(productDetail);

            if (prodDto.Id != null)
            {
                product.Id = prodDto.Id;
            }
            return product;
        }