コード例 #1
0
ファイル: EmployeeService.svc.cs プロジェクト: raldholm/LAB3
        public void SaveEmployee(MyEmployee employee)
        {
            try
            {
                var newemployee = context.Employees.SingleOrDefault(s => s.EmployeeID == employee.EmployeeId);
                if (employee != null)
                {

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

                    context.SaveChanges();

                }

            }
            catch (Exception)
            {
                throw new System.Data.Entity.Infrastructure.DbUpdateException();
            }
        }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: raldholm/LAB3
        protected void SaveEmployee_Button_Click(object sender, EventArgs e)
        {
            try
            {
                EmployeeServiceClient client = new EmployeeServiceClient();
                if (client.State == CommunicationState.Faulted)
                    client = new EmployeeServiceClient();

                MyEmployee employee = new MyEmployee();
                employee.EmployeeId = Convert.ToInt32(DisplayEmployee_TextBox.Text.Trim());
                employee.LastName = LastName_TextBox.Text.Trim();
                employee.FirstName = FirstName_TextBox.Text.Trim();
                employee.Title = Title_TextBox.Text.Trim();
                employee.TitleOfCourtesy = TitleOfCourtesy_TextBox.Text.Trim();
                employee.BirthDate = Convert.ToDateTime(BirthDate_TextBox.Text.Trim());
                employee.HireDate = Convert.ToDateTime(HireDate_TextBox.Text.Trim());
                employee.Address = Adress_TextBox.Text.Trim();
                employee.City = City_TextBox.Text.Trim();
                employee.Region = Region_TextBox.Text.Trim();
                employee.PostalCode = PostalCode_TextBox.Text.Trim();
                employee.Country = Country_TextBox.Text.Trim();
                employee.HomePhone = HomePhone_TextBox.Text.Trim();
                employee.Extension = Extension_TextBox.Text.Trim();
                employee.Notes = Notes_TextBox.Text.Trim();
                employee.ReportsTo = Convert.ToInt32(ReportsTo_TextBox.Text.Trim());

                client.SaveEmployee(employee);
                Response.Write("SPARAT!");
            }
            catch (FormatException ex)
            {
                Response.Write("Opps! Felaktig data inmatad - ");
                Response.Write("Felmeddelande: ");
                Response.Write(ex.Message);
                Response.Write(" Börja om genom att klicka <a href='Default.aspx'>" +
                    "här.");
            }
            catch (NullReferenceException ex)
            {
                Response.Write("Opps! Du måste sätta ett värde! - ");
                Response.Write("Felmeddelande: ");
                Response.Write(ex.Message);
                Response.Write(" Börja om genom att klicka <a href='Default.aspx'>" +
                    "här.");
            }

        }
コード例 #3
0
ファイル: EmployeeService.svc.cs プロジェクト: raldholm/LAB3
 public MyEmployee GetEmployee(int employeeId)
 {
     try
     {
         var newemployee = context.Employees.SingleOrDefault(s => s.EmployeeID == employeeId);
         MyEmployee employee = new MyEmployee();
         if (newemployee != null)
         {
             employee.EmployeeId = newemployee.EmployeeID;
             employee.LastName = newemployee.LastName;
             employee.FirstName = newemployee.FirstName;
             employee.Title = newemployee.Title;
             employee.TitleOfCourtesy = newemployee.TitleOfCourtesy;
             employee.BirthDate = newemployee.BirthDate;
             employee.HireDate = newemployee.HireDate;
             employee.Address = newemployee.Address;
             employee.City = newemployee.City;
             employee.Region = newemployee.Region;
             employee.PostalCode = newemployee.PostalCode;
             employee.Country = newemployee.Country;
             employee.HomePhone = newemployee.HomePhone;
             employee.Extension = newemployee.Extension;
             employee.Notes = newemployee.Notes;
             employee.ReportsTo = newemployee.ReportsTo;
         }
         return employee;
     }
     catch (CommunicationException ex)
     {
         throw new FaultException("An invalid operation has occurred."+ex.Message);
     }
     catch (Exception)
     {
         return new MyEmployee();
     }
 }