Example #1
0
        // DELETE Treballador
        public static void DeleteTreballador(int id)
        {
            Treballador c = dataContext.Treballadors.Where(x => x.Id == id).SingleOrDefault();

            if (c != null)
            {
                dataContext.Treballadors.Remove(c);
                dataContext.SaveChanges();
            }
        }
Example #2
0
 // POST Treballador
 public static Treballador InsertTreballador(Treballador c)
 {
     try
     {
         dataContext.Treballadors.Add(c);
         dataContext.SaveChanges();
         return(GetTreballador(c.Id));
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Example #3
0
        // PUT Treballador
        public static Treballador UpdateTreballador(Treballador c)
        {
            try
            {
                Treballador c0 = dataContext.Treballadors.Where(x => x.Id == c.Id).SingleOrDefault();
                if (!String.IsNullOrEmpty(c.nom))
                {
                    c0.nom = c.nom;
                }
                if (!String.IsNullOrEmpty(c.cognoms))
                {
                    c0.cognoms = c.cognoms;
                }
                if (!String.IsNullOrEmpty(c.dni))
                {
                    c0.dni = c.dni;
                }
                if (!String.IsNullOrEmpty(c.correu))
                {
                    c0.correu = c.correu;
                }
                if (!String.IsNullOrEmpty(c.naixement))
                {
                    c0.naixement = c.naixement;
                }
                if (!String.IsNullOrEmpty(c.image))
                {
                    c0.image = c.image;
                }
                c0.CategoriaProfesional_Id = c.CategoriaProfesional_Id;

                dataContext.SaveChanges();
                return(GetTreballador(c.Id));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #4
0
        // GET Treballador
        public static Treballador GetTreballador(int id)
        {
            Treballador c = dataContext.Treballadors.Where(x => x.Id == id).SingleOrDefault();

            return(c);
        }