Example #1
0
        public void update(Jewelry jewelry)
        {
            Context con = new Context();
            Jewelry j   = con.Jewelries.Find(jewelry.Id);

            if (j != null)
            {
                j.Description = jewelry.Description;
                j.Name        = jewelry.Name;
                j.Price       = jewelry.Price;
                j.ReleaseDate = jewelry.ReleaseDate;
                j.Type        = new JewelryType {
                    Id = jewelry.Type.Id
                };
                j.Color = new JewelryColor {
                    Id = jewelry.Color.Id
                };
                j.Category = new JewelryCategory {
                    Id = jewelry.Category.Id
                };
                con.Entry(j.Color).State    = EntityState.Unchanged;
                con.Entry(j.Category).State = EntityState.Unchanged;
                con.Entry(j.Type).State     = EntityState.Unchanged;
                con.Entry(j).State          = EntityState.Modified;
                con.SaveChanges();
            }
        }
Example #2
0
        public void Remove(Jewelry jewelry)
        {
            Context con = new Context();

            using (con)
            {
                con.Jewelries.Remove(jewelry);
                con.SaveChanges();
            }
        }
Example #3
0
        public void Add(Jewelry jewelry)
        {
            Context con = new Context();

            using (con)
            {
                con.Entry(jewelry.Category).State = EntityState.Unchanged;
                con.Entry(jewelry.Color).State    = EntityState.Unchanged;
                con.Entry(jewelry.Type).State     = EntityState.Unchanged;
                con.Jewelries.Add(jewelry);
                con.SaveChanges();
            }
        }