public async Task <IActionResult> PostBillDetail(BillDetailVM billDetail) { try { FMSAccidentalCheck check = (from c in dbContext.FMSAccidentalCheckList where c.Id == billDetail.CheckPointId select c).SingleOrDefault(); check.MaintenanceStatus = CheckMaintenanceStatus.InProgress; AccidentalBillDetail detail = new () { Id = Guid.NewGuid(), CheckPointId = billDetail.CheckPointId, ServiceType = billDetail.ServiceType, SubServiceType = billDetail.SubServiceType, Amount = Convert.ToString(billDetail.Amount) }; await dbContext.AccidentalBillDetails.AddAsync(detail); await dbContext.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> GetCheckListPointMarkDone(ApiRequest request) { try { FMSAccidentalCheck check = await dbContext.FMSAccidentalCheckList.Where(x => x.Id == request.FMSAccidentalCheckId).Select(x => x).SingleOrDefaultAsync(); Accident accident = await dbContext.Accidents.Where(x => x.Id == check.FMSAccidentId).Select(x => x).SingleOrDefaultAsync(); check.MaintenanceStatus = CheckMaintenanceStatus.Done; accident.LastUpdated = PakistanDateTime.Now; await dbContext.SaveChangesAsync(); string title = $"Accidental Job Vehicle Number {check.VehicleNumber}"; string notification = $"Check Point {check.Description} marked as done"; await hubContext.Clients.All.SendAsync("ReceiveMessageAllUsers", User.Identity.Name, title, notification); await SMSService.SendSMS(title + ": " + notification, "03035650720"); SMSService.SendMail(title, notification, "*****@*****.**"); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> GetCheckListPointDetails(ApiRequest request) { try { FMSAccidentalCommentModalVM modal = new FMSAccidentalCommentModalVM(); FMSAccidentalCheck check = await(from c in dbContext.FMSAccidentalCheckList where c.Id == request.FMSAccidentalCheckId select c).SingleOrDefaultAsync(); modal.FMSAccidentalCheckId = check.Id; modal.FMSAccidentId = check.FMSAccidentId; modal.FMSVehicleId = check.FMSVehicleId; modal.CheckPointName = check.Description; modal.VehicleNumber = request.VehicleNumber; if (check.Description.Contains("Bills Posting")) { modal.CommentModalType = CommentModalType.BillPosting; } else if (check.Description.Contains("Assigning Workshop")) { modal.CommentModalType = CommentModalType.AssignWorkshop; } else { modal.CommentModalType = CommentModalType.General; } modal.Comments = await(from c in dbContext.FMSAccidentalCheckComments where c.FMSAccidentalCheckId == check.Id select new FMSAccidentalCheckCommentVM() { FMSAccidentalCheckId = c.FMSAccidentalCheckId, FMSAccidentId = c.FMSAccidentId, Comment = c.Comment, FMSVehicleId = c.FMSVehicleId, Id = c.Id, LastUpdated = c.LastUpdated, FMSUserId = c.FMSUserId, Mentions = c.Mentions, FMSUserName = (from u in dbContext.Users where u.Id == c.FMSUserId.ToString() select u.Name).SingleOrDefault(), VehicleNumber = c.VehicleNumber }).OrderByDescending(x => x.LastUpdated).ToListAsync(); modal.Images = await(from i in dbContext.FMSAccidentalCheckImages where i.FMSAccidentalCheckId == check.Id select new FMSAccidentalCheckImageVM() { FMSAccidentId = i.FMSAccidentId, FMSAccidentalCheckId = i.FMSAccidentalCheckId, FMSVehicleId = i.FMSVehicleId, Id = i.Id, Image = i.Image, LastUpdated = i.LastUpdated }).ToListAsync(); return(Ok(modal)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> PostBill(AccidentBill bill) { try { var currentUser = (from u in dbContext.Users where u.Email == User.Identity.Name select u).FirstOrDefault(); FMSAccidentalCheck check = (from c in dbContext.FMSAccidentalCheckList where c.Id == bill.CheckPointId select c).SingleOrDefault(); check.MaintenanceStatus = CheckMaintenanceStatus.InProgress; check.Remarks = bill.Remarks; FMSAccidentalCheckComment newComment = new FMSAccidentalCheckComment() { Id = Guid.NewGuid(), FMSAccidentalCheckId = check.Id, FMSAccidentId = check.FMSAccidentId, Comment = bill.BillAmount.ToString(), FMSUserId = new Guid((from u in dbContext.Users where u.Email == User.Identity.Name select u.Id).SingleOrDefault()), FMSVehicleId = check.FMSVehicleId, VehicleNumber = check.VehicleNumber, LastUpdated = DateTime.Now, Mentions = "" }; await dbContext.FMSAccidentalCheckComments.AddAsync(newComment); bill.Id = new Guid(); await dbContext.AccidentBills.AddAsync(bill); check.CommentCount = await(from c in dbContext.FMSAccidentalCheckComments where c.FMSAccidentalCheckId == bill.CheckPointId select c).CountAsync(); Accident accident = await dbContext.Accidents.Where(x => x.Id == check.FMSAccidentId).Select(x => x).SingleOrDefaultAsync(); accident.LastUpdated = PakistanDateTime.Now; check.LastUpdated = PakistanDateTime.Now; await dbContext.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> AssignVendors(WorkshopVM workshopVM) { try { string code = "", name = ""; if (workshopVM.Type == "Approved") { var vendor = await(from a in viewsContext.PblVendorManagements where a.XCode == workshopVM.Code select a).FirstOrDefaultAsync(); code = vendor.XCode; name = vendor.XName; } else if (workshopVM.Type == "Un Approved") { var driver = await(from d in dbContext.Drivers where d.Code == workshopVM.Code select d).FirstOrDefaultAsync(); code = driver.Code; name = driver.Name; } AssignedWorkshop workshop = new AssignedWorkshop() { Id = Guid.NewGuid(), IncidentId = workshopVM.IncidentId, SupplierType = workshopVM.Type, SupplierCode = code, SupplierName = name, Remarks = workshopVM.Remarks }; await dbContext.AssignedWorkshops.AddAsync(workshop); if (await dbContext.SaveChangesAsync() > 0) { if (workshopVM.IncidentType == "Emergency") { FMSEmergencyCheck check = await(from c in dbContext.FMSEmergencyCheckList where c.Id == workshopVM.CheckId select c).FirstOrDefaultAsync(); check.LastUpdated = PakistanDateTime.Now; check.MaintenanceStatus = Shared.Enums.CheckMaintenanceStatus.InProgress; Emergency emergency = await(from c in dbContext.Emergencies where c.Id == workshopVM.IncidentId select c).FirstOrDefaultAsync(); emergency.LastUpdated = PakistanDateTime.Now; if (await dbContext.SaveChangesAsync() > 0) { return(Ok()); } else { return(BadRequest()); } } else if (workshopVM.IncidentType == "Accident") { FMSAccidentalCheck check = await(from c in dbContext.FMSAccidentalCheckList where c.Id == workshopVM.CheckId select c).FirstOrDefaultAsync(); check.LastUpdated = PakistanDateTime.Now; check.MaintenanceStatus = Shared.Enums.CheckMaintenanceStatus.InProgress; Accident accident = await(from c in dbContext.Accidents where c.Id == workshopVM.IncidentId select c).FirstOrDefaultAsync(); accident.LastUpdated = PakistanDateTime.Now; if (await dbContext.SaveChangesAsync() > 0) { return(Ok()); } else { return(BadRequest()); } } return(NotFound()); } else { return(BadRequest()); } } catch (Exception) { return(BadRequest()); } }
public async Task <IActionResult> AddCheckListPointComment(FMSAccidentalCheckCommentVM comment) { try { var currentUser = (from u in dbContext.Users where u.Email == User.Identity.Name select u).FirstOrDefault(); FMSAccidentalCheckComment newComment = new FMSAccidentalCheckComment() { Id = Guid.NewGuid(), FMSAccidentalCheckId = comment.FMSAccidentalCheckId, FMSAccidentId = comment.FMSAccidentId, Comment = comment.Comment, FMSUserId = new Guid((from u in dbContext.Users where u.Email == User.Identity.Name select u.Id).SingleOrDefault()), FMSVehicleId = comment.FMSVehicleId, VehicleNumber = comment.VehicleNumber, LastUpdated = DateTime.Now, Mentions = comment.Mentions }; await dbContext.FMSAccidentalCheckComments.AddAsync(newComment); await dbContext.SaveChangesAsync(); FMSAccidentalCheck check = await(from a in dbContext.FMSAccidentalCheckList where a.Id == comment.FMSAccidentalCheckId select a).SingleOrDefaultAsync(); check.LastUpdated = PakistanDateTime.Now; //await dbContext.SaveChangesAsync(); check.CommentCount = await(from c in dbContext.FMSAccidentalCheckComments where c.FMSAccidentalCheckId == comment.FMSAccidentalCheckId select c).CountAsync(); check.MaintenanceStatus = CheckMaintenanceStatus.InProgress; Accident accident = await dbContext.Accidents.Where(x => x.Id == comment.FMSAccidentId).Select(x => x).SingleOrDefaultAsync(); accident.LastUpdated = PakistanDateTime.Now; await dbContext.SaveChangesAsync(); if (!string.IsNullOrEmpty(comment.Mentions)) { string[] mentions = comment.Mentions.Split(','); foreach (var mention in mentions) { ApplicationUser user = (from u in dbContext.Users where u.Id == mention select u).FirstOrDefault(); await hubContext.Clients.All.SendAsync("ReceiveMessage", user.Email, $"Notification for Vehicle Number {check.VehicleNumber}", $"{currentUser.Name} mentioned you in a comment under accidental check list point {check.Description}"); await SMSService.SendSMS($"Notification for Vehicle Number {check.VehicleNumber}: {currentUser.Name} mentioned you in a comment under accidental check list point {check.Description}", "03035650720"); SMSService.SendMail($"Notification for Vehicle Number {check.VehicleNumber}", $"{currentUser.Name} mentioned you in a comment under accidental check list point {check.Description}", "*****@*****.**"); } } return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }