using Data.SeaHavenIndustries; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using SeaHavenIndustries.Data.IRepository; using SeaHavenIndustries.Helper; using System.Security.Claims; namespace SeaHavenIndustries.Data.Services { public class UserWorkorderService : IUserWorkorderRepository { private readonly ApplicationDbContext _context; private readonly IHttpContextAccessor _httpContextAccessor; private UserManager _userManager; private UploadFileHp _uploadFileHelper; public UserWorkorderService(ApplicationDbContext context, IHttpContextAccessor httpContextAccessor, UserManager userManager, UploadFileHp uploadFileHelper) { _context = context; _httpContextAccessor = httpContextAccessor; _userManager = userManager; _uploadFileHelper = uploadFileHelper; } public async Task> Getworkorder() { var userId = _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? ""; var data = _context.workOrders.AsSplitQuery().Where(w => w.istemplate != true && w.AssignTo == userId).Include(w => w.Locations).Include(w => w.AssignToUser).AsNoTracking().AsQueryable(); return data; } public async Task GetuserworkorderById(int Id) { var data = await _context.workOrders.Include(i => i.Quotes).Include(f => f.WorkOrderContacts).ThenInclude(i => i.POC).Include(f => f.workOrderAttachments).Include(f => f.Locations).Include(f => f.WorkOrderCategories).ThenInclude(i => i.Category).Include(f => f.AssignToUser).Where(w => w.Id == Id).FirstOrDefaultAsync(); return data ?? new WorkOrder(); } public async Task Updatesignoff(WorkOrder model) { try { var data=await _context.workOrders.Where(w=>w.Id== model.Id).FirstOrDefaultAsync(); if (data!=null) { data.SignOffSignature = model.SignOffSignature; await _context.SaveChangesAsync(); return "success"; } else { return "error"; } } catch(Exception ex) { return ex.Message; } } } }