Exemplo n.º 1
0
        public Response <string> AddProductAsync <T>(ProductModel model, T t)
        {
            string  imageName = UploadImageAsync(model.proImageStream);
            Product product   = _mapper.Map <Product>(model);

            product.DateCreated = DateTime.Now;
            product.ProStatus   = false;
            product.ProImage    = imageName;
            int proId = _repo.AddProduct(product);

            Type type = typeof(T);

            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                string[]         _specInfo = FileManager.StringSeparator(property.GetValue(t, null).ToString(), "//");
                ProSpecification spec      = new ProSpecification()
                {
                    ProId     = proId,
                    SpecId    = Int16.Parse(_specInfo[0]),
                    SpecValue = _specInfo[1]
                };
                _repo.AddProductSpec(spec);
                _repo.SaveChanges();
            }
            Response <string> res = new Response <string>()
            {
                IsSuccess = true,
                Code      = "200",
                Message   = "Thêm sản phẩm thành công",
                Data      = "/admin/addvariant?pid=" + proId
            };

            return(res);
        }