Пример #1
0
        public void DeleteEnd()
        {
            //var deleteOrderDetails =
            //    from details in lContext.Persons
            //    where details.Id  == this.Id
            //    select details;


            DataSource.Employee lDeleted = lDataContext.Employees.SingleOrDefault(p => p.Id == this.Id);

            if (lDeleted != null)
            {
                lDataContext.Employees.DeleteOnSubmit(lDeleted);

                try
                {
                    lDataContext.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    // Provide for exceptions.
                }
            }
        }
Пример #2
0
        public void EndEdit()
        {
            Boolean lChanged = false;

            DataSource.Employee lUpdate = lDataContext.Employees.SingleOrDefault(p => p.Id == this.Id);


            if (lUpdate == null)
            {
                DataSource.Employee newItem = new DataSource.Employee
                {
                    PersonId = this.PersonId,
                    DateIn   = this.DateIn,
                    DateOut  = this.DateOut,
                };
                // Add the new object to the Orders collection.
                lDataContext.Employees.InsertOnSubmit(newItem);

                // Submit the change to the database.
                try
                {
                    lDataContext.SubmitChanges();

                    this.Id = newItem.Id;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            else
            {
                lUpdate.PersonId = this.PersonId;
                lUpdate.DateIn   = this.DateIn;
                lUpdate.DateOut  = this.DateOut;

                lDataContext.SubmitChanges();
            }

            DataSource.Emp_Dept lEmpDept;

            foreach (HSDepartment l in this.Departments)
            {
                lEmpDept = lDataContext.Emp_Depts.SingleOrDefault(p => p.EmployeeId == this.Id && p.DepartmentId == l.Id);


                if (lEmpDept == null)
                {
                    if (l.IsSelected)
                    {
                        DataSource.Emp_Dept newEmpDept = new DataSource.Emp_Dept
                        {
                            EmployeeId   = this.Id,
                            DepartmentId = l.Id
                        };
                        // Add the new object to the Orders collection.
                        lDataContext.Emp_Depts.InsertOnSubmit(newEmpDept);
                        lChanged = true;
                    }
                }
                else
                {
                    if (l.IsSelected)
                    {
                        lEmpDept.EmployeeId   = this.Id;
                        lEmpDept.DepartmentId = l.Id;
                    }
                    else
                    {
                        lDataContext.Emp_Depts.DeleteOnSubmit(lEmpDept);
                    }

                    lChanged = true;
                }

                try
                {
                    if (lChanged)
                    {
                        lDataContext.SubmitChanges();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }