public Manager updateOfficer(string id, Manager off) { try { using (HotelManagementServerDataContext db = new HotelManagementServerDataContext()) { var query = (from acc in db.HOTEL_MANAGERs where acc.MANAGER_ID.Equals(Convert.ToInt32(id)) select acc); if (query.Count() == 1) { HOTEL_MANAGER acc = query.Single(); off = new Manager() { EmployeeNumber = acc.EMPLOYEE_NUM, CityID = acc.CITY_ID, ContactNumber = acc.CONTACT_NUM, Email = acc.EMAIL, Gender = acc.GENDER, Name = acc.FULL_NAMES, Surname = acc.SURNAME, Title = acc.TITLE, }; db.SubmitChanges(); return(off); } else { return(null); } } } catch (Exception) { return(null); } }
public string removeAdmin(string id) { try { using (HotelManagementServerDataContext db = new HotelManagementServerDataContext()) { var query = (from acc in db.HOTEL_MANAGERs where acc.MANAGER_ID.Equals(Convert.ToInt32(id)) select acc); if (query.Count() == 1) { HOTEL_MANAGER student = query.Single(); if (student.AUTHENTICATION_LEVEL == "A") { student.AUTHENTICATION_LEVEL = "S"; db.SubmitChanges(); return("Success Update Successful"); } else { return("Failed"); } } else { return("Failed Error User Not Found"); } } } catch (Exception) { return("Failed Update Failed"); } }
public string RegisterManager(Manager manager) { using (HotelManagementServerDataContext db = new HotelManagementServerDataContext()) { HOTEL_MANAGER officerLinq = null; try { int officerLinqTest = (from uOfficer in db.HOTEL_MANAGERs where uOfficer.EMAIL.Equals(manager.Email) select uOfficer).Count(); if (officerLinqTest == 0) { officerLinq = ConvertToLinq.ConvertOfficerToLinqObject(manager); db.HOTEL_MANAGERs.InsertOnSubmit(officerLinq); db.SubmitChanges(); return("Success Regristration Successful"); } else if (officerLinqTest != 0) { return("Failed Username already exists"); } } catch (Exception) { return("Failed Registration failed, contact admin"); } } return("Failed Registration failed, contact admin"); }
public void deleteOfficer(string offId) { try { using (HotelManagementServerDataContext db = new HotelManagementServerDataContext()) { HOTEL_MANAGER ToDelete = (from s in db.HOTEL_MANAGERs where s.MANAGER_ID.Equals(Convert.ToInt32(offId)) select s).Single(); db.HOTEL_MANAGERs.DeleteOnSubmit(ToDelete); db.SubmitChanges(); } } catch (Exception e) { e.GetBaseException(); } }
public string changePassword(string id, string oldPassword, string newPassword) { try { using (HotelManagementServerDataContext db = new HotelManagementServerDataContext()) { var query = (from acc in db.HOTEL_MANAGERs where acc.MANAGER_ID.Equals(Convert.ToInt32(id)) select acc); if (query.Count() == 1) { HOTEL_MANAGER student = query.Single(); string oldHashed = Secrecy.HashPassword(oldPassword); string passwordInDB = student.PASSWORD; if (oldHashed == passwordInDB) { student.PASSWORD = Secrecy.HashPassword(newPassword); db.SubmitChanges(); return("Password Changed"); } else { return("Incorrect old password"); } } else { return("Failed to change password"); } } } catch (Exception) { return("Failed to change password"); } }
public BaseUser Login(string email, string password) { CLIENT linqClient = null; HOTEL_MANAGER linqManager = null; HOTEL_OWNER linqOwner = null; using (HotelManagementServerDataContext db = new HotelManagementServerDataContext()) { try { //Search queries var query = (from uClient in db.CLIENTs where uClient.EMAIL.Equals(email) && uClient.PASSWORD.Equals(Secrecy.HashPassword(password)) select uClient); int linqClientCount = query.Count(); if (linqClientCount == 1) { linqClient = query.Single(); BaseUser client = new BaseUser(); client.ID = linqClient.CLIENT_ID; client.Title = linqClient.TITLE; client.Surname = linqClient.SURNAME; client.Name = linqClient.FULL_NAMES; client.Gender = linqClient.GENDER; client.Email = linqClient.EMAIL; client.ContactNumber = linqClient.CONTACT_NUM; client.AuthenticationLevel = linqClient.AUTHENTICATION_LEVEL; return(client); } else if (linqClientCount == 0) { var query2 = (from uOff in db.HOTEL_MANAGERs where uOff.EMAIL.Equals(email) && uOff.PASSWORD.Equals(Secrecy.HashPassword(password)) select uOff); int linqOfficerCount = query2.Count(); if (linqOfficerCount == 1) { linqManager = query2.Single(); if (linqManager.AUTHENTICATION_LEVEL == "M") { BaseUser manager = new BaseUser(); manager.Title = linqManager.TITLE; manager.Surname = linqManager.SURNAME; manager.Name = linqManager.FULL_NAMES; manager.Gender = linqManager.GENDER; manager.Email = linqManager.EMAIL; manager.ContactNumber = linqManager.CONTACT_NUM; manager.AuthenticationLevel = linqManager.AUTHENTICATION_LEVEL; manager.ID = linqManager.MANAGER_ID; return(manager); } else { return(null); } } else { var query3 = (from uOwn in db.HOTEL_OWNERs where uOwn.EMAIL.Equals(email) && uOwn.PASSWORD.Equals(Secrecy.HashPassword(password)) select uOwn); int linqOwnerCount = query3.Count(); if (linqOwnerCount == 1) { linqOwner = query3.Single(); BaseUser owner = new BaseUser(); owner.Title = linqOwner.TITLE; owner.Surname = linqOwner.SURNAME; owner.Name = linqOwner.FULL_NAMES; owner.Gender = linqOwner.GENDER; owner.Email = linqOwner.EMAIL; owner.ContactNumber = linqOwner.CONTACT_NUM; owner.AuthenticationLevel = linqOwner.AUTHENTICATION_LEVEL; owner.ID = linqOwner.OWNER_ID; return(owner); } else if (linqOwnerCount == 0) { return(null); } } } } catch (Exception) { return(null); //Find another way } return(null); //Find another way } }