Exemplo n.º 1
0
        public void InjectRessources(List <Ressource> ressources, List <string> ressourceTypes)
        {
            if (ressourceTypes.Any())
            {
                foreach (string cat in ressourceTypes.Distinct())
                {
                    TypeRessource tr = new TypeRessource();
                    tr.Label = cat;

                    if (!_context.TypeRessource.Where(x => x.Label.Equals(cat)).Any())
                    {
                        _context.TypeRessource.Add(tr);
                    }
                }
                _context.SaveChanges();
            }

            if (ressources.Any())
            {
                foreach (Ressource r in ressources)
                {
                    r.IdTypeRessource = _context.TypeRessource.Where(x => x.Label.Equals(r.TypeRessourceName)).Select(x => x.IdTypeRessource).FirstOrDefault();

                    _context.Ressource.Add(r);
                }
                _context.SaveChanges();
            }
        }
        public TypeRessource SaveTypeRessource(TypeRessource type)
        {
            WorkFlowContext ctx = new WorkFlowContext();
            Utilisateur user = ctx.Utilisateurs.Find(type.CreatedBy);
            type.Utilisateur = user;

            type = ctx.TypeRessources.Add(type);
            ctx.SaveChanges();
            type = ctx.TypeRessources.Find(type.TypeRessourceID);

            return type;
        }