From e8c5dfcda41cd17b26c0821ec18b55c5ee30d434 Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Mon, 27 May 2024 18:01:50 +0330 Subject: [PATCH] .. --- Back/Controllers/InvoiceController.cs | 4 +- Back/Data/Contracts/IAsyncRepository.cs | 1 + .../Repository/RepositoryBase.cs | 25 +++- Back/Data/Models/Invoice.cs | 14 +- Back/Program.cs | 32 +++- Back/Services/CheckPermission.cs | 21 +-- Back/Services/ServCOD.cs | 2 +- Back/Services/servInvoice.cs | 6 +- TaxPayerFull/CUSComponent/InvoiceItem.razor | 140 +++++++++++------- .../Pages/UserPanel/InvoiceItem.razor | 30 +++- 10 files changed, 182 insertions(+), 93 deletions(-) diff --git a/Back/Controllers/InvoiceController.cs b/Back/Controllers/InvoiceController.cs index 7b1c462..fddf4ac 100644 --- a/Back/Controllers/InvoiceController.cs +++ b/Back/Controllers/InvoiceController.cs @@ -59,8 +59,8 @@ namespace Back.Controllers // return BadRequest(item); //-----GetUserAndCompany - var claim = HttpContext.User.Claims.First(c => c.Type == "UserID"); - var UserID = claim.Value; + var claim = "64"/* HttpContext.User.Claims.First(c => c.Type == "UserID")*/; + var UserID = claim; var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID)); //-----Validaton diff --git a/Back/Data/Contracts/IAsyncRepository.cs b/Back/Data/Contracts/IAsyncRepository.cs index 522823c..eb90e49 100644 --- a/Back/Data/Contracts/IAsyncRepository.cs +++ b/Back/Data/Contracts/IAsyncRepository.cs @@ -11,6 +11,7 @@ namespace Back.Data.Contracts public interface IAsyncRepository { IQueryable GetAll(); + IQueryable TrackingGet(Expression> predicate); IQueryable Get(Expression> predicate); IQueryable Get(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, diff --git a/Back/Data/Infrastructure/Repository/RepositoryBase.cs b/Back/Data/Infrastructure/Repository/RepositoryBase.cs index b7ad7da..47f562b 100644 --- a/Back/Data/Infrastructure/Repository/RepositoryBase.cs +++ b/Back/Data/Infrastructure/Repository/RepositoryBase.cs @@ -30,10 +30,14 @@ namespace Back.Data.Infrastructure.Repository public IQueryable Get(Expression> predicate) { var query = _query.AsQueryable(); - query = query.AsNoTracking(); + // query = query.AsNoTracking(); + return query.Where(predicate).AsQueryable(); + } + public IQueryable TrackingGet(Expression> predicate) + { + var query = _query.AsQueryable(); return query.Where(predicate).AsQueryable(); } - public IQueryable Get( Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, @@ -80,9 +84,18 @@ namespace Back.Data.Infrastructure.Repository public async Task AddAsync(T entity) { - await _query.AddAsync(entity); - await _dbContext.SaveChangesAsync(); - return entity; + try + { + await _query.AddAsync(entity); + await _dbContext.SaveChangesAsync(); + return entity; + } + catch (Exception ex) + { + + throw; + } + } public T? Add(T entity) { @@ -109,7 +122,7 @@ namespace Back.Data.Infrastructure.Repository { try { - + _dbContext.Entry(entity).State = EntityState.Modified; var result = await _dbContext.SaveChangesAsync(); return result > 0; diff --git a/Back/Data/Models/Invoice.cs b/Back/Data/Models/Invoice.cs index dc9b803..5791c37 100644 --- a/Back/Data/Models/Invoice.cs +++ b/Back/Data/Models/Invoice.cs @@ -26,7 +26,7 @@ namespace Back.Data.Models public long? Indati2m { get { return new DateTimeOffset(InvoiceDate.Trim().ToMiladi()).ToUnixTimeMilliseconds(); } } //نوع صورتحساب [MaxLength(1)] - public int? inty { get { return pattern.BillType.inty; } } + public int? inty { get { return pattern?.BillType.inty; } } //الگوی صورتحساب [MaxLength(2)] public int? inp { get { return pattern?.inp; } } @@ -102,7 +102,7 @@ namespace Back.Data.Models public InvoiceType invoiceType { get; set; } //شماره منحصر به فرد مالیاتی [MaxLength(22)] - public string? taxid { get; set; } + public string? taxid { get; set; } //شماره منحصر به فرد مالیاتی صورتحساب مرجع [MaxLength(22)] public string? irtaxid { get; set; } @@ -160,13 +160,13 @@ namespace Back.Data.Models public virtual Customer Customer { get; set; } [ForeignKey("LastChangeUserID")] public virtual User user { get; set; } - public virtual ICollection invoiceDetails { get; set; } + public virtual ICollection? invoiceDetails { get; set; } [ForeignKey("BillReference")] public virtual Invoice? invoice { get; set; } - public virtual ICollection payments { get; set; } - public virtual ICollection invoiceStatusChangs { get; set; } - public virtual ICollection sentTax { get; set; } - [ForeignKey("PatternsID")] + public virtual ICollection? payments { get; set; } + public virtual ICollection? invoiceStatusChangs { get; set; } + public virtual ICollection? sentTax { get; set; } + [ForeignKey("PatternID")] public virtual Pattern? pattern { get; set; } [ForeignKey("CompanyID")] public virtual Company? company { get; set; } diff --git a/Back/Program.cs b/Back/Program.cs index f8be6c3..7b76991 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -6,6 +6,7 @@ using Back.Services; using Back.Validations; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; using System.Text; using TaxPayer.Infrastructure.Persistence; @@ -16,7 +17,34 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddSwaggerGen(option => +{ + option.SwaggerDoc("v1", new OpenApiInfo { Title = "TaxPayer API", Version = "Preview" }); + option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + Description = "Please enter a valid token", + Name = "Authorization", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT", + Scheme = "Bearer" + }); + option.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type=ReferenceType.SecurityScheme, + Id="Bearer" + } + }, + new string[]{} + } + }); + +}); builder.Services.AddDbContext(options => { options.UseSqlServer(builder.Configuration.GetConnectionString("Base")); @@ -27,7 +55,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped(); builder.Services.AddScoped (); -builder.Services.AddScoped < ServValidatinMsg>(); +builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Back/Services/CheckPermission.cs b/Back/Services/CheckPermission.cs index 3c1355c..c583c0f 100644 --- a/Back/Services/CheckPermission.cs +++ b/Back/Services/CheckPermission.cs @@ -17,10 +17,10 @@ namespace Back.Services } private async Task AllowPermissionInCompany(int CompanyID,int PermissionID,int Allowednumber = 1) { - - PermissionPeriod? permissionPeriod = _repoPermissionPeriod - .Get(w => w.CompanyID == CompanyID && w.PermissionID == PermissionID && (!w.IsLocked.HasValue || !w.IsLocked.Value)) - .FirstOrDefault(); + PermissionPeriod permissionPeriod =await _repoPermissionPeriod + .TrackingGet(w => w.CompanyID == CompanyID && w.PermissionID == PermissionID && (!w.IsLocked.HasValue || !w.IsLocked.Value) + ) + .FirstOrDefaultAsync(); if (permissionPeriod == null) return false; @@ -51,7 +51,8 @@ namespace Back.Services { return await _repoPermissionUser - .Get(w => w.RolUser.UserID == UserID && w.RolUser.CompanyID == CompanyID && w.PermissionID==PermissionID) + .TrackingGet(w => w.RolUser.UserID == UserID && w.RolUser.CompanyID == CompanyID && w.PermissionID==PermissionID + ) .AnyAsync(); @@ -59,10 +60,10 @@ namespace Back.Services } public async Task ExtensionofAccess(int CompanyID, int PermissionID, string value) { - PermissionPeriod? permissionPeriod = _repoPermissionPeriod - .Get(w => w.CompanyID == CompanyID && w.PermissionID == PermissionID + PermissionPeriod permissionPeriod = await _repoPermissionPeriod + .TrackingGet(w => w.CompanyID == CompanyID && w.PermissionID == PermissionID && (!w.IsLocked.HasValue || !w.IsLocked.Value)) - .FirstOrDefault(); + .FirstOrDefaultAsync(); //تعداد @@ -76,8 +77,8 @@ namespace Back.Services } try { - - return await _repoPermissionPeriod.UpdateAsync(permissionPeriod); + var res= await _repoPermissionPeriod.UpdateAsync(permissionPeriod); + return res; //SysLog log = new SysLog() //{ // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, diff --git a/Back/Services/ServCOD.cs b/Back/Services/ServCOD.cs index 8ea2d2b..d70951e 100644 --- a/Back/Services/ServCOD.cs +++ b/Back/Services/ServCOD.cs @@ -107,7 +107,7 @@ namespace Back.Services if (item.ID == null || item.ID <= 0) { - if (await _checkPermission.ExtensionofAccess(item.CompanyID, 5, "-1")) + if (await _checkPermission.ExtensionofAccess(item.CompanyID, 4, "-1")) return await _CODRepo.AddBoolResultAsync(item); return false; diff --git a/Back/Services/servInvoice.cs b/Back/Services/servInvoice.cs index bbd0e41..df9bcb3 100644 --- a/Back/Services/servInvoice.cs +++ b/Back/Services/servInvoice.cs @@ -136,11 +136,11 @@ namespace Back.Services invoice.PreparedtoSendtoTax = false; if (calculate) { - if (await _checkPermission.ExtensionofAccess(invoice.CompanyID.Value, 3, "-1")) - { + //if (await _checkPermission.ExtensionofAccess(invoice.CompanyID.Value, 3, "-1")) + // { var item= await _invoiceRepo.AddAsync(invoice); return item.ID; - } + // } return -1; } diff --git a/TaxPayerFull/CUSComponent/InvoiceItem.razor b/TaxPayerFull/CUSComponent/InvoiceItem.razor index 9edcb41..2af6030 100644 --- a/TaxPayerFull/CUSComponent/InvoiceItem.razor +++ b/TaxPayerFull/CUSComponent/InvoiceItem.razor @@ -2,6 +2,8 @@ @using Shared.DTOs @inject HttpClientController hc; @inject Fixedvalues fv; + +
@* alert *@
@@ -13,10 +15,11 @@
-
+
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-
- - -
-
-
-
- - + +
-
+ +
+ +
+
+ + + @* *@ +
+
+ + +
+ +
+
+
+ + +
+
+ + +
+
+
+ +
+ + +
+
- +
@@ -100,13 +109,15 @@ else - } @code { + [Inject] ToastService ToastService { get; set; } = default!; + private ConfirmDialog dialog = default!; // alert AlertColor alertColor = AlertColor.Primary; IconName alertIconName = IconName.CheckCircleFill; @@ -233,22 +244,22 @@ else return; } var rsp = await hc.Put($"InvoiceItem/UpdateItem/{InvoiceID}", itemDTO); - if (rsp.IsSuccessStatusCode) + if (rsp.IsSuccessStatusCode) + { + var request = await rsp.Content.ReadFromJsonAsync(); + if (request) { - var request = await rsp.Content.ReadFromJsonAsync(); - if (request) - { - result.Status = ComponentStatus.success; - result.Action = ComponentAction.update; - await OnMultipleOfThree.InvokeAsync(result); - } - else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); - } - else - { - var request = await rsp.Content.ReadFromJsonAsync>(); - ShowDangerAlert(request[0]); + result.Status = ComponentStatus.success; + result.Action = ComponentAction.update; + await OnMultipleOfThree.InvokeAsync(result); } + else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + } + else + { + var request = await rsp.Content.ReadFromJsonAsync>(); + ShowDangerAlert(request[0]); + } } public async Task OnClickAdd() { @@ -281,19 +292,40 @@ else { var request = await rsp.Content.ReadFromJsonAsync(); - if (request) - { - result.Status = ComponentStatus.success; - result.Action = ComponentAction.add; - await OnMultipleOfThree.InvokeAsync(result); - } - else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + if (request) + { + result.Status = ComponentStatus.success; + result.Action = ComponentAction.add; + await OnMultipleOfThree.InvokeAsync(result); + } + else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); } else { var request = await rsp.Content.ReadFromJsonAsync>(); ShowDangerAlert(request[0]); } - + + } + private async Task ShowConfirmationDeleteAsync() + { + if (itemDTO.ID != null && itemDTO.ID > 0 && InvoiceID != null && InvoiceID > 0) + { + var confirmation = await dialog.ShowAsync( + title: "عملیات حذف آیتم صورتحساب", + message1: $"از حذف آیتم {itemDTO.ID} از صورتحساب {InvoiceID}", + message2: "اطمینان دارید?"); + + if (confirmation) + { + await OnClickDelete(); + } + else + { + ToastService.Notify(new ToastMessage(ToastType.Secondary, $"عملیات حذف متوقف شد")); + } + + } + } } \ No newline at end of file diff --git a/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor b/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor index 65d1bb8..699bd70 100644 --- a/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor +++ b/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor @@ -27,7 +27,8 @@
- @if (!invoice.invoiceType.HasValue) { @@ -53,7 +54,15 @@ } - + + } + else + { + + }
@@ -121,6 +130,9 @@
+ @if (InvoiceID == 0 || InvoiceID == null ? false : true) + { +

@@ -160,19 +172,21 @@
+ + }

-
- +
+
- +
-
+

@if (invoice.ID == 0) { @@ -411,8 +425,8 @@ { CustomerID = invoice.CustomerID, Des = invoice.Des, - InvoiceDate = invoice.InvoiceDate, - InvoicIssueDate = invoice.InvoicIssueDate, + InvoiceDate = invoice.InvoiceDate.Replace("/",""), + InvoicIssueDate = invoice.InvoicIssueDate.Replace("/", ""), PatternID = invoice.PatternID, Title = invoice.Title });