shoc-backend/SeaHavenIndustries/Data/Services/UserWorkorderService.cs

58 lines
2.4 KiB
C#
Raw Normal View History

2024-09-28 14:58:36 -04:00
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<ApplicationUser> _userManager;
private UploadFileHp _uploadFileHelper;
public UserWorkorderService(ApplicationDbContext context, IHttpContextAccessor httpContextAccessor, UserManager<ApplicationUser> userManager, UploadFileHp uploadFileHelper)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
_userManager = userManager;
_uploadFileHelper = uploadFileHelper;
}
public async Task<IQueryable<WorkOrder>> 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<WorkOrder> 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<string> 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;
}
}
}
}