Ejemplo n.º 1
0
        //public void AddPhone(ProductModel model, PhoneModel p)
        //{
        //    string imageName = UploadImage(model.proName, "chung", model.proImageStream);
        //    Product product = _mapper.Map<Product>(model);
        //    product.ProVisible = false;
        //    product.ProTypeId = null;
        //    product.ProImage = imageName;
        //    int proId = _repo.AddProduct(product);


        //    int index = 1;
        //    Type type = typeof(PhoneModel);
        //    PropertyInfo[] properties = type.GetProperties();
        //    foreach (PropertyInfo property in properties)
        //    {
        //        ProSpecification spec = new ProSpecification()
        //        {
        //            ProId = proId,
        //            SpecIndex = index,
        //            SpecValue = property.GetValue(p, null).ToString()
        //        };

        //        _repo.AddProductSpec(spec);
        //        _repo.SaveChanges();
        //        index++;
        //    }

        //}



        public void AddVariant(VariantModel v)
        {
            string _iconImage = UploadImageAsync(v.proColorIcon);



            ProVariant proVariant = new ProVariant()
            {
                ProId        = v.proId,
                VarColor     = v.color,
                VarQty       = v.proQty,
                VarColorIcon = _iconImage,
                VarStatus    = v.proStatus,
                DateCreated  = DateTime.Now
            };

            _repo.AddPhoneVariant(proVariant);
            _repo.SaveChanges();

            for (int i = 0; i < v.proColorImage.Length; i++)
            {
                VarImages varImages = new VarImages()
                {
                    ImgPath = UploadImageAsync(v.proColorImage[i]),
                    VarId   = proVariant.VarId,
                    Index   = i + 1,
                };
                _repo.AddVariantImages(varImages);
                _repo.SaveChanges();
            }
        }