//public void AddJewelry(AddJewelry jewelry, ImageHelper image) public void AddJewelry(AddJewelry jewelry) { using (var _context = new SmyckenContext()) { var image = new Image() { FileName = jewelry.PictureFileName, Url = jewelry.PictureURL, News = false, Description = "", Category = jewelry.Category }; _context.Images.Add(image); _context.SaveChanges(); var newJewelry = _context.Jewelries.Add(new Jewelry() { Name = jewelry.Name, Price = jewelry.Price, Quantity = jewelry.Quantity, Description = jewelry.Description, Category = jewelry.Category, Visibility = true, Image = image }); _context.Jewelries.Add(newJewelry); _context.SaveChanges(); } }
public void RemoveJewelry(int jewelry) { using (var _context = new SmyckenContext()) { var updateJewelry = (from j in _context.Jewelries where j.ID == jewelry select j).FirstOrDefault(); if (updateJewelry != null) { updateJewelry.Visibility = false; } _context.SaveChanges(); } }
public void UpdateJewelry(EditJewelry jewelry) { using (var _context = new SmyckenContext()) { var updateJewelry = (from j in _context.Jewelries where j.ID == jewelry.ID && j.Visibility == true select j).FirstOrDefault(); if (updateJewelry != null) { updateJewelry.ID = jewelry.ID; updateJewelry.Name = jewelry.Name; updateJewelry.Price = jewelry.Price; updateJewelry.Quantity = jewelry.Quantity; updateJewelry.Category = jewelry.Category; updateJewelry.Description = jewelry.Description; } _context.SaveChanges(); } }