Example #1
0
        public string UpdateEmployeeInfo(MyEmployee employee)
        {
            try
            {
                DateTime x;
                using (var db = new theDB())
                {
                    var theEmployee = (from e in db.Employees
                                       where e.EmployeeID == employee.EmployeeId
                                       select e).FirstOrDefault();

                    if (theEmployee == null)
                    {
                        throw new FaultException("There is no employee with given ID");
                    }

                    theEmployee.FirstName       = employee.FirstName;
                    theEmployee.LastName        = employee.LastName;
                    theEmployee.Address         = employee.Address;
                    theEmployee.PostalCode      = employee.PostalCode;
                    theEmployee.Region          = employee.Region;
                    theEmployee.Title           = employee.Title;
                    theEmployee.TitleOfCourtesy = employee.TitleOfCourtesy;
                    theEmployee.BirthDate       = employee.BirthDate;
                    theEmployee.City            = employee.City;
                    theEmployee.Country         = employee.Country;
                    theEmployee.Notes           = employee.Notes;
                    theEmployee.Extension       = employee.Extension;
                    theEmployee.HireDate        = employee.HireDate;
                    theEmployee.HomePhone       = employee.HomePhone;
                    theEmployee.ReportsTo       = employee.ReportsTo;

                    db.SaveChanges();
                }
                return("The Employee was updated successfully");
            }
            catch (FaultException exc)
            {
                throw new FaultException(exc.Message);
            }
            catch (Exception)
            {
                throw new FaultException("Something went wrong while trying to save the employee. Try again later.");
            }
        }
Example #2
0
        public string UpdateEmployeeInfo(MyEmployee employee)
        {
            try
            {
                DateTime x;
                using (var db = new theDB())
                {
                    var theEmployee = (from e in db.Employees
                                       where e.EmployeeID == employee.EmployeeId
                                       select e).FirstOrDefault();

                    if (theEmployee == null)
                        throw new FaultException("There is no employee with given ID");

                    theEmployee.FirstName = employee.FirstName;
                    theEmployee.LastName = employee.LastName;
                    theEmployee.Address = employee.Address;
                    theEmployee.PostalCode = employee.PostalCode;
                    theEmployee.Region = employee.Region;
                    theEmployee.Title = employee.Title;
                    theEmployee.TitleOfCourtesy = employee.TitleOfCourtesy;
                    theEmployee.BirthDate = employee.BirthDate;
                    theEmployee.City = employee.City;
                    theEmployee.Country = employee.Country;
                    theEmployee.Notes = employee.Notes;
                    theEmployee.Extension = employee.Extension;
                    theEmployee.HireDate = employee.HireDate;
                    theEmployee.HomePhone = employee.HomePhone;
                    theEmployee.ReportsTo = employee.ReportsTo;

                    db.SaveChanges();
                }
                return "The Employee was updated successfully";
            }
            catch (FaultException exc)
            {
                throw new FaultException(exc.Message);
            }
            catch (Exception)
            {
                throw new FaultException("Something went wrong while trying to save the employee. Try again later.");
            }
        }