public bool editEmployee(int id, Employee inEmp) { var db = new WAPPContext(); try { var editEmp = db.Employee.Find(id); editEmp.FirstName = inEmp.FirstName; editEmp.LastName = inEmp.LastName; editEmp.PhoneNumber = inEmp.PhoneNumber; editEmp.EMail = inEmp.EMail; editEmp.Address = inEmp.Address; if (editEmp.ZipCode != inEmp.ZipCode) { if (db.City.FirstOrDefault(z => z.ZipCode == inEmp.ZipCode) == null) { var newCity = new City() { ZipCode = inEmp.ZipCode, CityName = inEmp.City }; db.City.Add(newCity); } editEmp.ZipCode = inEmp.ZipCode; } db.SaveChanges(); return(true); } catch (Exception exception) { LogException(exception); return(false); } }
public bool editCustomer(int id, AdminCustomer inCust) { var db = new WAPPContext(); try { var editCust = db.Customer.Find(id); editCust.FirstName = inCust.FirstName; editCust.LastName = inCust.LastName; editCust.PhoneNumber = inCust.PhoneNumber; editCust.EMail = inCust.EMail; editCust.Address = inCust.Address; if (editCust.ZipCode != inCust.ZipCode) { if (db.City.FirstOrDefault(z => z.ZipCode == inCust.ZipCode) == null) { var newCity = new City() { ZipCode = inCust.ZipCode, CityName = inCust.City }; db.City.Add(newCity); } editCust.ZipCode = inCust.ZipCode; } db.SaveChanges(); return(true); } catch (Exception exception) { LogException(exception); return(false); } }
public bool deleteEmployee(int id) { var db = new WAPPContext(); try { db.Shadow.Remove(db.Shadow.Find(id)); db.Employee.Remove(db.Employee.Find(id)); db.SaveChanges(); return(true); } catch (Exception exception) { LogException(exception); return(false); } }
public bool insertEmployee(EmployeeRegister inEmp) { using (var db = new WAPPContext()) { try { var newEmp = new Employee_DB(); var newShadow = new Shadow_DB(); string salt = Salt(); var passwordNSalt = inEmp.Password + salt; byte[] passwordDB = Hash(passwordNSalt); newEmp.FirstName = inEmp.FirstName; newEmp.LastName = inEmp.LastName; newEmp.Address = inEmp.Address; newEmp.ZipCode = inEmp.ZipCode; newEmp.EMail = inEmp.EMail; newEmp.PhoneNumber = inEmp.PhoneNumber; newShadow.Username = inEmp.Username; newShadow.Password = passwordDB; newShadow.Salt = salt; newEmp.Shadow = newShadow; var existingZip = db.City.Find(inEmp.ZipCode); if (existingZip == null) { var newCity = new City() { ZipCode = inEmp.ZipCode, CityName = inEmp.City }; newEmp.City = newCity; } db.Employee.Add(newEmp); db.SaveChanges(); return(true); } catch (Exception exception) { LogException(exception); return(false); } } }
public bool deleteCustomer(int id) { var db = new WAPPContext(); try { var c = db.Customer.Find(id); if (c.ContactPerson == true) { foreach (var item in c.Booking.Flights) { item.Seats += c.Booking.Travelers; } int t = c.Booking.ID; var list = db.Customer.Where(w => w.Booking.ID == t).ToList(); foreach (var i in list) { db.Customer.Remove(i); } db.Booking.Remove(db.Booking.Find(t)); } else { c.Booking.Travelers--; foreach (var item in c.Booking.Flights) { item.Seats++; } db.Customer.Remove(c); } db.SaveChanges(); return(true); } catch (Exception exception) { LogException(exception); return(false); } }
public bool editEmployeeLogin(int id, EmployeeEditLogin inEEL) { using (var db = new WAPPContext()) { try { var editShadow = db.Shadow.Find(id); string salt = Salt(); var passwordNSalt = inEEL.Password + salt; byte[] passwordDB = Hash(passwordNSalt); editShadow.Username = inEEL.Username; editShadow.Password = passwordDB; editShadow.Salt = salt; db.SaveChanges(); return(true); } catch (Exception exception) { LogException(exception); return(false); } } }