public async Task <ServiceResponse <IEnumerable <CountryView> > > GetAllCountries() { var response = new ServiceResponse <IEnumerable <CountryView> >(); try { response.Data = await(from x in _context.Countries join y in _context.Users on x.createdBy equals y.id join z in _context.Users on x.modifiedBy equals z.id into modifies from z in modifies.DefaultIfEmpty() select new CountryView() { Code = x.Code, modifiedBy = x.modifiedBy, createdBy = x.createdBy, createdByName = Common.GetFullName(y), createdDate = x.createdDate, Id = x.Id, modifiedByName = Common.GetFullName(z), modifiedDate = x.modifiedDate, Name = x.Name }).AsQueryable().ToListAsync(); response.Success = true; response.Message = "Data Retrived"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <int> > PutRecruitCare(int id, RecruitCare recruitCare) { var response = new ServiceResponse <int>(); try { if (recruitCare == null || recruitCare.id <= 0 || id != recruitCare.id) { response.Message = "Invalid item , Please correct and try again"; response.Success = false; return(response); } var item = _context.RecruitCare.Find(id); recruitCare.modifiedDate = DateTime.UtcNow; _context.Entry(item).CurrentValues.SetValues(recruitCare); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Recruitcare item updated successfully"; response.Data = recruitCare.id; } catch (Exception ex) { response.Message = await CustomLog.Log(ex, _context); response.Success = false; } return(response); }
public async Task <ServiceResponse <bool> > DeleteMasterDataType(int id) { var response = new ServiceResponse <bool>(); try { var masterData = await _context.MasterData.FindAsync(id); if (masterData == null) { response.Success = false; response.Message = "Invalid master data type"; return(response); } _context.MasterData.Remove(masterData); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Master data type deleted successfully"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <bool> > SendEmail(EmailModel[] emailModel) { var response = new ServiceResponse <bool>(); try { if (emailModel == null) { response.Message = "Invalid item , Please correct and try again"; response.Success = false; return(response); } var list = new List <EmailResponse>(); foreach (var item in emailModel.Select(x => x.key).Distinct()) { list.Add(new EmailResponse(item, Email.SendEmail(emailModel.Where(x => x.key == item).Select(x => x.value).ToList(), string.Format("Job Info {0}", item), item, _context, _configuration))); } response.Success = list.Any(x => x.status); response.Message = list.Any(x => x.status) ? "Email Sent Successfully" : "Unable to send emails for jobs " + string.Join(",", list.Select(x => x.key)); response.Data = true; } catch (Exception ex) { response.Message = await CustomLog.Log(ex, _context); response.Success = false; } return(response); }
public async Task <ServiceResponse <IList <DropdownModel> > > GetJobs() { var response = new ServiceResponse <IList <DropdownModel> >(); try { var user = _context.Users.Find(LoggedInUser); response.Data = await(from x in _context.Openings join c in _context.Countries on x.country equals c.Id where user.roleId == (int)Roles.SuperAdmin || x.country == user.country select new DropdownModel() { id = x.id, name = x.jobid + " - " + x.jobtitle, key = c.Code }).AsQueryable().ToListAsync(); response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ActionResult <ServiceResponse <IList <DropdownModel> > > > GetStatesByJobId(int id, bool includeDefaults) { var response = new ServiceResponse <IList <DropdownModel> >(); try { response.Data = await(from x in _context.State join j in _context.Openings on x.Country equals j.country where j.id == id select new DropdownModel() { id = x.Id, name = x.Name }).AsQueryable().ToListAsync(); if (!includeDefaults) { response.Data = response.Data.Where(x => x.name.ToLower() != "yet to grap").ToList(); } response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(Ok(response)); }
public async Task <ServiceResponse <IEnumerable <ClientCodesView> > > GetAllClientCodes() { var response = new ServiceResponse <IEnumerable <ClientCodesView> >(); try { response.Data = await(from x in _context.ClientCodes join c in _context.Users on x.createdBy equals c.id join m in _context.Users on x.modifiedBy equals m.id into modifies from m in modifies.DefaultIfEmpty() select new ClientCodesView() { Code = x.Code, createdBy = x.createdBy, createdByName = Common.GetFullName(c), createdDate = x.createdDate, Id = x.Id, modifiedBy = x.modifiedBy, ModifiedByName = Common.GetFullName(m), modifiedDate = x.modifiedDate, Name = x.Name, url = x.url }).ToListAsync(); response.Success = true; response.Message = "Data Retrived"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ActionResult <ServiceResponse <bool> > > PostOpenings(Openings openings) { var response = new ServiceResponse <bool>(); try { if (openings == null) { response.Success = false; response.Message = "Invalid Response , Please check"; return(Ok(response)); } openings.createdBy = LoggedInUser; openings.createdDate = DateTime.UtcNow; _context.Openings.Add(openings); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Job Opening added successfully"; response.Data = true; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(Ok(response)); }
public async Task <ServiceResponse <List <UserList> > > GetUsersByCountry() { var response = new ServiceResponse <List <UserList> >(); try { response.Data = await(from x in _context.Users select new UserList { id = x.id, name = Common.GetFullName(x), country = x.country }).AsQueryable().ToListAsync(); response.Message = "Users List"; response.Success = true; } catch (Exception ex) { response.Message = await CustomLog.Log(ex, _context); response.Success = false; } return(response); }
public async Task <ServiceResponse <bool> > DeleteRecruitCare(int id) { var response = new ServiceResponse <bool>(); try { var recruitCare = await _context.RecruitCare.FindAsync(id); if (recruitCare == null) { response.Message = "Recruit Care Not Found"; response.Success = false; } _context.RecruitCare.Remove(recruitCare); await _context.SaveChangesAsync(); response.Message = "Candidate Removed Successfully"; response.Success = true; } catch (Exception ex) { response.Message = await CustomLog.Log(ex, _context); response.Success = false; } return(response); }
public async Task <ServiceResponse <bool> > Logout(string id) { var response = new ServiceResponse <bool>(); try { var session = _context.UserSession.Find(id); if (session == null) { response.Message = "Invalid session"; response.Success = false; return(response); } session.outTime = DateTime.UtcNow; _context.Entry(session).CurrentValues.SetValues(session); await _context.SaveChangesAsync(); response.Message = "Logout Successfully"; response.Success = true; } catch (Exception ex) { response.Message = await CustomLog.Log(ex, _context); response.Success = false; } return(response); }
public async Task <ServiceResponse <PagedList <UserSessionView> > > GetUserSession(CustomPagingRequest request) { var response = new ServiceResponse <PagedList <UserSessionView> >(); try { var user = _context.Users.Find(LoggedInUser); var query = (from x in _context.UserSession join y in _context.Users on x.userid equals y.id where (y.roleId == (int)Roles.SuperAdmin) || ((y.roleId == (int)Roles.Recruiter) && y.country == user.country) select new UserSessionView() { userid = x.userid, sessionId = x.sessionId, inTime = x.inTime, name = Common.GetFullName(y), outTime = x.outTime, minutes = x.outTime == null ? 0 : (x.outTime.Value - x.inTime).TotalMinutes }).AsQueryable(); switch (request.sort) { case "userid": case "name": query = (request.sortOrder == "Descending" ? query.OrderByDescending(x => x.userid) : query.OrderBy(x => x.userid)); break; case "sessionId": query = (request.sortOrder == "Descending" ? query.OrderByDescending(x => x.sessionId) : query.OrderBy(x => x.sessionId)); break; case "inTime": query = (request.sortOrder == "Descending" ? query.OrderByDescending(x => x.inTime) : query.OrderBy(x => x.inTime)); break; case "outTime": query = (request.sortOrder == "Descending" ? query.OrderByDescending(x => x.outTime) : query.OrderBy(x => x.outTime)); break; case "minutes": query = (request.sortOrder == "Descending" ? query.OrderByDescending(x => x.minutes) : query.OrderBy(x => x.minutes)); break; default: break; } response.Data = new PagedList <UserSessionView>( query, request); response.Success = true; response.Message = "Retrived"; } catch (Exception ex) { response.Success = true; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <int> > PutJobCandidates(int id, JobCandidates jobCandidates) { var response = new ServiceResponse <int>(); try { if (id != jobCandidates.id) { response.Success = false; response.Message = "Invalid Candidate"; return(response); } var job = _context.JobCandidates.Find(id); if (job == null) { response.Success = false; response.Message = "Candidate details not found"; return(response); } if (User.Identity.IsAuthenticated) { var identity = User.Identity as ClaimsIdentity; if (identity != null) { IEnumerable <Claim> claims = identity.Claims; } } jobCandidates.modifiedBy = LoggedInUser; jobCandidates.modifiedDate = DateTime.UtcNow; _context.Entry(job).CurrentValues.SetValues(jobCandidates); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Update success"; response.Data = job.id; } catch (DbUpdateConcurrencyException ex) { if (!JobCandidatesExists(id)) { response.Success = false; response.Message = "Invalid Candidate"; return(response); } else { response.Success = false; response.Message = await CustomLog.Log(ex, _context); return(response); } } return(response); }
public async Task <ServiceResponse <bool> > UploadAttachment(int id) { var response = new ServiceResponse <bool>(); if (!Request.Form.Files.Any() || id <= 0) { response.Success = false; response.Message = "Unable to find resume or invalid candidate info"; return(response); } try { var candidate = _context.RecruitCare.Find(id); if (candidate == null) { response.Success = false; response.Message = "Unable to find candidate"; return(response); } using (var memoryStream = new MemoryStream()) { Request.Form.Files[0].CopyTo(memoryStream); candidate.resume = memoryStream.ToArray(); candidate.fileName = Request.Form.Files[0].FileName; } response.Success = true; response.Message = "Add or Update Success"; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!RecruitCareExists(id)) { response.Success = false; response.Message = "Unable to find Recruit care candidate info"; return(response); } else { response.Success = false; response.Message = await CustomLog.Log(ex, _context); return(response); } } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); return(response); } return(response); }
public async Task <ServiceResponse <dynamic> > GetDashBoardData(DashboardInput dashboardInput) { var response = new ServiceResponse <dynamic>(); try { var user = _context.Users.Find(LoggedInUser); var candidateStatus = await(from x in _context.MasterData join y in _context.MasterDataType on x.type equals y.id where y.name == "JobCandidateStatus" select x).ToListAsync(); var candidates = await(from x in _context.JobCandidates join j in _context.Openings on x.jobid equals j.id where j.country == user.country && (dashboardInput.recruiter == 0 ? true : (dashboardInput.recruiter == x.createdBy || dashboardInput.recruiter == x.modifiedBy)) && (dashboardInput.dateFrom.HasValue ? x.createdDate.Value.Date >= dashboardInput.dateFrom.Value.Date : true) && (dashboardInput.dateTo.HasValue ? x.createdDate.Value.Date <= dashboardInput.dateTo.Value.Date : true) select x).ToListAsync(); var res = (from x in candidateStatus join y in candidates on x.id equals y.status group x by x.name into g select new KeyValuePair <string, int>(g.Key, g.Count())).ToList(); var recruitcare = await(from x in _context.RecruitCare join j in _context.Openings on x.jobid equals j.id where j.country == user.country && (dashboardInput.recruiter == 0 ? true : (dashboardInput.recruiter == x.createdBy || dashboardInput.recruiter == x.modifiedBy)) && (dashboardInput.dateFrom.HasValue ? x.createdDate.Value.Date >= dashboardInput.dateFrom.Value.Date : true) && (dashboardInput.dateTo.HasValue ? x.createdDate.Value.Date <= dashboardInput.dateTo.Value.Date : true) select x).ToListAsync(); var resRec = (from x in candidateStatus join y in recruitcare on x.id equals y.status group x by x.name into g select new KeyValuePair <string, int>(g.Key, g.Count())).ToList(); List <KeyValuePair <string, KeyValuePair <int, int> > > result = new List <KeyValuePair <string, KeyValuePair <int, int> > >(); foreach (var item in candidateStatus) { var count = 0; count = (count + res.FirstOrDefault(x => x.Key == item.name).Value); count = (count + resRec.FirstOrDefault(x => x.Key == item.name).Value); result.Add(new KeyValuePair <string, KeyValuePair <int, int> >(item.name, new KeyValuePair <int, int>(item.id, count))); } response.Data = result;; response.Message = "Data Retrived"; response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <int> > PutMasterData(int id, MasterData masterData) { var response = new ServiceResponse <int>(); try { if (id != masterData.id) { response.Success = false; response.Message = "Invalid master data"; return(response); } var item = _context.MasterData.Find(id); if (item == null) { response.Success = false; response.Message = "Master Data not found"; return(response); } masterData.modifiedBy = LoggedInUser; masterData.modifiedDate = DateTime.UtcNow; _context.Entry(item).CurrentValues.SetValues(masterData); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Master Data updated successfully"; response.Data = masterData.id; } catch (DbUpdateConcurrencyException ex) { if (!MasterDataExists(id)) { response.Success = false; response.Message = "Master Data not found"; } else { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <int> > PutCity(int id, City city) { var response = new ServiceResponse <int>(); try { if (id != city.Id) { response.Success = false; response.Message = "Invalid city"; return(response); } var item = _context.Citys.Find(id); if (item == null) { response.Success = false; response.Message = "City not found"; return(response); } city.modifiedBy = LoggedInUser; city.modifiedDate = DateTime.UtcNow; _context.Entry(item).CurrentValues.SetValues(city); await _context.SaveChangesAsync(); response.Success = true; response.Message = "City updated successfully"; response.Data = city.Id; } catch (DbUpdateConcurrencyException ex) { if (!CityExists(id)) { response.Success = false; response.Message = "City not found"; } else { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <bool> > MoveToJobCandidates(int id) { var response = new ServiceResponse <bool>(); try { var recruitCare = await _context.RecruitCare.FindAsync(id); if (recruitCare == null) { response.Success = false; response.Message = "Invalid Recruitcare id"; return(response); } var ifExist = await _context.JobCandidates.FirstOrDefaultAsync(x => x.email == recruitCare.email && x.jobid == recruitCare.jobid); if (ifExist != null) { _context.RecruitCare.Remove(recruitCare); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Successf fully removed item from Recruitcare , Entry already exists in job candidates"; } else { var mappedItem = _mapper.Map <JobCandidates>(recruitCare); mappedItem.modifiedBy = LoggedInUser; mappedItem.modifiedDate = DateTime.UtcNow; mappedItem.modifiedBy = mappedItem.modifiedBy ?? mappedItem.createdBy; mappedItem.id = 0; _context.RecruitCare.Remove(recruitCare); _context.JobCandidates.Add(mappedItem); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Successf fully moved to job candidates"; } } catch (Exception ex) { response.Message = await CustomLog.Log(ex, _context); response.Success = false; } return(response); }
public async Task <ServiceResponse <int> > PutMasterDataType(int id, MasterDataType masterDataType) { var response = new ServiceResponse <int>(); try { if (id != masterDataType.id) { response.Success = false; response.Message = "Invalid master data"; return(response); } var item = _context.MasterDataType.Find(id); if (item == null) { response.Success = false; response.Message = "Master Data type not found"; return(response); } _context.Entry(item).CurrentValues.SetValues(masterDataType); await _context.SaveChangesAsync(); response.Success = true; response.Message = "Master Data type updated successfully"; response.Data = masterDataType.id; } catch (DbUpdateConcurrencyException ex) { if (!MasterDataTypeExists(id)) { response.Success = false; response.Message = "Master Data type not found"; } else { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ActionResult <ServiceResponse <IList <State> > > > GetStatesByCountry(int id) { var response = new ServiceResponse <IList <State> >(); try { response.Data = await _context.State.Where(x => x.Country == id).OrderBy(x => x.Name).ToListAsync(); response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(Ok(response)); }
public async Task <ServiceResponse <Openings> > GetOpeningById(int id) { var response = new ServiceResponse <Openings>(); try { response.Data = _context.Openings.Find(id); response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <IEnumerable <MasterDataType> > > GetMasterDataType() { var response = new ServiceResponse <IEnumerable <MasterDataType> >(); try { response.Data = await _context.MasterDataType.ToListAsync(); response.Success = true; response.Message = "Data Retrived"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <bool> > PutUsers(int id, UserDto users) { var response = new ServiceResponse <bool>(); try { if (id != users.id) { response.Success = false; response.Message = "Invalid user id"; return(response); } var user = await _context.Users.FindAsync(id); users.password = user.password; user.modifiedBy = LoggedInUser; users.modifiedDate = DateTime.UtcNow; var usr = _mapper.Map <Users>(users); _context.Entry(user).CurrentValues.SetValues(usr); await _context.SaveChangesAsync(); response.Success = true; response.Message = "User updated successfully"; } catch (Exception ex) { if (!UsersExists(id)) { response.Success = false; response.Message = "User not found"; return(response); } else { response.Success = false; response.Message = await CustomLog.Log(ex, _context); return(response); } } return(response); }
public async Task <ServiceResponse <int> > PostCountry(Country country) { _context.Countries.Add(country); var response = new ServiceResponse <int>(); try { if (country == null || country.Id > 0) { response.Success = false; response.Message = "Invalid country info"; } else { country.createdBy = LoggedInUser; country.createdDate = DateTime.UtcNow; _context.Countries.Add(country); await _context.SaveChangesAsync(); response.Data = country.Id; response.Success = true; response.Message = "Country added successfully"; } } catch (DbUpdateException e) when(e.InnerException?.InnerException is SqlException sqlEx && (sqlEx.Number == 2601 || sqlEx.Number == 2627)) { response.Success = false; await CustomLog.Log(e, _context); response.Message = "Country already Exists"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <string> > GetJobCode(int id) { var response = new ServiceResponse <string>(); try { var item = await _context.Countries.FirstOrDefaultAsync(x => x.Id == id); var newId = _context.Openings.Any() ? _context.Openings.Max(x => x.id) : 0; response.Data = item.Code + "-" + (newId + 1).ToString("00000"); response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <IList <MasterData> > > GetMasterDataByType(int id, bool includeDefault) { var response = new ServiceResponse <IList <MasterData> >(); try { if (Enum.IsDefined(typeof(MasterDataTypes), id)) { response.Data = await _context.MasterData.Where(x => x.type == id).OrderByDescending(x => x.type).ToListAsync(); if (includeDefault) { var list = await _context.MasterData.Where(x => x.type == (int)MasterDataTypes.Common).ToListAsync(); foreach (var item in list) { response.Data.Insert(0, item); } } if (response.Data == null) { response.Success = false; response.Message = "Data not found"; return(response); } response.Success = true; response.Message = "Data Retrived"; } else { response.Success = false; response.Message = "Invalid Master type, please check"; } } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <int> > AddBulk(dynamic state) { var response = new ServiceResponse <int>(); try { _context.State.Add(state); await _context.SaveChangesAsync(); response.Data = state.Id; response.Success = true; response.Message = "State added successfully"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ActionResult <ServiceResponse <string> > > GetCountryCodeByJobId(int jobid) { var response = new ServiceResponse <string>(); try { response.Data = await(from x in _context.Openings join c in _context.Countries on x.country equals c.Id where x.id == jobid select c.Code).FirstOrDefaultAsync(); response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(Ok(response)); }
public async Task <ServiceResponse <int> > PostMasterDataType(MasterDataType masterDataType) { var response = new ServiceResponse <int>(); try { _context.MasterDataType.Add(masterDataType); await _context.SaveChangesAsync(); response.Data = masterDataType.id; response.Success = true; response.Message = "Master data type added successfully"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }
public async Task <ServiceResponse <IList <City> > > GetCitiesByState(int id, bool includeDefaults) { var response = new ServiceResponse <IList <City> >(); try { response.Data = await _context.Citys.Where(x => x.State == id).OrderBy(x => x.Name).ToListAsync(); if (!includeDefaults) { response.Data = response.Data.Where(x => x.Name.ToLower() != "yet to grab").ToList(); } response.Success = true; response.Message = "Success"; } catch (Exception ex) { response.Success = false; response.Message = await CustomLog.Log(ex, _context); } return(response); }