//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 List<JewelryHelper> GetAllEarrings()
 {
     using (var _context = new SmyckenContext())
     {
         return (from a in _context.Jewelries
                 orderby a.ID descending
                 where a.Category == JewelryCategory.Earrings && a.Visibility == true
                 select new JewelryHelper
                 {
                     ID = a.ID,
                     Description = a.Description,
                     ArticleNr = a.ArticleNr,
                     Name = a.Name,
                     Price = a.Price,
                     PictureFileName = a.Image.FileName,
                     Category = a.Category,
                     Quantity = a.Quantity
                 }).ToList();
     }
 }
        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();
            }
        }
 public JewelryHelper GetOneJewelryById(int jewelryID)
 {
     using (var _context = new SmyckenContext())
     {
         _context.Jewelries.AsNoTracking();
         return (from a in _context.Jewelries
                 where a.ID == jewelryID && a.Visibility == true
                 select new JewelryHelper
                 {
                     ID = a.ID,
                     Description = a.Description,
                     Name = a.Name,
                     Price = a.Price,
                     Quantity = a.Quantity,
                     //ImageFileName = a.Image.FileName,
                     Category = a.Category
                 }).FirstOrDefault();
     }
 }
 public List<ImageHelper> GetAllNewsImage()
 {
     using (var _context = new SmyckenContext())
     {
         return (from i in _context.Images
                 where (i.News == true)
                 select new ImageHelper()
                 {
                     FileName = i.FileName,
                     Description = i.Description,
                     News = i.News,
                     Category = i.Category
                 }).ToList();
     }
 }