This commit is contained in:
2021-11-18 20:25:08 +00:00
parent 6c2fb27eb8
commit d466b4b0b8
3 changed files with 44 additions and 89 deletions

View File

@@ -108,7 +108,7 @@ namespace AyaNova.Biz
}
//For auth and access in client, also when opening wo and also when reporting wo
internal static async Task<CustomerRightsRecord> CustomerUserEffectiveRightsAsync(long userId, long? workorderId = null)
internal static async Task<CustomerRightsRecord> CustomerUserEffectiveRightsAsync(long userId, List<string> thisWorkOrderTags = null)
{
using (AyContext ct = ServiceProviderProvider.DBContext)
{
@@ -164,14 +164,10 @@ namespace AyaNova.Biz
ThisWOEffectiveWorkOrderReportId = AyaNova.Util.ServerGlobalBizSettings.Cache.CustomerDefaultWorkOrderReportId;
//If a workorder id was provided add it's tags to the wo tag checking rights items
if (workorderId != null)
if (thisWorkOrderTags != null && thisWorkOrderTags.Count > 0)
{
var WoTags = await ct.WorkOrder.AsNoTracking().Where(x => x.Id == workorderId).Select(x => x.Tags).FirstOrDefaultAsync();
if (WoTags != null)
{
CustomerWorkOrderReportByTagTags.AddRange(WoTags);
CustomerWorkOrderWikiAttachmentTags.AddRange(WoTags);
}
CustomerWorkOrderReportByTagTags.AddRange(thisWorkOrderTags);
CustomerWorkOrderWikiAttachmentTags.AddRange(thisWorkOrderTags);
}
//WO REPORT

View File

@@ -306,88 +306,27 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
// GET
//
internal async Task<WorkOrder> WorkOrderGetForCustomerAsync(long id, bool populateDisplayFields, bool logTheGetEvent = true, bool populateForReporting = false)
internal async Task<CustomerWorkOrder> WorkOrderGetForCustomerAsync(long id)
{
throw new System.NotImplementedException();
// var ret = await WorkOrderGetFullAsync(id);
// if (ret != null)
// {
// var stat = await GetCurrentWorkOrderStatusFromRelatedAsync(BizType, ret.Id);
// ret.IsLockedAtServer = stat.Locked;
// var userIsTechRestricted = UserIsTechRestricted;
// var userIsSubContractorFull = UserIsSubContractorFull;
// var userIsSubContractorRestricted = UserIsSubContractorRestricted;
// var userIsRestricted = (userIsTechRestricted || userIsSubContractorFull || userIsSubContractorRestricted);
// if (userIsRestricted)
// {
// //Restricted users can only work with workorder items they are scheduled on
// List<WorkOrderItem> removeItems = new List<WorkOrderItem>();
// //gather list of items to remove by checking if they are scheduled on them or not
// foreach (WorkOrderItem wi in ret.Items)
// {
// var userIsSelfScheduledOnThisItem = false;
// foreach (WorkOrderItemScheduledUser su in wi.ScheduledUsers)
// {
// if (su.UserId == UserId)
// {
// userIsSelfScheduledOnThisItem = true;
// break;
// }
// }
// if (!userIsSelfScheduledOnThisItem) removeItems.Add(wi);
// }
// foreach (var removeitem in removeItems)
// {
// ret.Items.Remove(removeitem);
// ret.IsCompleteRecord = false;
// }
// //Restricted users may have further restrictions
// foreach (WorkOrderItem wi in ret.Items)
// {
// //all restricted types
// wi.ScheduledUsers.RemoveAll(x => x.UserId != UserId);
// wi.Labors.RemoveAll(x => x.UserId != UserId);
// wi.Travels.RemoveAll(x => x.UserId != UserId);
// if (userIsTechRestricted)
// {
// wi.Expenses.RemoveAll(x => x.UserId != UserId);
// }
// if (userIsSubContractorFull)
// {
// wi.Expenses.RemoveAll(x => true);
// wi.OutsideServices.RemoveAll(x => true);
// }
// if (userIsSubContractorRestricted)
// {
// wi.Units.RemoveAll(x => true);
// wi.Parts.RemoveAll(x => true);
// wi.PartRequests.RemoveAll(x => true);
// wi.Expenses.RemoveAll(x => true);
// wi.Loans.RemoveAll(x => true);
// wi.OutsideServices.RemoveAll(x => true);
// }
// //tasks are allowed to be viewed and update the task completion types
// }
// }
// if (populateDisplayFields)
// await WorkOrderPopulateVizFields(ret, false, populateForReporting);
// if (logTheGetEvent && ret != null)
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
// }
// return ret;
var sourceWo = await ct.WorkOrder.AsNoTracking().FirstOrDefaultAsync(z => z.Id == id);
if (sourceWo == null) return null;
var customerEffectiveRights = await UserBiz.CustomerUserEffectiveRightsAsync(UserId, sourceWo.Tags);
var ret = new CustomerWorkOrder();
ret.Id = sourceWo.Id;
ret.Serial = sourceWo.Serial;
ret.ServiceDate = sourceWo.ServiceDate;
ret.CanWiki = false;
if (customerEffectiveRights.ThisWOCanWiki)
{
ret.Wiki = sourceWo.Wiki;
ret.CanWiki = true;
}
ret.CanAttachments = customerEffectiveRights.ThisWOCanAttachments;
ret.CustomerViz = await ct.Customer.AsNoTracking().Where(x => x.Id == sourceWo.CustomerId).Select(x => x.Name).FirstOrDefaultAsync();
ret.CustomerReferenceNumber = sourceWo.CustomerReferenceNumber;
ret.CustomerContactName = sourceWo.CustomerContactName;
ret.InvoiceNumber = sourceWo.InvoiceNumber;
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,20 @@
using System;
namespace AyaNova.Models
{
//Customer version of workorder which is the limited amount of data allowed to be viewed by Customer based on corresponding actual workorder
public class CustomerWorkOrder
{
public long Id { get; set; }
public long Serial { get; set; }
public string Wiki { get; set; }
public string CustomerViz { get; set; }
public string CustomerReferenceNumber { get; set; }
public string CustomerContactName { get; set; }
public DateTime? ServiceDate { get; set; }
public string InvoiceNumber { get; set; }
public bool CanWiki {get;set;}
public bool CanAttachments {get;set;}
}//eoc
}//eons