public void CreateCategory(dynamic Categorydetails) { dynamic CategorydetailsJSON = JsonConvert.DeserializeObject(Categorydetails.ToString()); Console.WriteLine(CategorydetailsJSON); Category Category = new Category() { CategoryName = CategorydetailsJSON.CategoryName, Id = CategorydetailsJSON.CategoryId }; _context.Categories.Add(Category); _Type Type = new _Type() { _TypeName = CategorydetailsJSON.TypeName, Id = CategorydetailsJSON.TypeId }; _context.Types.Add(Type); Category_Type CT = new Category_Type() { CategoryId = Category.Id, _TypeId = Type.Id }; _context.CategoryType.Add(CT); _context.SaveChanges(); }
public ActionResult CreateType(CategoryTypeViewModel viewModel) { if (ModelState.IsValid) { var model = new Category_Type { Name = viewModel.Name, Description = viewModel.Desciption, CreateUserId = User.Identity.GetUserId(), CreateTime = DateTime.Now }; db.Category_types.Add(model); db.SaveChanges(); return(RedirectToAction("CreateType", new { success = true, susccessObjName = model.Name })); } return(View(viewModel)); }
public void CreateProduct(dynamic ProductDetails) { dynamic ProductDetailsJSON = JsonConvert.DeserializeObject(ProductDetails.ToString()); int _categoryId; int _brandId; int _collectionId; int _typeid; ///////////////CATEGORY//////////////// dynamic c = 1; if (ProductDetailsJSON.CategoryId != null) { int category = ProductDetailsJSON.CategoryId; c = _context.Categories.Find(category); } if (c == null || ProductDetailsJSON.CategoryId == null) { Category _Category = new Category() { Id = _context.Categories.Select(a => a.Id).Max() + 1, CategoryName = ProductDetailsJSON.CategoryName }; _context.Categories.Add(_Category); _categoryId = _Category.Id; //_context.SaveChanges(); } else { _categoryId = ProductDetailsJSON.CategoryId; } ///////////////TYPE//////////////// dynamic t = 1; if (ProductDetailsJSON.TypeId != null) { int type = ProductDetailsJSON.TypeId; t = _context.Types.Find(type); } if (t == null || ProductDetailsJSON.TypeId == null) { _Type _Type = new _Type() { Id = _context.Types.Select(a => a.Id).Max() + 1, _TypeName = ProductDetailsJSON.TypeName }; _context.Types.Add(_Type); _typeid = _Type.Id; Category_Type CT = new Category_Type() { CategoryId = _categoryId, _TypeId = _typeid }; _context.CategoryType.Add(CT); } else { _typeid = ProductDetailsJSON.TypeId; } ///////////////BRAND//////////////// dynamic b = 1; if (ProductDetailsJSON.BrandId != null) { int brand = ProductDetailsJSON.BrandId; b = _context.Brands.Find(brand); } if (b == null || ProductDetailsJSON.BrandId == null) { Brand Brand = new Brand() { Id = _context.Brands.Select(a => a.Id).Max() + 1, BrandName = ProductDetailsJSON.BrandName }; _context.Brands.Add(Brand); _brandId = Brand.Id; //_context.SaveChanges(); } else { _brandId = ProductDetailsJSON.BrandId; } ///////////////Collection//////////////// dynamic co = 1; if (ProductDetailsJSON.CollectionId != null) { int coll = ProductDetailsJSON.CollectionId; co = _context.Collections.Find(coll); } if (co == null || ProductDetailsJSON.CollectionId == null) { Collection Collection = new Collection() { Id = _context.Collections.Select(a => a.Id).Max() + 1, BrandId = _brandId, CollectionName = ProductDetailsJSON.CollectionName }; _context.Collections.Add(Collection); _collectionId = Collection.Id; } else { _collectionId = ProductDetailsJSON.CollectionId; } ///////////////STOCK//////////////// Stock Stock = new Stock() { //Id = ProductDetailsJSON.StockId, Id = _context.Stock.Select(a => a.Id).Max() + 1, ProductQuantity = ProductDetailsJSON.Stock }; _context.Stock.Add(Stock); ///////////////PRODUCT//////////////// Product Product = new Product() { ProductName = ProductDetailsJSON.ProductName, _TypeId = _typeid, //ProductDetailsJSON.TypeId, CategoryId = _categoryId, //ProductDetailsJSON.CategoryId, CollectionId = _collectionId, //ProductDetailsJSON.CollectionId, BrandId = _brandId, //ProductDetailsJSON.BrandId, StockId = Stock.Id, //ProductDetailsJSON.StockId, Id = _context.Products.Select(a => a.Id).Max() + 1, ProductNumber = ProductDetailsJSON.ProductNumber, ProductEAN = ProductDetailsJSON.ProductEAN, ProductInfo = ProductDetailsJSON.ProductInfo, ProductDescription = ProductDetailsJSON.ProductDescription, ProductSpecification = ProductDetailsJSON.ProductSpecification, ProductPrice = ProductDetailsJSON.ProductPrice, ProductColor = ProductDetailsJSON.ProductColor, }; _context.Products.Add(Product); ///////////////IMAGE//////////////// // ProductImage ProductImage = new ProductImage() // { // ProductId = Product.Id, // ImageURL = ProductDetailsJSON.ImageURL, // //Id = ProductDetailsJSON.ImageId // Id = _context.ProductImages.Select(a => a.Id).Max() + 1, // }; // _context.ProductImages.Add(ProductImage); _context.SaveChanges(); }