public void UpdateEmployee(Employee employee) { try { using (var context = new NORTHWNDEntities()) { var employeeToUpdate = context.Employees.Where(x => x.EmployeeID == employee.EmployeeID).Select(x => x).FirstOrDefault(); if (employeeToUpdate != null) { employeeToUpdate.Address = employee.Address; employeeToUpdate.BirthDate = employee.BirthDate; employeeToUpdate.City = employee.City; employeeToUpdate.Country = employee.Country; employeeToUpdate.Extension = employee.Extension; employeeToUpdate.FirstName = employee.FirstName; employeeToUpdate.HireDate = employee.HireDate; employeeToUpdate.HomePhone = employee.HomePhone; employeeToUpdate.LastName = employee.LastName; employeeToUpdate.Notes = employee.Notes; employeeToUpdate.PostalCode = employee.PostalCode; employeeToUpdate.Region = employee.PostalCode; employeeToUpdate.ReportsTo = employee.ReportsTo; employeeToUpdate.Title = employee.Title; employeeToUpdate.TitleOfCourtesy = employee.TitleOfCourtesy; } context.SaveChanges(); } } catch (Exception ex) { throw new FaultException(ex.Message); } }
public void UpdateShipper(Shipper shipper) { using (var context = new NORTHWNDEntities()) { var shipperToUpdate = context.Shippers.Where(x => x.ShipperID == shipper.ShipperID).Select(x => x).FirstOrDefault(); if (shipperToUpdate != null) { shipperToUpdate.CompanyName = shipper.CompanyName; shipperToUpdate.Phone = shipper.Phone; } context.SaveChanges(); } }
public bool UpdateShipper(Shipper shipper) { using (var context = new NORTHWNDEntities()) { try { var shipperToUpdate = context.Shippers.FirstOrDefault(x => x.ShipperID == shipper.ShipperId); if (shipperToUpdate != null) { shipperToUpdate.ShipperID = shipper.ShipperId; shipperToUpdate.CompanyName = shipper.CompanyName; shipperToUpdate.Phone = shipper.Phone; } context.SaveChanges(); return true; } catch (Exception) { return false; throw; } } }
public bool UpdateShipper(Shipper shipper) { using (var context = new NORTHWNDEntities()) { try { var updatedShipper = context.Shippers.FirstOrDefault(x => x.ShipperID == shipper.ShipperID); if (updatedShipper != null) { updatedShipper.ShipperID = shipper.ShipperID; updatedShipper.CompanyName = shipper.CompanyName; updatedShipper.Phone = shipper.Phone; } context.SaveChanges(); return true; } catch (Exception ex) { throw new FaultException($"Shipper not updated {ex.Message}"); } } }