/// <summary> /// sets rating of vacancyemployee (like / dislike) /// </summary> /// <returns></returns> public object setRating() { try { var headers = Request.Headers; int employeeID = (headers.Contains("employeeID")) ? Int32.Parse(headers.GetValues("employeeID").First()) : -1; int vacancyID = (headers.Contains("vacancyID")) ? Int32.Parse(headers.GetValues("vacancyID").First()) : -1; int rating = (headers.Contains("rating")) ? Int32.Parse(headers.GetValues("rating").First()) : -99; WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; VacancyEmployee vac = (from VacancyEmployee in wqdb.VacancyEmployees where VacancyEmployee.employeeID == employeeID && VacancyEmployee.vacancyID == vacancyID select VacancyEmployee).First(); vac.rating = rating; wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// int employeeID, int employerID, string text, string sender, string title /// </summary> public object sendMessage() { try { var headers = Request.Headers; int employeeID = (headers.Contains("employeeID")) ? Int32.Parse(headers.GetValues("employeeID").First()) : -1; int employerID = (headers.Contains("employerID")) ? Int32.Parse(headers.GetValues("employerID").First()) : -1; int vacancyID = (headers.Contains("vacancyID")) ? Int32.Parse(headers.GetValues("vacancyID").First()) : -1; string text = (headers.Contains("text")) ? headers.GetValues("text").First() : null; string sender = (headers.Contains("sender")) ? headers.GetValues("sender").First() : null; string title = (headers.Contains("title")) ? headers.GetValues("title").First() : null; WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Message msg = new Message() { employeeID = employeeID, employerID = employerID, sender = sender, text = text, title = title, date = DateTime.Now, vacancyID = vacancyID, read = false }; wqdb.Messages.Add(msg); wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// adds employer. Headers: username, email, password /// </summary> /// <returns></returns> public object addEmployer() { try { var headers = Request.Headers; string username = HttpUtility.UrlDecode((headers.Contains("username")) ? headers.GetValues("username").First() : null); string email = HttpUtility.UrlDecode((headers.Contains("email")) ? headers.GetValues("email").First() : null); string password = HttpUtility.UrlDecode((headers.Contains("password")) ? headers.GetValues("password").First() : null); WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Employer usernameCheck = null; Employer emailCheck = null; try { usernameCheck = wqdb.Employers.First(x => x.username == username); emailCheck = wqdb.Employers.First(x => x.email == email); } catch (Exception ex) { } if (usernameCheck == null && emailCheck == null) { Employer employer = new Employer() { username = username, email = email, password = password }; wqdb.Employers.Add(employer); wqdb.SaveChanges(); return(Json(new { Result = "successful", employer = employer })); } else { string errorString = ""; if (usernameCheck != null) { errorString += "De gebruikersnaam bestaat al"; } if (emailCheck != null) { errorString += "dit email adres wordt al gebruikt"; } return(Json(new { Result = "failed", Error = errorString })); } } catch (System.Exception ex) { Console.WriteLine(ex); return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// edit employer /// </summary> /// <returns></returns> public object editEmployer() { try { var headers = Request.Headers; int ID = (headers.Contains("ID")) ? Int32.Parse(headers.GetValues("ID").First()) : -1; string name = (headers.Contains("name")) ? headers.GetValues("name").First() : null; string description = (headers.Contains("description")) ? headers.GetValues("description").First() : null; int employeeCount = (headers.Contains("employeeCount")) ? Int32.Parse(headers.GetValues("employeeCount").First()) : -1; string location = (headers.Contains("location")) ? headers.GetValues("location").First() : null; string password = (headers.Contains("password")) ? headers.GetValues("password").First() : null; string oldPassword = (headers.Contains("oldPassword")) ? headers.GetValues("oldPassword").First() : null; string email = (headers.Contains("email")) ? headers.GetValues("email").First() : null; WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Employer emp = wqdb.Employers.First(x => x.ID == ID); emp.name = (name != null) ? name : emp.name; emp.description = (description != null) ? description : emp.description; emp.employeeCount = (employeeCount != -1) ? employeeCount : emp.employeeCount; emp.location = (location != null) ? location : emp.location; if (password != null && emp.password == oldPassword) { emp.password = password; } else if (emp.password != oldPassword) { return(Json(new { Result = "failed", Error = "Verkeerd oud wachtwoord wachtwoord ingevoerd, uw wijzigingen zijn niet opgeslagen" })); } emp.email = (email != null) ? email : emp.email; wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (System.Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// deletes vacancy /// </summary> /// <param name="ID">vacancy id</param> /// <returns></returns> public object deleteVacancy(int ID) { try { WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; wqdb.Vacancies.Remove(wqdb.Vacancies.First(x => x.ID == ID)); wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (System.Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// update seen to true, the like on the vacancy has been seen by the employer /// </summary> /// <param name="ID">matchID</param> public object reactionSeen(int ID) { try { WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; VacancyEmployee vaemp = (from VacancyEmployee in wqdb.VacancyEmployees where VacancyEmployee.matchID == ID select VacancyEmployee).First(); vaemp.seen = true; wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// update read to true /// </summary> /// <param name="ID">message ID</param> public object messageRead(int ID) { try { WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Message msg = (from Message in wqdb.Messages where Message.ID == ID select Message).First(); msg.read = true; wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// deletes employer /// </summary> /// <returns></returns> public object deleteEmployer() { try { var headers = Request.Headers; int ID = (headers.Contains("ID")) ? Int32.Parse(headers.GetValues("ID").First()) : -1; string password = (headers.Contains("password")) ? headers.GetValues("password").First() : null; WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Employer passwordCheck = null; try { passwordCheck = wqdb.Employers.First(x => x.ID == ID); } catch (Exception ex) { } if (passwordCheck != null) { if (passwordCheck.password == password) { wqdb.Employers.Remove(wqdb.Employers.First(x => x.ID == ID)); wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } else { return(Json(new { Result = "failed", Error = "Verkeerd wachtwoord" })); } } else { return(Json(new { Result = "failed", Error = "Deze user bestaat niet" })); } } catch (System.Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// Create new Vacancy /// </summary> /// <param name="employerID"></param> /// <param name="function"></param> /// <param name="description"></param> /// <param name="salary"></param> /// <param name="hours"></param> /// <param name="requirements"></param> /// <returns>json sucessfull or failed with error</returns> public object addVacancy(int employerID, string function, string description, int salary, int hours, string requirements) { try { WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Vacancy vacancy = new Vacancy() { employerID = employerID, jobfunction = function, description = description, salary = salary, hours = hours, requirements = requirements }; wqdb.Vacancies.Add(vacancy); wqdb.SaveChanges(); return(Json(new { Result = "successful" })); } catch (System.Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// edits employee /// </summary> /// <returns></returns> public object editEmployee() { try { var headers = Request.Headers; int ID = (headers.Contains("ID")) ? Int32.Parse(headers.GetValues("ID").First()) : -1; WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Employee emp = wqdb.Employees.First(x => x.ID == ID); string firstName = (headers.Contains("firstName")) ? headers.GetValues("firstName").First() : null; string lastName = (headers.Contains("lastName")) ? headers.GetValues("lastName").First() : null; string industry = (headers.Contains("industry")) ? headers.GetValues("industry").First() : null; string positions = (headers.Contains("positions")) ? headers.GetValues("positions").First() : null; string interests = (headers.Contains("interests")) ? headers.GetValues("interests").First() : null; string languages = (headers.Contains("languages")) ? headers.GetValues("languages").First() : null; string skills = (headers.Contains("skills")) ? headers.GetValues("skills").First() : null; string educations = (headers.Contains("educations")) ? headers.GetValues("educations").First() : null; string experience = (headers.Contains("experience")) ? headers.GetValues("experience").First() : null; // werkervaring if (headers.Contains("dob") && headers.GetValues("dob").First() != null) { DateTime?dob = DateTime.Parse(headers.GetValues("dob").First().ToString()); //return Json(new { Result = "lolz dob", troep = dob }); emp.dob = (dob != null) ? dob : emp.dob; } string location = (headers.Contains("city")) ? headers.GetValues("city").First() : null; if (headers.Contains("hours")) { int?hours = int.Parse(headers.GetValues("hours").First()); emp.hours = (hours != null) ? hours : emp.hours; } string password = (headers.Contains("password")) ? headers.GetValues("password").First() : null; string oldPassword = (headers.Contains("oldPassword")) ? headers.GetValues("oldPassword").First() : null; string email = (headers.Contains("email")) ? headers.GetValues("email").First() : null; emp.firstName = (firstName != null) ? firstName : emp.firstName; emp.lastName = (lastName != null) ? lastName : emp.lastName; emp.industry = (industry != null) ? industry : emp.industry; emp.positions = (positions != null) ? positions : emp.positions; emp.interests = (interests != null) ? interests : emp.interests; emp.languages = (languages != null) ? languages : emp.languages; emp.skills = (skills != null) ? skills : emp.skills; emp.educations = (educations != null) ? educations : emp.educations; emp.experience = (experience != null) ? experience : emp.experience; emp.location = (location != null) ? location : emp.location; emp.educations = (educations != null) ? educations : emp.educations; if (password != null && emp.password == oldPassword) { emp.password = password; } else if (emp.password != oldPassword) { return(Json(new { Result = "failed", Error = "Verkeerd oud wachtwoord wachtwoord ingevoerd, uw wijzigingen zijn niet opgeslagen" })); } emp.email = (email != null) ? email : emp.email; wqdb.SaveChanges(); return(Json(new { Result = "successful", User = emp })); } catch (System.Exception ex) { return(Json(new { Result = "failed", Error = ex })); } }
/// <summary> /// matching algorythm /// </summary> /// <param name="employeeID"></param> /// <param name="vacancyID"></param> private void setMatchScore(int employeeID, int vacancyID) { int bedrijfsScore = 0; WorQitEntities wqdb = new WorQitEntities(); wqdb.Configuration.ProxyCreationEnabled = false; Vacancy vacancy = wqdb.Vacancies.Where(x => x.ID == vacancyID).First(); Employee employee = wqdb.Employees.Where(x => x.ID == employeeID).First(); List <Vacancy> vacancies = wqdb.Vacancies.Where(x => x.employerID == vacancy.employerID).ToList(); foreach (Vacancy v in vacancies) { List <VacancyEmployee> vList = wqdb.VacancyEmployees.Where(x => x.vacancyID == v.ID).ToList(); foreach (VacancyEmployee ve in vList) { bedrijfsScore = ve.rating ?? default(int); } if (bedrijfsScore > -5) { int matchScore = 0; if (employee.industry != null) { if (v.branche.Contains(employee.industry)) { matchScore = matchScore + 10; } } if (employee.positions != null) { if (v.jobfunction.Contains(employee.positions)) { matchScore = matchScore + 5; } } if (employee.skills != null) { if (v.requirements.Contains(employee.skills)) { matchScore = matchScore + 7; } } if (employee.educations != null) { if (v.educations.Contains(employee.educations)) { matchScore = matchScore + 9; } } var ve = wqdb.VacancyEmployees.Where(x => x.employeeID == employee.ID).Where(x => x.vacancyID == v.ID).FirstOrDefault(); if (ve == null) { VacancyEmployee newVE = new VacancyEmployee() { employeeID = employee.ID, vacancyID = v.ID, matchingValue = matchScore, rating = 0 }; wqdb.VacancyEmployees.Add(newVE); wqdb.SaveChanges(); } else { ve.matchingValue = matchScore; } } } }