private void SaveExecute() { try { User.Gender = Gender.ToString(); User.MarriageStatus = Status; using (CompanyDBEntities db = new CompanyDBEntities()) { db.tblUsers.Add(User); db.SaveChanges(); int id = db.tblUsers.Where(u => u.JMBG == User.JMBG).FirstOrDefault().UserID; Admin.ExpirationDate = DateTime.Now.AddDays(7); Admin.AdminType = Type; Admin.UserID = id; db.tblAdmins.Add(Admin); db.SaveChanges(); } MessageBox.Show("Administrator Created Successfully!"); main.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
// Method that add Admin to database public void AddAdmin(vwAdmin admin) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblUser newUser = new tblUser(); tblAdmin newAdmin = new tblAdmin(); newUser.FirstName = admin.FirstName; newUser.LastName = admin.LastName; newUser.JMBG = admin.JMBG; newUser.Gender = admin.Gender; newUser.Residence = admin.Residence; newUser.MarriageStatus = admin.MarriageStatus; newUser.Username = admin.Username; newUser.UserPassword = SecurePasswordHasher.Hash(admin.UserPassword); context.tblUsers.Add(newUser); context.SaveChanges(); admin.UserID = newUser.UserID; newAdmin.UserID = admin.UserID; newAdmin.ExpirationDate = DateTime.Now.AddDays(7); newAdmin.AdminType = admin.AdminType; context.tblAdmins.Add(newAdmin); context.SaveChanges(); admin.AdminID = newAdmin.AdminID; } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// method for deleting the project /// </summary> private void DeleteProjectExecute() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { int id = project.ProjectID; // checking the action MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to delete the project?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { tblProject projectToDelete = (from x in context.tblProjects where x.ProjectID == id select x).First(); // deleting the project context.tblProjects.Remove(projectToDelete); context.SaveChanges(); // updating the list ProjectList = GetAllProjects().ToList(); MessageBox.Show("The project deleted successfully."); // logging the action FileActions.FileActions.Instance.Deleting(FileActions.FileActions.path, FileActions.FileActions.actions, "project", projectToDelete.ProjectName); } } } catch (Exception) { MessageBox.Show("The project can not be deleted, please try again."); } }
private void SaveExecute() { try { using (CompanyDBEntities db = new CompanyDBEntities()) { User.Gender = Gender.ToString(); User.MarriageStatus = Status; db.tblUsers.Add(User); db.SaveChanges(); Worker.UserID = User.UserID; Worker.YearsOfService = 0; Worker.EducationDegree = Degree; db.tblWorkers.Add(Worker); db.SaveChanges(); } MessageBox.Show("Worker Created Successfully!"); main.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private void SaveExecute() { try { using (CompanyDBEntities db = new CompanyDBEntities()) { User.Gender = Gender.ToString(); User.MarriageStatus = Status; db.tblUsers.Add(User); db.SaveChanges(); Manager.UserID = User.UserID; Manager.ReservedPassword = Manager.ReservedPassword + "WPF"; db.tblManagers.Add(Manager); db.SaveChanges(); } MessageBox.Show("Manager Created Successfully!"); main.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
/// <summary> /// method for saving data to the database /// </summary> private void SaveExecute() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblPosition newPosition = new tblPosition(); newPosition.PositionName = position.PositionName; newPosition.PositionDescription = position.PositionDescription; newPosition.PositionID = position.PositionID; // saving data context.tblPositions.Add(newPosition); context.SaveChanges(); MessageBox.Show("The position created successfully."); // logging the action FileActions.FileActions.Instance.Adding(FileActions.FileActions.path, FileActions.FileActions.actions, "position", newPosition.PositionName); } addPosition.Close(); } catch (Exception) { MessageBox.Show("Wrong inputs. Please try again."); } }
private void SaveExecute() { try { using (CompanyDBEntities db = new CompanyDBEntities()) { tblUser user = db.tblUsers.Where(u => u.UserID == Admin.UserID).FirstOrDefault(); user.FirstName = Admin.FirstName; user.LastName = Admin.LastName; user.JMBG = Admin.JMBG; user.Gender = Gender.ToString(); user.Residence = Admin.Residence; user.MarriageStatus = Status; user.Username = Admin.Username; user.UserPassword = Admin.UserPassword; tblAdmin admin = db.tblAdmins.Where(a => a.AdminID == Admin.AdminID).FirstOrDefault(); admin.ExpirationDate = Admin.ExpirationDate; admin.AdminType = Type; db.SaveChanges(); } MessageBox.Show("Admin Updated Successfully!"); main.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public static (string username, Models.UserType type) SolveGUID(CompanyDBEntities _context, string guid) { var user = _context.Users.FirstOrDefault(x => x.Guid.Equals(guid)); if (user is null) { throw new SecurityException("Guid not found"); } return(user.Username, user.UserType); }
public static void Validate(CompanyDBEntities _context, Car car) { if (car.LicensePlate.Length < 4) { throw new ValidationException("Too short license plate"); } var user = _context.Users.FirstOrDefault(x => x.Username.Equals(car.Username)); if (user is null) { throw new ValidationException("User does not exist"); } }
/// <summary> /// method for checking username and password and opening the windows /// </summary> private void SaveExecute() { string adminType = AdminType(Username, UserPassword); if (username == "WPFMaster" && userPassword == "WPFAccess") { MasterView master = new MasterView(); master.ShowDialog(); } else if (adminType == "TEAM") { TeamAdminView team = new TeamAdminView(); team.ShowDialog(); } else if (adminType == "SYSTEM") { SystemAdminView system = new SystemAdminView(); system.ShowDialog(); } else if (adminType == "LOCAL") { LocalAdminView local = new LocalAdminView(); local.ShowDialog(); } else if (IsManager(username, userPassword)) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { // getting the manager for later actions with projects tblUser user = (from x in context.tblUsers where x.Username == username select x).First(); manager = (from y in context.tblManagers where y.UserID == user.UserID select y).First(); ManagerView managerView = new ManagerView(manager); managerView.ShowDialog(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } } else { MessageBox.Show("Wrong username or password, please try again."); } }
public vwAdmin FindAdmin(string username) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { vwAdmin admin = (from e in context.vwAdmins where e.Username == username select e).First(); return(admin); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public vwWorker FindEmployee(string username) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { vwWorker employee = (from e in context.vwWorkers where e.Username == username select e).First(); return(employee); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// method for getting all projects to the list /// </summary> /// <returns></returns> private List <tblProject> GetAllProjects() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { List <tblProject> list = new List <tblProject>(); list = (from x in context.tblProjects select x).ToList(); return(list); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
// Method that reads all Employees from database public List <vwWorker> GetAllEmployees() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { List <vwWorker> list = new List <vwWorker>(); list = (from x in context.vwWorkers select x).ToList(); return(list); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// Gets all information about positions /// </summary> /// <returns>a list of found positions</returns> public List <tblPosition> GetAllPosition() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { List <tblPosition> list = new List <tblPosition>(); list = (from x in context.tblPositions select x).ToList(); return(list); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
// Method that reads all Managers from database public List <vwManager> GetAllManagers() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { List <vwManager> list = new List <vwManager>(); list = (from x in context.vwManagers select x).ToList(); return(list); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public static LoginResultModel ValidateUserLogin(LoginModel userlogin) { var loginResult = new LoginResultModel(); try { var UserName = new SqlParameter { ParameterName = "UserName", Value = userlogin.UserName }; var Password = new SqlParameter { ParameterName = "Password", SqlDbType = SqlDbType.NVarChar, Value = Encrypt(userlogin.Password) }; using (var dbContext = new CompanyDBEntities()) { var results = dbContext .MultipleResults("[dbo].[PROC_ValidateUserLoginReport]") .With <LoginResultModel>() .With <CompanyModel>() .Execute(UserName, Password); if (results != null && results.Count > 0) { loginResult = ((List <LoginResultModel>)results[0]).SingleOrDefault(); if (loginResult != null) { if (loginResult.ResponseCode.Equals("00")) { loginResult.LstCompany = ((List <CompanyModel>)results[1]).ToList(); if (loginResult.LstCompany.Count > 0) { loginResult.DBName = loginResult.LstCompany.FirstOrDefault().DBName; loginResult.CompanyName = loginResult.LstCompany.FirstOrDefault().CompanyName; } } } } } } catch (Exception ex) { Common.LogError("Login", "ValidateUserLogin", "ValidateUserLogin", ex.Message.ToString(), ex.InnerException.Message.ToString(), "", ""); } return(loginResult); }
/// <summary> /// method for checking if user is manager /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> private bool IsManager(string username, string password) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblUser user = (from x in context.tblUsers where x.Username == username && x.UserPassword == password select x).First(); int id = user.UserID; tblManager manager = (from y in context.tblManagers where y.UserID == id select y).First(); return(true); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
private List <vwAdmin> GetAllAdmins() { List <vwAdmin> admins = new List <vwAdmin>(); try { using (CompanyDBEntities db = new CompanyDBEntities()) { admins = db.vwAdmins.Where(a => a.AdminID > 0).ToList(); return(admins); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(null); } }
/// <summary> /// method for checking which type is admin /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> private string AdminType(string username, string password) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblUser user = (from x in context.tblUsers where x.Username == username && x.UserPassword == password select x).First(); int id = user.UserID; tblAdmin admin = (from y in context.tblAdmins where y.UserID == id select y).First(); string type = admin.AdminType; return(type); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
/// <summary> /// Creates or edits an sector /// </summary> /// <param name="sector">the sector that is being added</param> /// <returns>a new or edited sector</returns> public tblSector AddSector(tblSector sector) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { if (sector.SectorID == 0) { tblSector newSector = new tblSector { SectorName = sector.SectorName, SectorDescription = sector.SectorDescription }; context.tblSectors.Add(newSector); context.SaveChanges(); sector.SectorID = newSector.SectorID; return(sector); } else { tblSector sectorToEdit = (from ss in context.tblSectors where ss.SectorID == sector.SectorID select ss).First(); sectorToEdit.SectorName = sector.SectorName; sectorToEdit.SectorName = sector.SectorName; sectorToEdit.SectorID = sector.SectorID; context.SaveChanges(); return(sector); } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
// Method that add Manager to database public void AddManager(vwManager manager) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblUser newUser = new tblUser(); tblManager newManager = new tblManager(); newUser.FirstName = manager.FirstName; newUser.LastName = manager.LastName; newUser.JMBG = manager.JMBG; newUser.Gender = manager.Gender; newUser.Residence = manager.Residence; newUser.MarriageStatus = manager.MarriageStatus; newUser.Username = manager.Username; newUser.UserPassword = SecurePasswordHasher.Hash(manager.UserPassword); context.tblUsers.Add(newUser); context.SaveChanges(); manager.UserID = newUser.UserID; newManager.UserID = manager.UserID; newManager.Email = manager.Email; newManager.ReservedPassword = manager.ReservedPassword + "WPF"; newManager.LevelOfResponsibility = manager.LevelOfResponsibility; newManager.SuccessfulProjects = manager.SuccessfulProjects; newManager.Salary = "1200"; newManager.OfficeNumber = manager.OfficeNumber; context.tblManagers.Add(newManager); context.SaveChanges(); manager.ManagerID = newManager.ManagerID; } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
// Method that add Employee to database public void AddEmployee(vwWorker employee) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblUser newUser = new tblUser(); tblWorker newEmployee = new tblWorker(); newUser.FirstName = employee.FirstName; newUser.LastName = employee.LastName; newUser.JMBG = employee.JMBG; newUser.Gender = employee.Gender; newUser.Residence = employee.Residence; newUser.MarriageStatus = employee.MarriageStatus; newUser.Username = employee.Username; newUser.UserPassword = SecurePasswordHasher.Hash(employee.UserPassword); context.tblUsers.Add(newUser); context.SaveChanges(); employee.UserID = newUser.UserID; newEmployee.UserID = employee.UserID; newEmployee.YearsOfService = employee.YearsOfService; newEmployee.EducationDegree = employee.EducationDegree; newEmployee.SectorID = 1; newEmployee.PositionID = employee.PositionID; newEmployee.Salary = "1200"; context.tblWorkers.Add(newEmployee); context.SaveChanges(); employee.WorkerID = newEmployee.WorkerID; } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
/// <summary> /// Search if user with that ID exists in the user table /// </summary> /// <param name="userID">Takes the user id that we want to search for</param> /// <returns>True if the user exists</returns> public bool IsUserID(int userID) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { int result = (from x in context.tblUsers where x.UserID == userID select x.UserID).FirstOrDefault(); if (result != 0) { return(true); } else { return(false); } } } catch (Exception ex) { Debug.WriteLine("Exception " + ex.Message.ToString()); return(false); } }
// Methot to check if Employee username exists in database public bool IsUser(string username) { try { using (CompanyDBEntities context = new CompanyDBEntities()) { vwWorker employee = (from e in context.vwWorkers where e.Username == username select e).First(); if (employee == null) { return(false); } else { return(true); } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// method for saving data to the database /// </summary> private void SaveExecute() { try { using (CompanyDBEntities context = new CompanyDBEntities()) { tblUser newUser = new tblUser(); tblAdmin newAdmin = new tblAdmin(); // inputs and validations if (user.FirstName.All(Char.IsLetter)) { newUser.FirstName = user.FirstName; } else { MessageBox.Show("Wrong First Name input, please try again."); } if (user.LastName.All(Char.IsLetter)) { newUser.LastName = user.LastName; } else { MessageBox.Show("Wrong Last Name input, please try again."); } newUser.JMBG = user.JMBG; // JMBG validation if (JmbgInputValidation(newUser.JMBG) == false) { MessageBox.Show("Wrong input, please check your JMBG (13 characters)."); } string sex = user.Gender.ToUpper(); // gender validation if ((sex == "M" || sex == "Z" || sex == "X" || sex == "N")) { newUser.Gender = sex; } else { MessageBox.Show("Wrong Gender input, please enter M, Z, X or N."); } user.UserID = newUser.UserID; newUser.Residence = user.Residence; string marriage = user.MarriageStatus.ToUpper(); if ((marriage == "MARRIED" || marriage == "UNMARRIED" || marriage == "DIVORCED")) { newUser.MarriageStatus = marriage; } else { MessageBox.Show("Wrong Marriage status input. Please try again.\n (Married/Unmarried/Divorced)"); } newUser.Username = user.Username; newUser.UserPassword = user.UserPassword; string adminType = admin.AdminType.ToUpper(); if ((adminType == "TEAM" || adminType == "SYSTEM" || adminType == "LOCAL")) { newAdmin.AdminType = adminType; } else { MessageBox.Show("Wrong Admin type input. Please try again.\n (Team/System/Local)"); } newAdmin.AdminID = admin.AdminID; newAdmin.ExpirationDate = DateTime.Now.AddDays(7); newAdmin.UserID = newUser.UserID; // saving data to the database context.tblUsers.Add(newUser); context.tblAdmins.Add(newAdmin); context.SaveChanges(); MessageBox.Show("The admin created successfully."); // logging the action FileActions.FileActions.Instance.Adding(FileActions.FileActions.path, FileActions.FileActions.actions, "user", newUser.FirstName + " " + newUser.LastName); FileActions.FileActions.Instance.Adding(FileActions.FileActions.path, FileActions.FileActions.actions, "admin", newUser.FirstName + " " + newUser.LastName); } masterView.Close(); } catch (Exception) { MessageBox.Show("Wrong inputs, please check your inputs or try again."); } }
public UserApi(CompanyDBEntities context) { _context = context; }
public VisitsApiController(CompanyDBEntities context) { _context = context; }
public GenericRepository(CompanyDBEntities context) { this.context = context; this.dbSet = context.Set <T>(); }
public IHttpActionResult Get() { CompanyDBEntities cb = new CompanyDBEntities(); return(Ok(cb.FetchAllDepartments())); }