public void UpdateProduct(Products _Product, MobileProperties Mobile, LaptopProperties Laptop) { Products prod = _Context.Products.Where(x => x.ProductId == _Product.ProductId).SingleOrDefault(); prod.BrandId = _Product.BrandId; prod.CategoryId = _Product.CategoryId; prod.ProductName = _Product.ProductName; prod.ProductDescription = _Product.ProductDescription; prod.ProductPrice = _Product.ProductPrice; prod.ProductQuantity = _Product.ProductQuantity; prod.Discount = _Product.Discount; prod.VendorName = _Product.VendorName; prod.ProductColor = _Product.ProductColor; prod.ProductRate = _Product.ProductRate; prod.IsOffer = _Product.IsOffer; _Context.SaveChanges(); if (Mobile != null) { UpdateMobile(Mobile, _Product.ProductId); } if (Laptop != null) { UpdateLaptop(Laptop, _Product.ProductId); } }
public async Task <IActionResult> Edit(int id, [Bind("ProductId,ScreenSize,ScreenType,Ram,CameraPropertry,Battery,ModeNo,FingerPrint,WaterResist,Processor,HardType,HardStorage,Genaration,ExtraProperty")] LaptopProperties laptopProperties) { if (id != laptopProperties.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(laptopProperties); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LaptopPropertiesExists(laptopProperties.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", laptopProperties.ProductId); return(View(laptopProperties)); }
public async Task <IActionResult> Create([Bind("ProductId,ScreenSize,ScreenType,Ram,CameraPropertry,Battery,ModeNo,FingerPrint,WaterResist,Processor,HardType,HardStorage,Genaration,ExtraProperty")] LaptopProperties laptopProperties) { if (ModelState.IsValid) { _context.Add(laptopProperties); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", laptopProperties.ProductId); return(View(laptopProperties)); }
public void AddProduct(Products _Product, MobileProperties Mobile, LaptopProperties Laptop) { _Product.ProductId = (_Context.Products.Select(x => x.ProductId).Max() + 1); _Context.Products.Add(_Product); _Context.SaveChanges(); if (Mobile != null) { Mobile.ProductId = _Product.ProductId; _Context.MobileProperties.Add(Mobile); _Context.SaveChanges(); } if (Laptop != null) { Laptop.ProductId = _Product.ProductId; _Context.LaptopProperties.Add(Laptop); _Context.SaveChanges(); } }
void UpdateLaptop(LaptopProperties laptop, int prod_Id) { LaptopProperties _Laptop = _Context.LaptopProperties.Where(x => x.ProductId == prod_Id).SingleOrDefault(); _Laptop.ScreenSize = laptop.ScreenSize; _Laptop.ScreenType = laptop.ScreenType; _Laptop.Ram = laptop.Ram; _Laptop.CameraPropertry = laptop.CameraPropertry; _Laptop.Battery = laptop.Battery; _Laptop.ModeNo = laptop.ModeNo; _Laptop.FingerPrint = laptop.FingerPrint; _Laptop.WaterResist = laptop.WaterResist; _Laptop.Processor = laptop.Processor; _Laptop.HardType = laptop.HardType; _Laptop.HardStorage = laptop.HardStorage; _Laptop.Genaration = laptop.Genaration; _Laptop.ExtraProperty = laptop.ExtraProperty; _Context.SaveChanges(); }