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

            context.Entry(employee).State = EntityState.Deleted;
            context.SaveChanges();
        }
Beispiel #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();
        }
Beispiel #3
0
        public static void DataChanges()
        {
            var ctx1 = new SoftUniEntities();

            var employee1 = ctx1.Employees.Find(1);

            employee1.FirstName = "Gosho";

            var ctx2 = new SoftUniEntities();

            var employee2 = ctx2.Employees.Find(1);

            employee2.FirstName = "Vanka";

            ctx1.SaveChanges();
            ctx2.SaveChanges();
        }
Beispiel #4
0
        public static void Main()
        {
            SoftUniEntities context = new SoftUniEntities();

            using (context)
            {
                //                Town townOne = new Town();
                //                townOne.Name = "Studentski Grad";
                //
                //                context.Towns.Add(townOne);
                //                context.SaveChanges();

                Town st = context.Towns.FirstOrDefault(town => town.Name == "Sofia");
                context.Addresses.RemoveRange(st.Addresses);
                context.Towns.Remove(st);
                context.SaveChanges();
            }
        }
Beispiel #5
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();
        }