public static void storeEmployee(string employeeName, String employeeEmail) { using (var db = new PhoneLog.Models.PhoneLogContext()) { var employee = new PhoneLog.Models.Employee { EmployeeName = employeeName, EmployeeEmail = employeeEmail }; db.Employees.Add(employee); try { int result = db.SaveChanges(); Console.WriteLine(result); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } }
public static void storeCallType(string callType) { using (var db = new PhoneLog.Models.PhoneLogContext()) { var call = new PhoneLog.Models.CallType { CallType1 = callType }; db.CallTypes.Add(call); try { int result = db.SaveChanges(); Console.WriteLine(result); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } }
public static void deleteEmployee(int id) { using (var db = new PhoneLog.Models.PhoneLogContext()) { var employee = db.Employees.Where(item => item.Id == id).Single(); db.Employees.Remove(employee); db.SaveChanges(); } }
public static void deleteCallType(int id) { using (var db = new PhoneLog.Models.PhoneLogContext()) { var callType = db.CallTypes.Where(item => item.Id == id).Single(); db.CallTypes.Remove(callType); db.SaveChanges(); } }