public bool Update(SupportContract model) { var bulider = new UpdateBuilder("support") .RegisterField("SupportNum", model.SupportNum) .RegisterField("OpposeNum", model.OpposeNum) .RegisterClause(new EqualBuilder <long>("ResourceId", model.ResourceId)); return(AdoProvide.ExecuteNonQuery(WriteConnectionString, bulider) > 0); }
public bool Insert(SupportContract model) { var bulider = new InsertBuilder("support") .RegisterField("ResourceId", model.ResourceId) .RegisterField("SupportNum", model.SupportNum) .RegisterField("OpposeNum", model.OpposeNum) .RegisterField("ReadNum", model.ReadNum); return(AdoProvide.ExecuteNonQuery(WriteConnectionString, bulider) > 0); }
public SummaryTabView([ServiceDependency] WorkItem workItem) { this.workItem = workItem as LaytonWorkItem; InitializeComponent(); InitializeUserDefinedCategoryTabs(); _listAssetTypes.Populate(); tree = new UltraTree(); bApply = false; m_objSupportContract = new SupportContract(); //LoadForm(); }
public JsonResult setSupport(User user, int status, long articleId) { int result = 0; var isSupport = supportService.IsSupport(user.UserID, articleId); if (isSupport) { result = 1; } else { var returnResult = supportService.GetModelByResourceId(articleId); if (returnResult.Code == 0 && returnResult.Data != null) { if (status == 0) { returnResult.Data.SupportNum = returnResult.Data.SupportNum + 1; } else { returnResult.Data.OpposeNum = returnResult.Data.OpposeNum + 1; } supportService.Update(returnResult.Data); } else { SupportContract support = new SupportContract(); support.OpposeNum = 0; support.ReadNum = 0; support.SupportNum = 0; if (status == 0) { support.SupportNum = 1; } else { support.OpposeNum = 1; } support.ResourceId = articleId; supportService.Insert(support); } SupportRecordContract record = new SupportRecordContract(); record.Status = status; record.ResourceId = articleId; record.UserId = user.UserID; record.UserName = user.UserName; record.CreatDate = DateTime.Now; supportService.InsertRecord(record);//添加记录 } return(Json(new ReturnResult <int>(result))); }
public virtual void HandleSupportItemEvent(SupportItemDto supportItemDto, TenantInfo tenantInfo) { // Add Cross-Tenant Permissions between Vendors and Customers based on the new SupportItem // via LeaseItems for the relevant Asset // Permissions are for Incidents, WorkOrders, Assets and Users List <string> entities = new List <string>() { "Incident", "WorkOrder", "Asset", "User" }; SupportContract supportContract = _supportContractRepository.Get((int)supportItemDto.SupportContractId); Vendor vendor = _vendorRepository.Get((int)supportContract.VendorId); int vendorTenantId = (int)vendor.TenantId; List <int> leaseAgreementIds = _leaseItemRepository.GetAll().Where(s => s.AssetId == supportItemDto.AssetId).Select(s => (int)s.LeaseAgreementId).ToList(); List <int> customerIds = _leaseAgreementRepository.GetAll().Where(l => leaseAgreementIds.Contains(l.Id)).Select(l => (int)l.CustomerId).Distinct().ToList(); List <int> customerTenantIds = _customerRepository.GetAll().Where(c => customerIds.Contains(c.Id)).Select(c => (int)c.TenantId).Distinct().ToList(); bool clearCache = false; var allCtps = _crossTenantPermissionRepository.GetAllList(); foreach (var entity in entities) { foreach (var customerTenantId in customerTenantIds) { // Add the Customer Tenant Ids to the Vendors' CTPs var existingVendorPermission = allCtps.Where(p => p.TenantId == vendorTenantId && p.EntityType == entity).FirstOrDefault(); if (existingVendorPermission != null) { var existingIds = existingVendorPermission.Tenants.Split(',').ToList().Select(int.Parse).ToList(); if (!existingIds.Contains(customerTenantId)) { existingIds.Add(customerTenantId); var ctp = _crossTenantPermissionRepository.GetAll().Where(p => p.TenantId == vendorTenantId && p.EntityType == entity).FirstOrDefault(); ctp.Tenants = string.Join(",", existingIds); _crossTenantPermissionRepository.Update(ctp); clearCache = true; } } else { CrossTenantPermission ctp = new CrossTenantPermission() { EntityType = entity, TenantId = vendorTenantId, Tenants = customerTenantId.ToString(), TenantType = "V", TenantRefId = vendorTenantId }; _crossTenantPermissionRepository.Insert(ctp); clearCache = true; } // Add the Vendor Tenant Id to this Customer' CTPs var existingCustomerPermission = allCtps.Where(p => p.TenantId == customerTenantId && p.EntityType == entity).FirstOrDefault(); if (existingCustomerPermission != null) { var existingIds = existingCustomerPermission.Tenants.Split(',').ToList().Select(int.Parse).ToList(); if (!existingIds.Contains(vendorTenantId)) { existingIds.Add(vendorTenantId); var ctp = _crossTenantPermissionRepository.GetAll().Where(p => p.TenantId == customerTenantId && p.EntityType == entity).FirstOrDefault(); ctp.Tenants = string.Join(",", existingIds); _crossTenantPermissionRepository.Update(ctp); clearCache = true; } } else { CrossTenantPermission ctp = new CrossTenantPermission() { EntityType = entity, TenantId = customerTenantId, Tenants = vendorTenantId.ToString(), TenantType = "C", TenantRefId = customerTenantId }; _crossTenantPermissionRepository.Insert(ctp); clearCache = true; } } } if (clearCache) { _cacheManager.GetCrossTenantPermissionCache().Clear(); } }
private void CreateContracts() { // Support Contracts int counter = 0; bool createSupportContracts = true; var supportContracts = _context.SupportContracts.ToList(); if (supportContracts.Count > 0) { var lastSupportContract = supportContracts.Last(); if (supportContractDescriptions.Contains(lastSupportContract.Description)) { createSupportContracts = false; } ; } if (createSupportContracts) { var assetOwner = _context.AssetOwners.FirstOrDefault(); do { int?vendorId = (supportContractVendorIds[counter].ToUpper() != "NULL") ? (int?)Convert.ToInt32(supportContractVendorIds[counter]) : null; SupportContract supportContract = new SupportContract() { AssetOwnerId = assetOwner.Id, VendorId = vendorId, Description = supportContractDescriptions[counter], EndDate = DateTime.ParseExact(supportContractEndDates[counter], "yyyy-mm-dd", null), StartDate = DateTime.ParseExact(supportContractStartDates[counter], "yyyy-mm-dd", null), Reference = supportContractReferences[counter], TenantId = assetOwner.TenantId, Title = supportContractTitles[counter], AcknowledgedAt = DateTime.ParseExact(supportContractAcknowledgedAts[counter], "yyyy-mm-dd", null), AcknowledgedBy = supportContractAcknowledgedBys[counter], IsAcknowledged = (supportContractAcknowledgedBys[counter] != "0") ? true : false, IsRFQTemplate = false, CreationTime = DateTime.Now, IsDeleted = false }; var createdSupportContract = _context.SupportContracts.Add(supportContract).Entity; _context.SaveChanges(); counter = counter + 1; } while (counter < supportContractReferences.Count()); } // Add Assets counter = 0; bool createSupportItems = true; var supportItems = _context.SupportItems.ToList(); if (supportItems.Count > 0) { var lastSupportItem = supportItems.Last(); if (supportItemDescriptions.Contains(lastSupportItem.Description)) { createSupportItems = false; } ; } if (createSupportItems) { var assetOwner = _context.AssetOwners.FirstOrDefault(); do { int?assetClassId = (supportItemAssetClassIds[counter].ToUpper() != "NULL") ? (int?)Convert.ToInt32(supportItemAssetClassIds[counter]) : null; int?consumableTypeId = (supportItemConsumableTypeIds[counter].ToUpper() != "NULL") ? (int?)Convert.ToInt32(supportItemConsumableTypeIds[counter]) : null; int?frequency = (supportItemFrequencies[counter].ToUpper() != "NULL") ? (int?)Convert.ToInt32(supportItemFrequencies[counter]) : null; int?supportTypeId = (supportItemSupportTypeIds[counter].ToUpper() != "NULL") ? (int?)Convert.ToInt32(supportItemSupportTypeIds[counter]) : null; SupportItem supportItem = new SupportItem() { AssetClassId = assetClassId, AssetId = Convert.ToInt32(supportItemAssetIds[counter]), Description = supportItemDescriptions[counter], TenantId = assetOwner.TenantId, ConsumableTypeId = consumableTypeId, Frequency = frequency, IsAdHoc = (supportItemIsAdHocs[counter] != "0") ? true : false, IsChargeable = (supportItemIsChargeables[counter] != "0") ? true : false, IsStandbyReplacementUnit = (supportItemIsStandbys[counter] != "0") ? true : false, SupportContractId = Convert.ToInt32(supportItemSupportContractIds[counter]), UomId = Convert.ToInt32(supportItemUomIds[counter]), SupportTypeId = supportTypeId, UnitPrice = Convert.ToInt32(supportItemUnitPrices[counter]), CreationTime = DateTime.Now, IsDeleted = false }; var createdSupportItem = _context.SupportItems.Add(supportItem).Entity; _context.SaveChanges(); counter = counter + 1; } while (counter < supportItemDescriptions.Count()); } }
public bool Insert(SupportContract model) { return(_support.Insert(model)); }
public bool Update(SupportContract model) { return(_support.Update(model)); }
public async Task <PagedResultDto <GetAttachmentForViewDto> > GetSome(GetSomeAttachmentsInput input) { using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MustHaveTenant, AbpDataFilters.MayHaveTenant)) // BYPASS TENANT FILTER to include Users { var tenantInfo = await TenantManager.GetTenantInfo(); var tenantType = tenantInfo.Tenant.TenantType; string relatedType = string.Empty; bool authForAsset = false; bool authForIncident = false; bool authForLeaseAgreement = false; bool authForQuotation = false; bool authForSupportContract = false; bool authForWorkOrder = false; // Check Authorization for Attachments related to Assets Asset relatedAsset = new Asset(); if (input.RelatedEntity == "Asset") { relatedAsset = _assetRepository.Get(input.ReferenceId); SupportItem relatedSupportItem = _supportItemRepository.GetAll().Where(c => c.AssetId == relatedAsset.Id).Include(c => c.SupportContractFk).FirstOrDefault(); switch (tenantType) { case "A": authForAsset = (relatedSupportItem?.SupportContractFk?.AssetOwnerId == tenantInfo.AssetOwner.Id) ? true : false; break; case "V": authForAsset = (relatedSupportItem?.SupportContractFk?.VendorId == tenantInfo.Vendor.Id) ? true : false; break; case "C": LeaseItem relatedLeaseItem = _leaseItemRepository.GetAll().Where(l => l.AssetId == relatedAsset.Id).Include(l => l.LeaseAgreementFk).FirstOrDefault(); authForAsset = (relatedLeaseItem?.LeaseAgreementFk?.CustomerId == tenantInfo.Customer.Id) ? true : false; break; default: authForAsset = true; break; } } SupportContract relatedSupportContract = new SupportContract(); if (input.RelatedEntity == "SupportContract") { relatedSupportContract = _supportContractRepository.Get(input.ReferenceId); switch (tenantType) { case "A": authForSupportContract = (relatedSupportContract?.AssetOwnerId == tenantInfo.AssetOwner.Id) ? true : false; break; case "V": authForSupportContract = (relatedSupportContract?.VendorId == tenantInfo.Vendor.Id) ? true : false; break; case "C": List <int> relatedAssetIds = _supportItemRepository.GetAll().Where(c => c.SupportContractId == input.ReferenceId).Select(c => c.AssetId).ToList(); List <LeaseItem> relatedLeaseItems = _leaseItemRepository.GetAll().Where(l => relatedAssetIds.Contains((int)l.AssetId)).Include(l => l.LeaseAgreementFk).ToList(); List <int?> relatedCustomerIds = relatedLeaseItems.Select(l => l.LeaseAgreementFk).Select(l => l.CustomerId).ToList(); authForSupportContract = (relatedCustomerIds.Contains(tenantInfo.Customer.Id)) ? true : false; break; default: authForSupportContract = true; break; } } WorkOrder relatedWorkOrder = new WorkOrder(); if (input.RelatedEntity == "WorkOrder") { relatedWorkOrder = _workOrderRepository.GetAll().Include(c => c.AssetOwnershipFk).Where(w => w.Id == input.ReferenceId).FirstOrDefault(); switch (tenantType) { case "A": authForWorkOrder = (relatedWorkOrder?.AssetOwnershipFk?.AssetOwnerId == tenantInfo.AssetOwner.Id) ? true : false; break; case "V": authForWorkOrder = (relatedWorkOrder?.VendorId == tenantInfo.Vendor.Id) ? true : false; break; case "C": authForWorkOrder = (relatedWorkOrder?.CustomerId == tenantInfo.Customer.Id) ? true : false; break; default: authForWorkOrder = true; break; } } // TODO: Complete Auth Check LeaseAgreement relatedLeaseAgreement = new LeaseAgreement(); if (input.RelatedEntity == "LeaseAgreement") { relatedLeaseAgreement = _leaseAgreementRepository.Get(input.ReferenceId); if (relatedLeaseAgreement?.Id > 0) { authForLeaseAgreement = true; } } // TODO: Complete Auth Check Incident relatedIncident = new Incident(); if (input.RelatedEntity == "Incident") { relatedIncident = _incidentRepository.Get(input.ReferenceId); if (relatedIncident?.Id > 0) { authForIncident = true; } } // TODO: Complete Auth Check Quotation relatedQuotation = new Quotation(); if (input.RelatedEntity == "Quotation") { relatedQuotation = _quotationRepository.Get(input.ReferenceId); if (relatedQuotation?.Id > 0) { authForQuotation = true; } } var filteredAttachments = _attachmentRepository.GetAll() .Include(e => e.AssetFk) .Include(e => e.IncidentFk) .Include(e => e.LeaseAgreementFk) .Include(e => e.QuotationFk) .Include(e => e.SupportContractFk) .Include(e => e.WorkOrderFk) .Include(e => e.CustomerInvoiceFk) .WhereIf((!authForAsset && !authForIncident && !authForLeaseAgreement && !authForQuotation && !authForSupportContract && !authForWorkOrder), e => e.Id == 0) .WhereIf(authForAsset, e => e.AssetId == input.ReferenceId) .WhereIf(authForIncident, e => e.IncidentId == input.ReferenceId) .WhereIf(authForLeaseAgreement, e => e.LeaseAgreementId == input.ReferenceId) .WhereIf(authForQuotation, e => e.QuotationId == input.ReferenceId) .WhereIf(authForSupportContract, e => e.SupportContractId == input.ReferenceId) .WhereIf(authForWorkOrder, e => e.WorkOrderId == input.ReferenceId); var pagedAndFilteredAttachments = filteredAttachments .OrderBy(input.Sorting ?? "id asc") .PageBy(input); var attachments = from o in pagedAndFilteredAttachments join o1 in _lookup_assetRepository.GetAll() on o.AssetId equals o1.Id into j1 from s1 in j1.DefaultIfEmpty() join o2 in _lookup_incidentRepository.GetAll() on o.IncidentId equals o2.Id into j2 from s2 in j2.DefaultIfEmpty() join o3 in _lookup_leaseAgreementRepository.GetAll() on o.LeaseAgreementId equals o3.Id into j3 from s3 in j3.DefaultIfEmpty() join o4 in _lookup_quotationRepository.GetAll() on o.QuotationId equals o4.Id into j4 from s4 in j4.DefaultIfEmpty() join o5 in _lookup_supportContractRepository.GetAll() on o.SupportContractId equals o5.Id into j5 from s5 in j5.DefaultIfEmpty() join o6 in _lookup_workOrderRepository.GetAll() on o.WorkOrderId equals o6.Id into j6 from s6 in j6.DefaultIfEmpty() join o7 in _lookup_customerInvoiceRepository.GetAll() on o.IncidentId equals o7.Id into j7 from s7 in j7.DefaultIfEmpty() join o8 in _lookup_userRepository.GetAll() on o.UploadedBy equals o8.Id into j8 from s8 in j8.DefaultIfEmpty() select new GetAttachmentForViewDto() { Attachment = new AttachmentDto { Filename = o.Filename, Description = o.Description, UploadedAt = o.UploadedAt, UploadedBy = o.UploadedBy, BlobFolder = o.BlobFolder, BlobId = o.BlobId, Id = o.Id }, AssetReference = s1 == null ? "" : s1.Reference.ToString(), IncidentDescription = s2 == null ? "" : s2.Description.ToString(), LeaseAgreementReference = s3 == null ? "" : s3.Reference.ToString(), QuotationTitle = s4 == null ? "" : s4.Title.ToString(), SupportContractTitle = s5 == null ? "" : s5.Title.ToString(), WorkOrderSubject = s6 == null ? "" : s6.Subject.ToString(), CustomerInvoiceDescription = s7 == null ? "" : s7.Description.ToString(), UploadedByName = s8 == null ? "" : s8.Name + " (" + s8.EmailAddress + ")" //AssetReference = relatedAsset.Reference.ToString(), //IncidentDescription = relatedIncident.Description.ToString(), //LeaseAgreementReference = relatedLeaseAgreement.Reference.ToString(), //QuotationTitle = relatedQuotation.Title.ToString(), //SupportContractTitle = relatedSupportContract.Title.ToString(), //WorkOrderSubject = relatedWorkOrder.Subject.ToString() }; var totalCount = await filteredAttachments.CountAsync(); var pagedResult = new PagedResultDto <GetAttachmentForViewDto>( totalCount, await attachments.ToListAsync()); return(pagedResult); } }