public HunterCV.Common.DocumentCollection Get(string id) { Guid gid = new Guid(id); HunterCV.Common.DocumentCollection result = new HunterCV.Common.DocumentCollection(); var documents = new List <HunterCV.Common.Resume>(); using (hunterCVEntities context = new hunterCVEntities()) { var cvs = context.Resumes .Where(p => p.CandidateID == gid); if (cvs.Any()) { cvs.Each(p => { documents.Add(new HunterCV.Common.Resume { ResumeID = p.ResumeID, FileName = p.FileName, Description = p.Description, CandidateID = p.CandidateID, IsCloudy = true }); }); } } result.Documents = documents; return(result); }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Post(HunterCV.Common.Position position) { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Single(u => u.UserName == userName); var role = context.Users.Single(uu => uu.UserName == userName) .Roles.Single(); if (role.LicenseType == "Free") { int count = context.Positions.Where(c => c.UserId == user.UserId).Count(); if (count >= 1) { throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("License"), ReasonPhrase = "This license type does not allow the operation" }); } } Position target = Mapper.Map <HunterCV.Common.Position, Position>(position); target.User = user; context.Positions.AddObject(target); context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Post(IEnumerable <HunterCV.Common.MailTemplate> templates) { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var role = context.Users.Single(user => user.UserName == userName) .Roles.Single(); var exists = context.MailTemplates.Where(t => t.RoleId == role.RoleId); foreach (MailTemplate tmpl in exists) { context.MailTemplates.DeleteObject(tmpl); } foreach (HunterCV.Common.MailTemplate tmpl in templates) { tmpl.RoleId = role.RoleId; MailTemplate target = Mapper.Map <HunterCV.Common.MailTemplate, MailTemplate>(tmpl); context.MailTemplates.AddObject(target); } context.SaveChanges(); } }
public ActionResult AddUser(AddUserModel model) { string userName = User.Identity.Name, roleName = null; if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { using (hunterCVEntities context = new hunterCVEntities()) { roleName = context.Users.Where(u => u.UserName == userName).Single().Roles.Single().RoleName; var user = context.Users.Single(u => u.UserName == model.UserName); user.ApplicationRole = model.ApplicationRole; context.SaveChanges(); } Roles.AddUserToRole(model.UserName, roleName); return(RedirectToAction("Manage", "Account")); } } // If we got this far, something failed, redisplay form return(RedirectToAction("Manage", "Account")); }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Delete(string id) { using (hunterCVEntities context = new hunterCVEntities()) { var candidate = context.Candidates.Where(c => c.CandidateID == new Guid(id)).FirstOrDefault(); context.Candidates.DeleteObject(candidate); context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Delete(Guid id) { using (hunterCVEntities context = new hunterCVEntities()) { var resume = context.Previews.Where(c => c.PreviewID == id).FirstOrDefault(); context.Previews.DeleteObject(resume); context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Delete(string id) { using (hunterCVEntities context = new hunterCVEntities()) { var position = context.Positions.Where(c => c.PositionId == new Guid(id)).FirstOrDefault(); context.Positions.DeleteObject(position); context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Delete(int id) { using (hunterCVEntities context = new hunterCVEntities()) { var resume = context.Resumes.Where(c => c.ResumeID == id).FirstOrDefault(); var resumeContent = context.ResumeContents.Where(c => c.ResumeID == id).FirstOrDefault(); context.Resumes.DeleteObject(resume); context.ResumeContents.DeleteObject(resumeContent); context.SaveChanges(); } }
public HttpResponseMessage Put(HunterCV.Common.Resume resume) { using (hunterCVEntities context = new hunterCVEntities()) { var entity = context.Resumes .Where(p => p.ResumeID == resume.ResumeID).FirstOrDefault(); entity.Description = resume.Description; context.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK)); }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Put(HunterCV.Common.CandidateStatus status) { string username = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var roleEntity = context.Users.Single(user => user.UserName == username) .Roles.Single(); roleEntity.CandidatesStatuses = status.Xml; context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerable <HunterCV.Common.Position> Get() { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var positions = context.Users.Single(user => user.UserName == userName) .Roles.Single().Users .SelectMany(p => p.Positions); return(positions.Select(p => Mapper.Map <Position, HunterCV.Common.Position>(p)).ToList()); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Put(HunterCV.Common.Area area) { string username = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var role = context.Users.Single(user => user.UserName == username) .Roles.Single(); role.CandidatesAreas = area.Xml; context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Put(HunterCV.Common.Settings settings) { string username = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var roleEntity = context.Users.Single(user => user.UserName == username) .Roles.Single(); roleEntity.Settings = settings.Xml; context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Delete(string id) { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Single(u => u.UserName == userName); var candidate = context.Candidates.Where(c => c.CandidateID == new Guid(id)).FirstOrDefault(); candidate.Starred = null; context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public void Post(HunterCV.Common.Candidate favorite) { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Single(u => u.UserName == userName); var candidate = context.Candidates.Single(c => c.CandidateID == favorite.CandidateID); candidate.Starred = favorite.Starred; context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public IEnumerable <HunterCV.Common.Candidate> Put(HunterCV.Common.Candidate candidate) { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var curruser = context.Users.Single(user => user.UserName == userName); if (!candidate.SkipDuplicatesCheck) { //check duplicates IEnumerable <Candidate> candidates = context.Candidates.Where(c => c.FirstName.ToLower().Trim() == candidate.FirstName.ToLower().Trim() && c.LastName.ToLower().Trim() == candidate.LastName.ToLower().Trim() && c.CandidateID != candidate.CandidateID); if (candidates.Any()) { return(candidates.Select(p => Mapper.Map <Candidate, HunterCV.Common.Candidate>(p)).ToList()); } } var entity = Mapper.Map <HunterCV.Common.Candidate, Candidate>(candidate); //delete old positions context.CandidatePositions.Where(c => c.CandidateId == candidate.CandidateID).Each(d => { context.CandidatePositions.DeleteObject(d); }); entity.UserId = curruser.UserId; context.Candidates.Attach(entity); context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); foreach (HunterCV.Common.CandidatePosition position in candidate.CandidatePositions) { entity.CandidatePositions.Add(new CandidatePosition { CandidateId = candidate.CandidateID, PositionId = position.PositionId, CandidatePositionDate = position.CandidatePositionDate, CandidatePositionStatus = position.CandidatePositionStatus }); } context.SaveChanges(); return(null); } }
public HttpResponseMessage GetContent(int id) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); using (hunterCVEntities context = new hunterCVEntities()) { var cvs = context.Resumes.Include("ResumeContent") .Where(p => p.ResumeID == id); if (cvs.Any()) { response.Content = new StreamContent(new MemoryStream(cvs.FirstOrDefault().ResumeContent.FileContent)); } } return(response); }
/// <summary> /// /// </summary> /// <param name="position"></param> public void Put(HunterCV.Common.Position position) { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var curruser = context.Users.Single(user => user.UserName == userName); var entity = Mapper.Map <HunterCV.Common.Position, Position>(position); entity.UserId = curruser.UserId; context.Positions.Attach(entity); context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); context.SaveChanges(); } }
public HttpResponseMessage GetContent(Guid id) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); using (hunterCVEntities context = new hunterCVEntities()) { var cvs = context.Previews .Where(p => p.PreviewID == id).FirstOrDefault(); if (cvs != null) { response.Content = new StreamContent(new MemoryStream(cvs.FileContent)); response.Content.Headers.ContentType = new MediaTypeHeaderValue(cvs.ContentType); } } return(response); }
public ActionResult Manage() { string userName = User.Identity.Name; var vm = new ManageAccountModel(); using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Where(u => u.UserName == userName).Single(); var role = user.Roles.SingleOrDefault(); ViewBag.ApplicationRole = user.ApplicationRole; if (role != null) { vm.Users = role.Users.ToList <User>(); } } return(View(vm)); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, false); using (hunterCVEntities context = new hunterCVEntities()) { var role = context.Users.Where(u => u.UserName == model.UserName).Single().Roles.SingleOrDefault(); if (role != null) { return(RedirectToAction("Manage", "Account")); } } return(RedirectToLocal(returnUrl)); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); if (requestContext.HttpContext.Request.IsAuthenticated) { string userName = User.Identity.Name; using (hunterCVEntities context = new hunterCVEntities()) { var role = context.Users.Where(u => u.UserName == userName).Single().Roles.SingleOrDefault(); if (role == null) { ViewBag.LicenseType = "None"; } else { ViewBag.LicenseType = role.LicenseType; } } } }
public HttpResponseMessage GetContent(int id) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); using (hunterCVEntities context = new hunterCVEntities()) { var cvs = context.Resumes.Include("ResumeContent") .Where(p => p.ResumeID == id); if (cvs.Any()) { response.Content = new StreamContent(new MemoryStream(cvs.FirstOrDefault().ResumeContent.FileContent)); string extension = new FileInfo(cvs.FirstOrDefault().FileName).Extension.ToLower(); string contentType = string.Empty; switch (extension) { case ".pdf": contentType = "application/pdf"; break; case ".doc": contentType = "application/msword"; break; case ".docx": contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; } response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); } } return(response); }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public Task <HttpResponseMessage> Post() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var streamProvider = new MultipartMemoryStreamProvider(); var query = Request.GetQueryNameValuePairs(); string candidateId = string.Empty; if (query != null) { var matches = query.Where(kv => kv.Key.ToLower() == "candidateid"); if (matches.Count() > 0) { candidateId = matches.First().Value; } } //Ensure.Argument.NotNull(commands, "commands"); // Read the form data and return an async task. var task = Request.Content.ReadAsMultipartAsync(streamProvider). ContinueWith <HttpResponseMessage>(t => { if (t.IsFaulted || t.IsCanceled) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception)); } if (string.IsNullOrEmpty(candidateId)) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Missing CandidateId parameter")); } //Select the appropriate content item this assumes only 1 part var fileContent = streamProvider.Contents.First(); string fileName = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty); Stream fileStream = fileContent.ReadAsStreamAsync().Result; var description = streamProvider.Contents.Last().ReadAsStringAsync().Result; using (hunterCVEntities context = new hunterCVEntities()) { Resume resume = new Resume(); resume.FileName = fileName; resume.Description = description; resume.CandidateID = new Guid(candidateId); context.AddToResumes(resume); context.SaveChanges(); ResumeContent content = new ResumeContent(); content.ResumeID = resume.ResumeID; content.FileContent = ReadAllBytes(fileStream); context.AddToResumeContents(content); context.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK)); }); return(task); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { if (Roles.RoleExists(model.Company)) { ModelState.AddModelError("", "Company name allready exists"); } else { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { Roles.CreateRole(model.Company); Roles.AddUserToRole(model.UserName, model.Company); using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Single(u => u.UserName == model.UserName); var role = context.Roles.Single(r => r.RoleName == model.Company); //admin user user.ApplicationRole = "A"; role.CandidatesCompanies = @"<?xml version=""1.0"" encoding=""utf-8""?><companies><company title=""Coca-Cola, Inc.""></company></companies>"; role.CandidatesAreas = @"<?xml version=""1.0"" encoding=""utf-8"" ?><areas><area title=""Security""></area><area title=""Management""></area><area title=""System""></area><area title=""BI""></area><area title=""Hardware""></area><area title=""QA""><area title=""Automation""></area><area title=""Manual""></area><area title=""Mobile""></area><area title=""Security""></area><area title=""Finance""></area></area><area title=""Developing""><area title=""JAVA""></area><area title=""WEB""></area><area title=""C""></area><area title=""C++""></area></area><area title=""Sales""></area><area title=""Administrator""></area><area title=""IT""></area><area title=""ERP""></area><area title=""Product""></area><area title=""Algorithem""></area><area title=""Embedded""></area><area title=""Electricity Engeneering""></area><area title=""Industrial Management""></area><area title=""Support""></area><area title=""Media""></area><area title=""Analist""></area><area title=""Internet""></area><area title=""UX/UI""></area><area title=""Marketing""></area><area title=""PMO""></area></areas>"; role.CandidatesStatuses = @"<?xml version=""1.0"" encoding=""utf-8""?><statuses> <status title=""Classification""></status> <status title=""Interview Process""> </status> <status title=""Before Contract Signing""> </status> <status title=""Signed""></status></statuses>"; role.CandidatesRoles = @"<?xml version=""1.0"" encoding=""utf-8""?>" + @"<roles>" + @"<role title=""Team Leader""/>" + @"<role title=""Manager""/>" + @"<role title=""Director""/>" + @"<role title=""VP""/>" + @"<role title=""Programmer""/>" + @"<role title=""Junior Programmer""/>" + @"<role title=""Junior QA""/>" + @"<role title=""Student""/>" + @"<role title=""QA""/>" + @"</roles>"; role.PositionsStatuses = @"<?xml version=""1.0"" encoding=""utf-8"" ?><statuses><status title=""Open""></status><status title=""Before Contract Signing""></status><status title=""Manned""></status></statuses>"; role.Settings = @"<?xml version=""1.0"" encoding=""utf-8"" ?><settings><setting title=""PositionsStartIndex"" value=""100"" /><setting title=""CandidatesStartIndex"" value=""1600"" /><setting title=""PhoneFormat"" value=""(999) 000-0000"" /><setting title=""MobileFormat"" value=""(999) 000-0000"" /><setting title=""MSWordPhone2WildCards"" value=""[0-9]{3}-[0-9]{7}"" /><setting title=""MSWordPhone1WildCards"" value=""[0-9]{2}-[0-9]{7}"" /><setting title=""MSWordMobile2WildCards"" value=""[0-9][5][0-9][0-9]{7}"" /><setting title=""MSWordMobile1WildCards"" value=""[0-9][5][0-9]-[0-9]{7}"" /></settings>"; role.LicenseType = "Free"; context.SaveChanges(); } FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return(RedirectToAction("Download", "Subscription")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } } // If we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public Task <HttpResponseMessage> Post() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var streamProvider = new MultipartMemoryStreamProvider(); var query = Request.GetQueryNameValuePairs(); Guid previewId = Guid.Empty; if (query != null) { var matches = query.Where(kv => kv.Key.ToLower() == "previewid"); if (matches.Count() > 0) { previewId = new Guid(matches.First().Value); } } //Ensure.Argument.NotNull(commands, "commands"); // Read the form data and return an async task. var task = Request.Content.ReadAsMultipartAsync(streamProvider). ContinueWith <HttpResponseMessage>(t => { if (t.IsFaulted || t.IsCanceled) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception)); } //Select the appropriate content item this assumes only 1 part var fileContent = streamProvider.Contents.First(); string fileName = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty); Stream fileStream = fileContent.ReadAsStreamAsync().Result; string extension = new FileInfo(fileName).Extension.ToLower(); string contentType = string.Empty; switch (extension) { case ".pdf": contentType = "application/pdf"; break; case ".doc": contentType = "application/msword"; break; case ".docx": contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; } var description = streamProvider.Contents.Last().ReadAsStringAsync().Result; using (hunterCVEntities context = new hunterCVEntities()) { Preview preview = new Preview(); preview.PreviewID = previewId; preview.FileName = fileName; preview.ContentType = contentType; preview.FileContent = ReadAllBytes(fileStream); context.AddToPreviews(preview); context.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK)); }); return(task); }
/// <summary> /// /// </summary> /// <returns></returns> public HunterCV.Common.UserData Get() { string userName = Membership.GetUser().UserName; using (hunterCVEntities context = new hunterCVEntities()) { var positions = context.Users.Single(user => user.UserName == userName) .Roles.Single().Users .SelectMany(p => p.Positions); var role = context.Users.Single(user => user.UserName == userName) .Roles.Single(); var users = new Dictionary <string, string>(); users.Add("", ""); role.Users.Each((u) => { users.Add(u.UserId.ToString(), u.UserName); }); var templates = role.MailTemplates; var areas = role.CandidatesAreas; var companies = role.CandidatesCompanies; var roles = role.CandidatesRoles; var candidateStatuses = role.CandidatesStatuses; var positionsStatuses = role.PositionsStatuses; var settings = role.Settings; Guid licenseGuid = Guid.Empty; switch (role.LicenseType) { case "Free": licenseGuid = Common.Role.FreeLicenseGuid; break; case "Standard": licenseGuid = Common.Role.StandardLicenseGuid; break; case "Premium": licenseGuid = Common.Role.PremiumLicenseGuid; break; } return(new HunterCV.Common.UserData { license = licenseGuid, roleId = role.RoleId, positions = positions.Select(p => Mapper.Map <Position, HunterCV.Common.Position>(p)).ToList(), areas = areas, companies = companies, roles = roles, candidatesStatuses = candidateStatuses, positionsStatuses = positionsStatuses, templates = templates.Select(p => Mapper.Map <MailTemplate, HunterCV.Common.MailTemplate>(p)).ToList(), settings = settings, users = users }); } }
/// <summary> /// Gets candidates /// </summary> /// <param name="request"></param> /// <returns></returns> public HunterCV.Common.CandidatesApiResponse Get([FromUri] HunterCV.Common.CandidatesApiRequest request) { string userName = Membership.GetUser().UserName; request.PageSize = request.PageSize == 0 ? 5 : request.PageSize; HunterCV.Common.CandidatesApiResponse response = new Common.CandidatesApiResponse(); using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Single(u => u.UserName == userName); var candidates = user.Roles.Single().Users .SelectMany(p => p.Candidates); var m_filteredCandidates = (from l in candidates select l); //name if (!string.IsNullOrEmpty(request.FilterFullName)) { string[] segments = request.FilterFullName.Split(' '); foreach (string s in segments) { m_filteredCandidates = m_filteredCandidates.Where(a => a.FirstName.ToLower().Contains(request.FilterFullName.ToLower()) || a.LastName.ToLower().Contains(request.FilterFullName.ToLower())); } } //starred var selectedStarred = new List <string>(); if (request.FilterStarredGold) { selectedStarred.Add("Gold"); } if (request.FilterStarredRed) { selectedStarred.Add("Red"); } if (request.FilterStarredBlue) { selectedStarred.Add("Blue"); } if (selectedStarred.Count() > 0) { m_filteredCandidates = m_filteredCandidates.Where(a => selectedStarred.Contains(a.Starred)); } //created by if (!string.IsNullOrEmpty(request.FilterCreatedBy)) { Guid guid = new Guid(request.FilterCreatedBy); m_filteredCandidates = m_filteredCandidates.Where(a => a.UserId == guid); } //areas if (!string.IsNullOrEmpty(request.FilterAreas)) { IEnumerable <String> areas = request.FilterAreas.Split(',').ToList(); if (areas.Count() > 0) { m_filteredCandidates = m_filteredCandidates.Where(p => areas.Contains(p.Areas)); } } if (!string.IsNullOrEmpty(request.FilterRole)) { m_filteredCandidates = m_filteredCandidates.Where(a => a.Roles == request.FilterRole); } if (!string.IsNullOrEmpty(request.FilterStatus)) { m_filteredCandidates = m_filteredCandidates.Where(a => a.Status == request.FilterStatus); } if (!string.IsNullOrEmpty(request.FilterMailEntryId)) { m_filteredCandidates = m_filteredCandidates.Where(a => a.MailEntryID == request.FilterMailEntryId); } if (request.FilterCandidateNumber.HasValue) { m_filteredCandidates = m_filteredCandidates.Where(a => a.CandidateNumber.Value == request.FilterCandidateNumber); } if (request.FilterRegistrationStartDate.HasValue && request.FilterRegistrationEndDate.HasValue) { DateTime start = new DateTime(request.FilterRegistrationStartDate.Value); DateTime end = new DateTime(request.FilterRegistrationEndDate.Value); m_filteredCandidates = m_filteredCandidates.Where(a => a.RegistrationDate.Value >= start && a.RegistrationDate.Value <= end); } response.TotalRows = m_filteredCandidates.Count(); response.TotalPages = response.TotalRows / request.PageSize + (response.TotalRows % request.PageSize > 0 ? 1 : 0); //Sorting if (request.SortField == "Starred") { if (request.SortType == 1) { m_filteredCandidates = m_filteredCandidates.OrderByDescending(p => p.Starred); } else { m_filteredCandidates = m_filteredCandidates.OrderBy(p => p.Starred); } } if (request.SortField == "CandidateNumber") { if (request.SortType == 1) { m_filteredCandidates = m_filteredCandidates.OrderByDescending(p => p.CandidateNumber); } else { m_filteredCandidates = m_filteredCandidates.OrderBy(p => p.CandidateNumber); } } if (request.SortField == "RegistrationDate") { if (request.SortType == 1) { m_filteredCandidates = m_filteredCandidates.OrderByDescending(p => p.RegistrationDate); } else { m_filteredCandidates = m_filteredCandidates.OrderBy(p => p.RegistrationDate); } } if (request.SortField == "FirstName") { if (request.SortType == 1) { m_filteredCandidates = m_filteredCandidates.OrderByDescending(p => p.FirstName); } else { m_filteredCandidates = m_filteredCandidates.OrderBy(p => p.FirstName); } } if (request.SortField == "LastName") { if (request.SortType == 1) { m_filteredCandidates = m_filteredCandidates.OrderByDescending(p => p.LastName); } else { m_filteredCandidates = m_filteredCandidates.OrderBy(p => p.LastName); } } if (request.SortField == "Experience") { if (request.SortType == 1) { m_filteredCandidates = m_filteredCandidates.OrderByDescending(p => p.Experience); } else { m_filteredCandidates = m_filteredCandidates.OrderBy(p => p.Experience); } } response.Candidates = m_filteredCandidates .Skip(request.PageSize * request.PageNumber) .Take(request.PageSize) .Select(p => Mapper.Map <Candidate, HunterCV.Common.Candidate>(p)).ToList(); } return(response); }
/// <summary> /// /// </summary> /// <param name="candidate"></param> public HunterCV.Common.PostCandidateApiResponse Post(HunterCV.Common.Candidate candidate) { string userName = Membership.GetUser().UserName; var response = new HunterCV.Common.PostCandidateApiResponse(); using (hunterCVEntities context = new hunterCVEntities()) { var user = context.Users.Single(u => u.UserName == userName); var role = context.Users.Single(u => u.UserName == userName) .Roles.Single(); if (role.LicenseType == "Free") { int count = context.Candidates.Where(c => c.UserId == user.UserId).Count(); if (count >= 10) { throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("License"), ReasonPhrase = "This license type does not allow the operation" }); } } if (!candidate.SkipDuplicatesCheck) { //check duplicates IEnumerable <Candidate> candidates = context.Candidates.Where(c => c.FirstName.ToLower().Trim() == candidate.FirstName.ToLower().Trim() && c.LastName.ToLower().Trim() == candidate.LastName.ToLower().Trim()); if (candidates.Any()) { response.Duplicates = candidates.Select(p => Mapper.Map <Candidate, HunterCV.Common.Candidate>(p)).ToList(); return(response); } } int startIndex = 1000; //get start index var docSettings = XDocument.Parse(role.Settings); var elementsSettings = docSettings.Root.Elements(); XElement startIndexElement = (from el in docSettings.Root.Elements("setting") where (string)el.Attribute("title") == "CandidatesStartIndex" select el).FirstOrDefault(); if (startIndexElement != null) { startIndex = (int)startIndexElement.Attribute("value"); } if (context.Candidates.Any()) { startIndex = context.Candidates.Max(c => c.CandidateNumber).Value + 1; } candidate.CandidateNumber = startIndex; response.NewCandidate = candidate; Candidate target = Mapper.Map <HunterCV.Common.Candidate, Candidate>(candidate); target.User = user; context.Candidates.AddObject(target); //check favorite //if (candidate.IsFavorite) //{ // target.FavoriteUsers.Add(user); //} context.SaveChanges(); return(response); } }