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 Shipper GetShipperById(int id) { using (var context = new NORTHWNDEntities()) { return context.Shippers.Where(x => x.ShipperID == id).Select(x => new Shipper { ShipperID = x.ShipperID, CompanyName = x.CompanyName, Phone = x.Phone }).FirstOrDefault(); } }
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 Shipper GetShipperById(int id) { using (var context = new NORTHWNDEntities()) { try { return context.Shippers.Where(x => x.ShipperID == id).Select(x => new Shipper { CompanyName = x.CompanyName, Phone = x.Phone, ShipperId = x.ShipperID }).FirstOrDefault(); } catch (Exception e) { throw; } } }
public Employee GetEmployeeById(int id) { try { using (var context = new NORTHWNDEntities()) { var employee = context.Employees.Where(x => x.EmployeeID == id).Select(x => new Employee { EmployeeID = x.EmployeeID, Address = x.Address, BirthDate = x.BirthDate, City = x.City, Country = x.Country, Extension = x.Extension, FirstName = x.FirstName, HireDate = x.HireDate, HomePhone = x.HomePhone, LastName = x.LastName, Notes = x.Notes, PostalCode = x.PostalCode, Region = x.Region, ReportsTo = x.ReportsTo, Title = x.Title, TitleOfCourtesy = x.TitleOfCourtesy }).FirstOrDefault(); if (employee == null) { throw new FaultException("Could not find employee with this ID."); } return employee; } } catch(Exception ex) { throw new FaultException(ex.Message); } }
public Shipper GetShipperById(int id) { using (var context = new NORTHWNDEntities()) { try { return context.Shippers.Where(x => x.ShipperID == id).Select(x => new Shipper { ShipperID = x.ShipperID, CompanyName = x.CompanyName, Phone = x.Phone }).FirstOrDefault(); } catch (Exception ex) { throw new FaultException($"Found no shipper {ex.Message}"); } } }
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}"); } } }