Exemple #1
0
        public static void Delete(Employee employee)
        {
            var context = new SoftUniEntities();

            context.Entry(employee).State = EntityState.Deleted;
            context.SaveChanges();
        }
Exemple #2
0
        public static void Add(Employee employee)
        {
            var context = new SoftUniEntities();

            var entry = context.Entry(employee);

            entry.State = EntityState.Added;

            context.Employees.Add(employee);
            context.SaveChanges();
        }
Exemple #3
0
        public static void Modify(Employee employee, string newName)
        {
            var context = new SoftUniEntities();

            string[] name      = Regex.Split(newName.Trim(), @"\s+");
            string   firstName = Regex.Split(newName.Trim(), @"\s+")[0];

            employee.FirstName = firstName;

            if (name.Length == 2)
            {
                string lastName = Regex.Split(newName.Trim(), @"\s+")[0];
                employee.LastName = lastName;
            }

            var entry = context.Entry(employee);

            entry.State = EntityState.Modified;

            context.SaveChanges();
        }