public ViewResult UpdateProfile(FormCollection collection) { int EmployeeID = Session["EmployeeID"] == null ? 0 : Convert.ToInt32(Session["EmployeeID"]); using (JobRepoDataContext Context = new JobRepoDataContext()) { Employee emp = Context.Employees .FirstOrDefault(e => e.EmployeeID == EmployeeID); if (emp != null) { try { UpdateModel(emp, new String[] { "FirstName", "LastName", "Phone", "Email", "JobTitle" } , collection); if (ModelState.IsValid) { Context.SaveChanges(); } } catch { } } return(View(emp)); } }
public KeywordsPopularityDto GetKeywordsPopularity(string Keyword) { //Keyword = System.Uri.UnescapeDataString(Keyword); Keyword = Keyword.Replace("[Keyword]", "."); using (JobRepoDataContext context = new JobRepoDataContext()) { /* * LINQ to Entity does not support ToString() when we need Count = pop.Count.ToString() * to fix this problem we need to get data as Objct (var tempobject) and LINQ to Object * support Tostring() */ var tempobject = from pop in context.KeywordPopularities .Where(e => e.Keyword.Equals(Keyword)) select new { Keyword = pop.Keyword, Count = pop.Count }; IEnumerable <KeywordsPopularityDto> popJson = (from pop in tempobject.AsEnumerable() select new KeywordsPopularityDto { Keyword = pop.Keyword, Count = pop.Count.ToString() }).ToList(); return(popJson.FirstOrDefault()); } }
public ActionResult ManageResumes() { /* * We can use TempData[] rather than Session[] ,The difference between this two is that the TempData * object will be deleted from the session when it is read. TempData is just a wrapper of the session. */ // List<Resume> res = null; List <ResumeDTO> res = null; int EmployeeID = Session["EmployeeID"] == null ? 0 : Convert.ToInt32(Session["EmployeeID"]); if (EmployeeID > 0) { using (JobRepoDataContext Context = new JobRepoDataContext()) { res = (from r in Context.Resumes.Where(e => e.EmployeeID == EmployeeID) select new ResumeDTO { Description = r.Description, employeeID = r.EmployeeID, Keywords = r.Keywords, PostedDate = r.PostedDate, resumeID = r.ResumeID, Title = r.Title }).ToList(); // res = Context.Resume.Where(e => e.EmployeeID == EmployeeID).ToList(); return(View(res)); } } return(View(res)); }
public void SetAsPopular(string Keyword) { using (JobRepoDataContext Context = new JobRepoDataContext()) { Context.SetKeywordsPopularity(Keyword); } }
public ActionResult UploadResume(FileModel model) { int EmployeeID = Session["EmployeeID"] == null ? 0 : Convert.ToInt32(Session["EmployeeID"]); if (EmployeeID > 0 && ModelState.IsValid) { byte[] uploadedfile = new byte[model.File.ContentLength]; if (uploadedfile.Length > 0) { HttpPostedFileBase file = model.File; file.InputStream.Read(uploadedfile, 0, (int)model.File.ContentLength); using (JobRepoDataContext Context = new JobRepoDataContext()) { Resume entity = new Resume() { Title = model.Title, PostedDate = DateTime.Now, Description = uploadedfile, Keywords = model.Keywords, EmployeeID = EmployeeID }; Context.Resumes.AddObject(entity); Context.SaveChanges(); } } return(RedirectToAction("ManageResumes")); } return(View()); }
public ActionResult DeleteResume(int id) { using (JobRepoDataContext Context = new JobRepoDataContext()) { var resume = Context.Resumes.Where(e => e.ResumeID == id).First(); Context.DeleteObject(resume); Context.SaveChanges(); } return(RedirectToAction("ManageResumes")); }
public static List <string> SearchLocations(string prefixText, int count) { List <string> cities = null; using (JobRepoDataContext context = new JobRepoDataContext()) { cities = context.Cities.Where(e => e.CityName.Contains(prefixText)) .Select(e => e.CityName).ToList(); } return(cities); }
public JsonResult Keywords() { object Keywords = null; using (JobRepoDataContext Context = new JobRepoDataContext()) { Keywords = (from i in Context.KeywordPopularities.Select(e => e.Keyword).Distinct() select new { ID = i, Name = i }).ToList(); } return(Json(Keywords, JsonRequestBehavior.AllowGet)); }
public List <KeywordPopularityDTO> KeywordCount(string Keyword) { List <KeywordPopularityDTO> res = null; using (JobRepoDataContext Context = new JobRepoDataContext()) { res = (from i in Context.KeywordPopularities.Where(e => e.Keyword.Contains(Keyword)) select new KeywordPopularityDTO { Keyword = i.Keyword, Count = i.Count }) .ToList(); } return(res); }
public List <KeywordsPopularityDto> GetKeywordsPopularityAsJSONV2() { using (JobRepoDataContext context = new JobRepoDataContext()) { IEnumerable <KeywordsPopularityDto> popJson = from pop in context.KeywordPopularities .OrderBy(e => e.Keyword) select new KeywordsPopularityDto { Keyword = pop.Keyword, Count = pop.Count + "" }; return(popJson.ToList()); } }
public string SelectEmployee(int employeeID) { int employerID = Session["EmployerID"] == null ? 0 : Convert.ToInt32(Session["EmployerID"]); using (JobRepoDataContext Context = new JobRepoDataContext()) { Thread.Sleep(300); // added for test purpose Context.SelectedEmployees.AddObject( new SelectedEmployee() { EmployeeID = employeeID, EmployerID = employerID }); Context.SaveChanges(); } return("The employee has been added to your selected List"); }
public void ProcessRequest(HttpContext context) { string ImageType = string.Empty; using (JobRepoDataContext ctx = new JobRepoDataContext()) { String EEE = context.Request.QueryString["employerid"]; int employerid = Convert.ToInt32(context.Request.QueryString["employerid"]); Employer emp = ctx.Employers.FirstOrDefault(e => e.EmployerID == employerid); if (emp != null && emp.Logo != null) { //context.Response.ContentType ="jpg"; context.Response.BinaryWrite(emp.Logo); } } }
public string GetKeywordsPopularityAsJSONV1() { using (JobRepoDataContext context = new JobRepoDataContext()) { //IEnumerable<KeywordPopularity> popJson = from pop in context.KeywordPopularities // select pop; //DataContractJsonSerializer ser = // new DataContractJsonSerializer(typeof(IEnumerable<KeywordPopularity>)); /* * You cannot return an IEnumerable of type KeywordPopularity because * EF entities cannot be serialized by default and we must add code generation to them * so instead of returning an ADO.NET entity , we can do one of the following solutions: * 1 - Create a DTO object which is decorated either by Attribute [DataContract] or [Serializable] can fixed out problem as we will have a Serializable object * 2 - Using the second GetKeywordsPopularityAsJSONV2 * * But if you still want to know how to create Serializable entities please see * http://msdn.microsoft.com/en-us/library/ff407090.aspx * */ IEnumerable <KeywordsPopularityDto> popJson = from pop in context.KeywordPopularities .OrderBy(e => e.Keyword) select new KeywordsPopularityDto { Keyword = pop.Keyword, Count = pop.Count + "" }; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(IEnumerable <KeywordsPopularityDto>)); MemoryStream ms = new MemoryStream(); ser.WriteObject(ms, popJson); string json = Encoding.Default.GetString(ms.ToArray()); ms.Close(); //HttpContext.Current.Response // Response WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return(json); } }
// // GET: /SelectedEmployee/ //[Authorize] public ActionResult List(string keyword = "") { if (keyword == "error") { throw new HttpException("invalid data has been entered!"); } else { string[] filters = keyword.Split(';'); List <Employee> emps = null; int EmployerID = Session["EmployerID"] == null ? 0 : Convert.ToInt32(Session["EmployerID"]); using (JobRepoDataContext Context = new JobRepoDataContext()) { if (keyword != "") { emps = (from sel in Context.SelectedEmployees.Where(e => e.EmployerID == EmployerID) join emp in Context.Employees on sel.EmployeeID equals emp.EmployeeID join res in Context.Resumes.Where(p => filters.Any(x => p.Keywords.Contains(x))) on emp.EmployeeID equals res.EmployeeID select emp).Distinct().ToList(); } else { emps = (from sel in Context.SelectedEmployees.Where(e => e.EmployerID == EmployerID) join emp in Context.Employees on sel.EmployeeID equals emp.EmployeeID join res in Context.Resumes on emp.EmployeeID equals res.EmployeeID select emp).Distinct().ToList(); } if (Request.IsAjaxRequest()) { return(PartialView("_AjaxEnabledSelectedEmployee", emps)); } return(View("List", emps)); } } }
public bool IsValidUserName(string username) { bool isvalid = false; if (username != "" && username.Length >= Membership.MinRequiredPasswordLength) { using (JobRepoDataContext context = new JobRepoDataContext()) { var query = from MembershipUser user in Membership.GetAllUsers() //Notice that you cannot user Lambda where .Where ( e => e. ....) //instead , you need to use by LINQ Where operator: where user..... where user.UserName.ToUpper().Equals(username.ToUpper()) select user; //IQueryable is not serializable so if we need to return the result , //it should be returned as list : query.ToList(); isvalid = (query.Count() == 0); } } return(isvalid); }
public XElement GetKeywordsPopularity() { XElement popXml = null; using (JobRepoDataContext context = new JobRepoDataContext()) { //popXml = new //XElement("KeywordPopularities", from pop in context.KeywordPopularities // select new // XElement("KeywordPopularities", // new XElement("Keyword", pop.Keyword), // new XElement("Count", pop.Count + "") // )); /* * The aobve code does not work becuase We're using an XElement constructor that takes parameters * in our "select" clause. Since XElement doesn't have a parameterless constructor, * we might need to change your code to select an anonymous type, * and initialize the XElement collection after the fact so * we should do the EF query first, and then calling ToList() on it * so that I can select the XElement collection using Linq to Objects rather than EF * http://stackoverflow.com/questions/3464035/what-does-the-parameterless-constructors-and-initializers-are-supported * */ var els = from pop in context.KeywordPopularities .OrderBy(e => e.Keyword) select new { pop.Keyword, pop.Count }; popXml = new XElement("KeywordPopularities", els.ToList() .Select(e => new XElement("KeywordPopularity", new XElement("Keyword", e.Keyword), new XElement("Count", e.Count + "") ))); } return(popXml); }
public ActionResult CreateProfile( [Bind(Include = "FirstName,LastName,Phone,Email,JobTitle,UserName,Password,Question1,Answer1,Question2,Answer2", Exclude = "UserID")] EmployeeDTO emp) { if (String.IsNullOrEmpty(emp.UserName)) { ModelState.AddModelError("UserName", "UserName cannot be empty"); } if (String.IsNullOrEmpty(emp.Password)) { ModelState.AddModelError("Password", "Password cannot be empty"); } if (String.IsNullOrEmpty(emp.Question1)) { ModelState.AddModelError("Question1", "Question1 cannot be empty"); } if (String.IsNullOrEmpty(emp.Answer1)) { ModelState.AddModelError("Answer1", "Answer1 cannot be empty"); } if (String.IsNullOrEmpty(emp.Question2)) { ModelState.AddModelError("Question2", "Question2 cannot be empty"); } if (String.IsNullOrEmpty(emp.Answer2)) { ModelState.AddModelError("Answer2", "Answer2 cannot be empty"); } if (String.IsNullOrEmpty(emp.FirstName)) { ModelState.AddModelError("FirstName", "FirstName cannot be empty"); } if (String.IsNullOrEmpty(emp.LastName)) { ModelState.AddModelError("LastName", "LastName cannot be empty"); } if (String.IsNullOrEmpty(emp.Phone)) { ModelState.AddModelError("Phone", "Phone cannot be empty"); } if (String.IsNullOrEmpty(emp.Email)) { ModelState.AddModelError("Email", "Email cannot be empty"); } if (String.IsNullOrEmpty(emp.JobTitle)) { ModelState.AddModelError("JobTitle", "JobTitle cannot be empty"); } if (ModelState.IsValid) { if (Common.CreateUser(emp.UserName, emp.Password, emp.Email, emp.Question1, emp.Answer1, emp.Question2, emp.Answer2)) { using (JobRepoDataContext Context = new JobRepoDataContext()) { Employee employee = new Employee() { Email = emp.Email, FirstName = emp.FirstName, LastName = emp.LastName, JobTitle = emp.JobTitle, Phone = emp.Phone, UserID = Guid.Parse(Session["UserID"].ToString()) }; Context.Employees.AddObject(employee); Context.SaveChanges(); Session["EmployeeID"] = employee.EmployeeID; return(RedirectToAction("UpdateProfile")); } } } return(View()); }