Example #1
0
        public static void AddType(this DBEntities DB, ItemView itemView)
        {
            Arme      arme      = new Arme();
            Armure    armure    = new Armure();
            Potion    potion    = new Potion();
            Ressource ressource = new Ressource();

            if (itemView.Type == typeItem.Arme)
            {
                BeginTransaction(DB);
                arme.genre      = itemView.genreArme.ToString();
                arme.efficacite = itemView.efficaciteArme;
                arme.idItems    = itemView.Id;
                DB.Armes.Add(arme);
            }
            else if (itemView.Type == typeItem.Armure)
            {
                BeginTransaction(DB);
                armure.matiere = itemView.matiere;
                armure.Poids   = itemView.poids;
                armure.taille  = itemView.taille;
                armure.idItems = itemView.Id;
                DB.Armures.Add(armure);
            }
            else if (itemView.Type == typeItem.Potion)
            {
                BeginTransaction(DB);
                potion.duree   = itemView.duree;
                potion.effet   = itemView.effet;
                potion.idItems = itemView.Id;
                DB.Potions.Add(potion);
            }
            else if (itemView.Type == typeItem.Ressource)
            {
                BeginTransaction(DB);
                ressource.description = itemView.description;
                ressource.idItems     = itemView.Id;
                DB.Ressources.Add(ressource);
            }
            DB.SaveChanges();
            Commit();
        }
Example #2
0
        public static ItemView EditItem(this DBEntities DB, ItemView itemView)
        {
            BeginTransaction(DB);
            itemView.SaveImage();
            Item item = itemView.ToItem();

            item.Type            = itemView.Type.ToString();
            DB.Entry(item).State = EntityState.Modified;
            if (item.Type == typeItem.Arme.ToString())
            {
                Arme arme = DB.Armes.Where(i => i.idItems.Equals(item.Id)).FirstOrDefault();
                arme.efficacite      = itemView.efficaciteArme;
                arme.genre           = itemView.genreArme.ToString();
                DB.Entry(arme).State = EntityState.Modified;
            }
            else if (item.Type == typeItem.Armure.ToString())
            {
                Armure armure = DB.Armures.Where(i => i.idItems.Equals(item.Id)).FirstOrDefault();
                armure.matiere         = itemView.matiere;
                armure.Poids           = itemView.poids;
                armure.taille          = itemView.taille;
                DB.Entry(armure).State = EntityState.Modified;
            }
            else if (item.Type == typeItem.Potion.ToString())
            {
                Potion potion = DB.Potions.Where(i => i.idItems.Equals(item.Id)).FirstOrDefault();
                potion.duree           = itemView.duree;
                potion.effet           = itemView.effet;
                DB.Entry(potion).State = EntityState.Modified;
            }
            else if (item.Type == typeItem.Ressource.ToString())
            {
                Ressource ressource = DB.Ressources.Where(i => i.idItems.Equals(item.Id)).FirstOrDefault();
                ressource.description     = itemView.description;
                DB.Entry(ressource).State = EntityState.Modified;
            }
            DB.SaveChanges();
            Commit();
            return(item.ToItemView());
        }