コード例 #1
0
        public ActionResult AddProductRequest(String name, String code, String category, String price,String image,String desc)
        {
            ProductHandler prodHandler = new ProductHandler();
            ProductDto product = new ProductDto();
            product.Name = name;

            product.Code = code;
            product.CategoryId = int.Parse(category);
            product.Price = float.Parse(price);
            product.Image = image;

            product.Description = System.Net.WebUtility.HtmlDecode(desc);
            prodHandler.AddNewProduct(product);

            if(Session[CONST.SESSION.USER] != null){
                UserDto userDto = (UserDto)Session[CONST.SESSION.USER];
                if (UserHandler.AdminLogin(userDto.Username, userDto.Password) == CONST.ROLE.ADMIN)
                {

                    return RedirectToAction("Index", "Admin");
                }
                else if (UserHandler.AdminLogin(userDto.Username, userDto.Password) == CONST.ROLE.MOD)
                {

                    return RedirectToAction("Index", "Mod");
                }
            }
            return RedirectToAction("Index", "Home");
        }
コード例 #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
ファイル: Common.cs プロジェクト: Musasthl/d-shopping-core
        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;
        }
コード例 #4
0
ファイル: Common.cs プロジェクト: Musasthl/d-shopping-core
        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;
        }