public static void SuspendResumeJob(CustomJobModel job, string loggedInUserid) { using (var dbcontext = new KaamShaamEntities()) { var dbObj = dbcontext.Jobs.FirstOrDefault(j => j.Id == job.Id); if (dbObj != null) { var postedByUser = dbObj.AspNetUser; KaamShaam.Services.EmailService.SendEmail(postedByUser.Email, "Job Status Changed - KamSham.Pk", postedByUser.FullName + " We noticed some changes in your job '" + dbObj.JobTitle + "'. Please review your jobs."); KaamShaam.Services.EmailService.SendSms(postedByUser.Mobile, "Please review your changes in jobs at https://kamsham.pk"); if (loggedInUserid == dbObj.PostedById) { dbObj.UserStstus = !dbObj.UserStstus; } else { dbObj.AdminStatus = !dbObj.AdminStatus; } } dbcontext.SaveChanges(); } }
public void TriggerJob(string id) { try { RecurringJob.Trigger(id); CustomJobModel job = GetJob(id); LogHistory(Guid.NewGuid(), id, job.ScriptType, DateTime.Now, "Trigger"); } catch (Exception ex) { throw new Exception($"Failed to trigger job: {id}. Error: {ex.Message}"); } }
public void RemoveJob(string id) { try { CustomJobModel job = GetJob(id); RecurringJob.RemoveIfExists(id); LogHistory(Guid.NewGuid(), id, job.ScriptType, DateTime.Now, "Deleted"); } catch (Exception ex) { throw new Exception($"Failed to remove Custom Job {id}. Error: {ex.Message}"); } }
public ActionResult PostJob(CustomJobModel model) { if (ModelState.IsValid) { if (Request.IsAuthenticated) { var id = System.Web.HttpContext.Current.User.Identity.GetUserId(); model.PostedById = id; } model.Email = " "; JobService.AddJob(model); } return(RedirectToAction("ManageJobs", "Job")); }
public static List <CustomJobModel> GetJobsProposals(string loggedInUserId) { using (var dbcontext = new KaamShaamEntities()) { var jobs = dbcontext.Jobs.Where(j => !j.IsRecycled && j.IsApproved && j.UserStstus && j.PostedById == loggedInUserId).ToList(); var mappedJobs = jobs.Select(j => j.Mapper()).ToList().OrderByDescending(jo => jo.PostingDateObj).ToList(); List <CustomJobModel> tempo = new List <CustomJobModel>(); foreach (var obj in mappedJobs) { if (obj.JobHistory != null) { //var isStatus = obj.JobHistory.Any( // t =>t.JobStatus == (int)Commons.Enums.JobHistoryStatus.Applying); var histories = obj.JobHistory; foreach (var his in histories) { // if(his.JobStatus != (int)Commons.Enums.JobHistoryStatus.End) { var cc = new CustomJobModel { Id = obj.Id, ContractorId = his.ContractorId, CatName = obj.CatName, PostedById = obj.PostedById, Email = obj.Email, Fee = obj.Fee, JobTitle = obj.JobTitle, ContractorName = his.ContractorName, Mobile = obj.Mobile, PostingDate = obj.PostingDate, JobStatus = his.JobStatus, CanRate = his.JobStatus == (int)Commons.Enums.JobHistoryStatus.Continue }; tempo.Add(cc); } } //if (isStatus) //{ // tempo.Add(obj); //} } } return(tempo); } }
public static void DeleteJob(CustomJobModel job, string loggedInUserid) { using (var dbcontext = new KaamShaamEntities()) { var dbObj = dbcontext.Jobs.FirstOrDefault(j => j.Id == job.Id); if (dbObj != null) { if (loggedInUserid == dbObj.PostedById) { dbObj.IsRecycled = true; } else { dbObj.IsRecycled = true; } } dbcontext.SaveChanges(); } }
public static Job ChangeJobApproval(CustomJobModel job) { using (var dbcontext = new KaamShaamEntities()) { var dbJob = dbcontext.Jobs.FirstOrDefault(l => l.Id == job.Id); if (dbJob != null) { dbJob.IsApproved = job.IsApproved; if (!job.IsApproved) { dbJob.FeedBack = job.Feedback; } else { dbJob.FeedBack = null; } dbcontext.SaveChanges(); } return(dbJob); } }
public HttpResponseMessage PostJob(CustomJobModel model) { try { #region not mapped if (model == null || string.IsNullOrEmpty(model.JobTitle) || string.IsNullOrEmpty(model.PostedById) || string.IsNullOrEmpty(model.Fee) || string.IsNullOrEmpty(model.LocationCords) || string.IsNullOrEmpty(model.LocationName) || string.IsNullOrEmpty(model.Mobile) || string.IsNullOrEmpty(model.Email) || model.CategoryId == 0) { var response = new ApiResponseModel { Data = null, Message = "Data is not mapped", Success = false }; return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } #endregion var jobresponse = JobService.AddJob(model); var res = new ApiResponseModel { Data = jobresponse, Message = "Jon Posted. Find job id in Data", Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, res)); } catch (Exception excep) { var response = new ApiResponseModel { Data = null, Message = excep.InnerException.Message, Success = false }; return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } }
public List <CustomJobModel> GetJobs() { try { var conn = Hangfire.JobStorage.Current.GetConnection(); var jobs = StorageConnectionExtensions.GetRecurringJobs(conn); //cast jobs to WAMCustomJob type List <CustomJobModel> retJobs = new List <CustomJobModel>(); foreach (var job in jobs) { string jString = job.Job.ToString().ToUpper(); string scriptType = ""; if (jString.Contains("VBS")) { scriptType = "VBS"; } else if (jString.Contains("BAT")) { scriptType = "BAT"; } else if (jString.Contains("PS")) { scriptType = "PS"; } else { scriptType = "OTHER"; } CustomJobModel cjm = new CustomJobModel(job.Id, scriptType, job.Cron, job.LastJobState, job.Job.Args[1].ToString()); retJobs.Add(cjm); } return(retJobs); } catch (Exception ex) { throw new Exception($"Failed to retrieve jobs. Error: {ex.Message}"); } }
public static void EditJob(CustomJobModel job) { using (var dbcontext = new KaamShaamEntities()) { try { var dbObj = dbcontext.Jobs.FirstOrDefault(j => j.Id == job.Id); if (dbObj != null) { dbObj.JobTitle = job.JobTitle; dbObj.Mobile = job.Mobile; dbObj.Email = job.Email ?? "NA"; dbObj.Fee = Convert.ToInt32(job.Fee); dbObj.IsApproved = false; dbObj.FeedBack = null; dbObj.CategoryId = job.CategoryId; } dbcontext.SaveChanges(); } catch (Exception cxc) { } } }
public static long AddJob(CustomJobModel job) { DbGeography loc = null; if (!string.IsNullOrEmpty(job.LocationCords) && job.LocationCords != "") { var latlng = job.LocationCords.Split('_'); if (latlng.Length == 2) { loc = Commons.Commons.ConvertLatLonToDbGeography(latlng[1], latlng[0]); // lat _ lng } } var obj = new Job { JobTitle = job.JobTitle, Mobile = job.Mobile, Email = job.Email, Fee = !string.IsNullOrEmpty(job.Fee)? Convert.ToInt32(job.Fee):0, CategoryId = job.CategoryId, Location = loc, UserStstus = true, AdminStatus = true, IsApproved = false, IsRecycled = false, PostedById = job.PostedById, LocationName = job.LocationName, PostingDate = DateTime.Now }; using (var dbcontext = new KaamShaamEntities()) { dbcontext.Jobs.Add(obj); dbcontext.SaveChanges(); return(obj.Id); } }