mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 07:33:14 +00:00
58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|