public async Task <ActionResult> New(NewMessage message) { if (this.ModelState.IsValid) { message.SentAt = DateTime.UtcNow; message.SentByUserId = this.User.Identity.GetUserId <long>(); var result = await this.DbRepository.NewMessage(message); if (result.IsSuccess) { var statusResult = await this.DbRepository.StatusMessage(this.User.Identity.GetUserId <long>()); if (statusResult.IsSuccess) { var status = statusResult.Payload; this._hubContext.Clients.Group(JobHub.GetGroup(status.CompanyId)).update(status.CompanyId, status.TotalNoOfMessages, status.TotalNoOfUnreadMessages); } return(this.RedirectToAction("Status")); } } var selectListResult = await this.DbRepository.GetCompaniesSelectList(message.CompanyId); if (selectListResult.IsSuccess) { this.ViewBag.Companies = selectListResult.Payload; } return(this.View(message)); }
public async Task <ActionResult> Details(string code) { if (string.IsNullOrEmpty(code)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } await this.DbRepository.MarkAsRead(code, this.User.Identity.GetUserId <long>()); var result = await this.DbRepository.DetailsMessage(code); if (result.IsSuccess == false || result.Payload == null) { return(HttpNotFound()); } var statusResult = await this.DbRepository.StatusMessage(this.User.Identity.GetUserId <long>()); if (statusResult.IsSuccess) { var status = statusResult.Payload; this._hubContext.Clients.Group(JobHub.GetGroup(status.CompanyId)).update(status.CompanyId, status.TotalNoOfMessages, status.TotalNoOfUnreadMessages); } return(this.View(result.Payload)); }
public void Update(int jobId) { var job = this._dbContext .Jobs .Include(x => x.Status) .Include(x => x.Actions) .Include(x => x.Positions) .FirstOrDefault(x => x.Id == jobId); if (job == null) { return; } if (job.StatusId == 1 || string.IsNullOrEmpty(job.Resolution) || job.Actions.Count == 1) { return; } var actions = job.Actions.OrderByDescending(x => x.AddedAt).Select(x => new ActionListViewModel { Id = x.Id, Name = x.Name, AddedAt = x.AddedAt, }).ToArray().AsJson(); var positions = job.Positions.OrderBy(x => x.AddedAt).Select(x => new LatLng { Lat = x.Latitude, Lng = x.Longitude }).ToArray().AsJson(); this._hubContext.Clients.Group(JobHub.GetGroup(job.Id)) .update(job.Id, job.Status.Name, job.Resolution, actions, positions); if (job.StatusId != 3) { return; } job.IsInProgress = false; this._dbContext.Entry(job).State = EntityState.Modified; this._dbContext.SaveChanges(); RecurringJob.RemoveIfExists("update-job-#" + job.Id); }