forked from ddrilling/AsbCloudServer
cleanup
This commit is contained in:
parent
6a338403af
commit
30a59d0809
@ -1,6 +1,6 @@
|
|||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
public class CompanyDto: IId
|
public class CompanyDto : IId
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Caption { get; set; }
|
public string Caption { get; set; }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
public class EventDto: IId
|
public class EventDto : IId
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace AsbCloudApp.Data
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Data
|
|
||||||
{
|
{
|
||||||
public class PlanFactBase<T>
|
public class PlanFactBase<T>
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace AsbCloudApp.Data
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Data
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lines container for Time Vs Depth chart
|
/// Lines container for Time Vs Depth chart
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
public class TelemetryAnalysisDto: IId
|
public class TelemetryAnalysisDto : IId
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int IdTelemetry { get; set; }
|
public int IdTelemetry { get; set; }
|
||||||
|
9
AsbCloudApp/Data/TelemetryDto.cs
Normal file
9
AsbCloudApp/Data/TelemetryDto.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
public class TelemetryDto : IId
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string RemoteUid { get; set; }
|
||||||
|
public TelemetryInfoDto Info { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ namespace AsbCloudApp.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сообщение получаемое от телеметрии
|
/// Сообщение получаемое от телеметрии
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TelemetryMessageDto: IId
|
public class TelemetryMessageDto : IId
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
11
AsbCloudApp/Data/UserRoleDto.cs
Normal file
11
AsbCloudApp/Data/UserRoleDto.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
public class UserRoleDto : IId
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Caption { get; set; }
|
||||||
|
public virtual ICollection<UserDto> Users { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -7,5 +7,6 @@
|
|||||||
public double? Latitude { get; set; }
|
public double? Latitude { get; set; }
|
||||||
public double? Longitude { get; set; }
|
public double? Longitude { get; set; }
|
||||||
public string WellType { get; set; }
|
public string WellType { get; set; }
|
||||||
|
public TelemetryDto Telemetry { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IClusterService
|
public interface IClusterService
|
||||||
{
|
{
|
||||||
Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany,
|
Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany,
|
||||||
CancellationToken token );
|
CancellationToken token);
|
||||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
||||||
int depositId, CancellationToken token );
|
int depositId, CancellationToken token);
|
||||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
||||||
CancellationToken token);
|
CancellationToken token);
|
||||||
Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany,
|
Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany,
|
||||||
|
@ -7,11 +7,15 @@ namespace AsbCloudApp.Services
|
|||||||
public interface ICrudService<Tdto>
|
public interface ICrudService<Tdto>
|
||||||
where Tdto : Data.IId
|
where Tdto : Data.IId
|
||||||
{
|
{
|
||||||
Task<Tdto> GetAsync(int id, CancellationToken token = default);
|
List<string> Incledes { get; }
|
||||||
Task<Tdto> InsertAsync(Tdto newItem, CancellationToken token = default);
|
|
||||||
Task<IEnumerable<Tdto>> InsertRangeAsync(IEnumerable<Tdto> newItems, CancellationToken token = default);
|
|
||||||
Task<Tdto> UpdateAsync(Tdto item, CancellationToken token = default);
|
|
||||||
Task<int> DeleteAsync(int id, CancellationToken token = default);
|
Task<int> DeleteAsync(int id, CancellationToken token = default);
|
||||||
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default);
|
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default);
|
||||||
|
Task<IEnumerable<Tdto>> GetAllAsync(CancellationToken token = default);
|
||||||
|
Task<Tdto> GetAsync(int id, CancellationToken token = default);
|
||||||
|
Task<Data.PaginationContainer<Tdto>> GetPageAsync(int skip = 0, int take = 32, CancellationToken token = default);
|
||||||
|
Task<int> InsertAsync(Tdto newItem, CancellationToken token = default);
|
||||||
|
Task<int> InsertRangeAsync(IEnumerable<Tdto> newItems, CancellationToken token = default);
|
||||||
|
Task<int> UpdateAsync(int id, Tdto item, CancellationToken token = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using AsbCloudApp.Data;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Services
|
namespace AsbCloudApp.Services
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using AsbCloudDb.Model;
|
||||||
using System.Collections.Generic;
|
|
||||||
using AsbCloudDb.Model;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AsbCloudDb.Migrations
|
namespace AsbCloudDb.Migrations
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Data.Common;
|
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@ -41,11 +41,15 @@ namespace AsbCloudDb.Model
|
|||||||
//var context = new AsbCloudDbContext(options);
|
//var context = new AsbCloudDbContext(options);
|
||||||
|
|
||||||
public AsbCloudDbContext() : base()
|
public AsbCloudDbContext() : base()
|
||||||
{ }
|
{
|
||||||
|
Database.Migrate();
|
||||||
|
}
|
||||||
|
|
||||||
public AsbCloudDbContext(DbContextOptions<AsbCloudDbContext> options)
|
public AsbCloudDbContext(DbContextOptions<AsbCloudDbContext> options)
|
||||||
: base(options)
|
: base(options)
|
||||||
{ }
|
{
|
||||||
|
Database.Migrate();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
@ -290,7 +294,8 @@ namespace AsbCloudDb.Model
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<WellSectionType>(entity => {
|
modelBuilder.Entity<WellSectionType>(entity =>
|
||||||
|
{
|
||||||
entity.HasData(new List<WellSectionType>{
|
entity.HasData(new List<WellSectionType>{
|
||||||
new WellSectionType{ Id = 1, Caption = "Пилотный ствол"},
|
new WellSectionType{ Id = 1, Caption = "Пилотный ствол"},
|
||||||
new WellSectionType{ Id = 2, Caption = "Направление"},
|
new WellSectionType{ Id = 2, Caption = "Направление"},
|
||||||
@ -301,14 +306,16 @@ namespace AsbCloudDb.Model
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<WellType>(entity => {
|
modelBuilder.Entity<WellType>(entity =>
|
||||||
|
{
|
||||||
entity.HasData(new List<WellType> {
|
entity.HasData(new List<WellType> {
|
||||||
new WellType{ Id = 1, Caption = "Наклонно-направленная"},
|
new WellType{ Id = 1, Caption = "Наклонно-направленная"},
|
||||||
new WellType{ Id = 2, Caption = "Горизонтальная"},
|
new WellType{ Id = 2, Caption = "Горизонтальная"},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<MeasureCategory>(entity => {
|
modelBuilder.Entity<MeasureCategory>(entity =>
|
||||||
|
{
|
||||||
entity.HasData(new List<MeasureCategory> {
|
entity.HasData(new List<MeasureCategory> {
|
||||||
new MeasureCategory{ Id = 1, Name = "Показатели бурового раствора", ShortName = "Раствор"},
|
new MeasureCategory{ Id = 1, Name = "Показатели бурового раствора", ShortName = "Раствор"},
|
||||||
new MeasureCategory{ Id = 2, Name = "Шламограмма", ShortName = "Шламограмма"},
|
new MeasureCategory{ Id = 2, Name = "Шламограмма", ShortName = "Шламограмма"},
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace AsbCloudDb.Model
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For well related entities
|
/// For well related entities
|
||||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_relation_company_well"), Comment("отношение скважин и компаний")]
|
[Table("t_relation_company_well"), Comment("отношение скважин и компаний")]
|
||||||
public partial class RelationCompanyWell: IIdWell
|
public partial class RelationCompanyWell : IIdWell
|
||||||
{
|
{
|
||||||
[Column("id_well")]
|
[Column("id_well")]
|
||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_report_property"), Comment("Отчеты с данными по буровым")]
|
[Table("t_report_property"), Comment("Отчеты с данными по буровым")]
|
||||||
public class ReportProperty: IId, IIdWell
|
public class ReportProperty : IId, IIdWell
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
4
AsbCloudDb/Readme.md
Normal file
4
AsbCloudDb/Readme.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Применить миграции
|
||||||
|
```
|
||||||
|
dotnet ef database update --project .\AsbCloudDb
|
||||||
|
```
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using AsbCloudDb.Model;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using AsbCloudDb.Model;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AsbCloudDbDemoData
|
namespace AsbCloudDbDemoData
|
||||||
{
|
{
|
||||||
@ -12,7 +12,7 @@ namespace AsbCloudDbDemoData
|
|||||||
Console.WriteLine("Заполнить БД тестовыми данными? y/n");
|
Console.WriteLine("Заполнить БД тестовыми данными? y/n");
|
||||||
string result = Console.ReadLine();
|
string result = Console.ReadLine();
|
||||||
|
|
||||||
if(result != "y")
|
if (result != "y")
|
||||||
{
|
{
|
||||||
Console.WriteLine("Хорошо, в другой раз.");
|
Console.WriteLine("Хорошо, в другой раз.");
|
||||||
return;
|
return;
|
||||||
@ -299,7 +299,7 @@ namespace AsbCloudDbDemoData
|
|||||||
else
|
else
|
||||||
Console.WriteLine("Ошибка при добавлении данных");
|
Console.WriteLine("Ошибка при добавлении данных");
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,15 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<IMeasureService, MeasureService>();
|
services.AddTransient<IMeasureService, MeasureService>();
|
||||||
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
||||||
|
|
||||||
|
// admin crud services:
|
||||||
|
services.AddTransient<ICrudService<DepositDto>, CrudServiceBase<DepositDto, Deposit>>();
|
||||||
|
services.AddTransient<ICrudService<ClusterDto>, CrudServiceBase<ClusterDto, Cluster>>();
|
||||||
|
services.AddTransient<ICrudService<WellDto>, CrudServiceBase<WellDto, Well>>();
|
||||||
|
services.AddTransient<ICrudService<CompanyDto>, CrudServiceBase<CompanyDto, Company>>();
|
||||||
|
services.AddTransient<ICrudService<UserDto>, CrudServiceBase<UserDto, User>>();
|
||||||
|
services.AddTransient<ICrudService<UserRoleDto>, CrudServiceBase<UserRoleDto, UserRole>>();
|
||||||
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure
|
namespace AsbCloudInfrastructure
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ namespace AsbCloudInfrastructure.Services.Cache
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// ignore
|
// ignore
|
||||||
// TODO: figure out what the well
|
// TODO: figure out what the hell
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -16,46 +18,79 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
protected readonly IAsbCloudDbContext context;
|
protected readonly IAsbCloudDbContext context;
|
||||||
protected readonly DbSet<TModel> dbSet;
|
protected readonly DbSet<TModel> dbSet;
|
||||||
|
|
||||||
|
public List<string> Incledes { get; } = new List<string>();
|
||||||
|
|
||||||
public CrudServiceBase(IAsbCloudDbContext context)
|
public CrudServiceBase(IAsbCloudDbContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
dbSet = context.Set<TModel>();
|
dbSet = context.Set<TModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<Tdto> GetAsync(int id, CancellationToken token = default)
|
public virtual async Task<PaginationContainer<Tdto>> GetPageAsync(int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var entity = await dbSet.AsNoTracking()
|
var query = GetQueryWithIncludes();
|
||||||
.FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
|
var count = await query
|
||||||
var dto = entity.Adapt<Tdto>();
|
.CountAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
var container = new PaginationContainer<Tdto>
|
||||||
|
{
|
||||||
|
Skip = skip,
|
||||||
|
Take = take,
|
||||||
|
Count = count,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (skip >= count)
|
||||||
|
return container;
|
||||||
|
|
||||||
|
var entities = await query
|
||||||
|
.ToListAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
container.Items = entities
|
||||||
|
.Select(entity => Convert(entity))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IEnumerable<Tdto>> GetAllAsync(CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var query = GetQueryWithIncludes();
|
||||||
|
var entities = await query
|
||||||
|
.ToListAsync(token).ConfigureAwait(false);
|
||||||
|
var dto = entities.Select(entity => Convert(entity));
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<Tdto> InsertAsync(Tdto newItem, CancellationToken token = default)
|
public virtual async Task<Tdto> GetAsync(int id, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var newEntity = newItem.Adapt<TModel>();
|
var query = GetQueryWithIncludes();
|
||||||
var dbEntity = dbSet.Add(newEntity);
|
var entity = await query
|
||||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
.FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
|
||||||
return dbEntity.Entity.Adapt<Tdto>();
|
var dto = Convert(entity);
|
||||||
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<IEnumerable<Tdto>> InsertRangeAsync(IEnumerable<Tdto> newItems, CancellationToken token = default)
|
public virtual Task<int> InsertAsync(Tdto item, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var newEntities = newItems.Adapt<IEnumerable<TModel>>();
|
var entity = Convert(item);
|
||||||
var dbEntities = new Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TModel>[newItems.Count()];
|
dbSet.Add(entity);
|
||||||
|
return context.SaveChangesAsync(token);
|
||||||
for (int i = 0; i < dbEntities.Length; i++)
|
|
||||||
dbEntities[i] = dbSet.Add(newEntities.ElementAt(i));
|
|
||||||
|
|
||||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
|
||||||
return dbEntities.Select(e => e.Entity.Adapt<Tdto>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<Tdto> UpdateAsync(Tdto item, CancellationToken token = default)
|
public virtual Task<int> InsertRangeAsync(IEnumerable<Tdto> items, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var newEntity = item.Adapt<TModel>();
|
var entities = items.Select(i => Convert(i));
|
||||||
var dbEntity = dbSet.Update(newEntity);
|
dbSet.AddRange(entities);
|
||||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
return context.SaveChangesAsync(token);
|
||||||
return dbEntity.Entity.Adapt<Tdto>();
|
}
|
||||||
|
|
||||||
|
public virtual Task<int> UpdateAsync(int id, Tdto item, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var entity = Convert(item);
|
||||||
|
dbSet.Update(entity);
|
||||||
|
return context.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<int> DeleteAsync(int id, CancellationToken token = default)
|
public virtual Task<int> DeleteAsync(int id, CancellationToken token = default)
|
||||||
@ -76,5 +111,17 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
dbSet.RemoveRange(entities);
|
dbSet.RemoveRange(entities);
|
||||||
return context.SaveChangesAsync(token);
|
return context.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual Tdto Convert(TModel src) => src.Adapt<Tdto>();
|
||||||
|
|
||||||
|
public virtual TModel Convert(Tdto src) => src.Adapt<TModel>();
|
||||||
|
|
||||||
|
private IQueryable<TModel> GetQueryWithIncludes()
|
||||||
|
{
|
||||||
|
IQueryable<TModel> query = dbSet;
|
||||||
|
foreach (var include in Incledes)
|
||||||
|
query = query.Include(include);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
using System;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using NPOI.SS.UserModel;
|
||||||
|
using NPOI.XSSF.UserModel;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data;
|
|
||||||
using AsbCloudApp.Services;
|
|
||||||
using AsbCloudDb.Model;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using NPOI.SS.UserModel;
|
|
||||||
using NPOI.XSSF.UserModel;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -39,7 +36,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (matchFiles is not null && matchFiles.Any()) {
|
if (matchFiles is not null && matchFiles.Any())
|
||||||
|
{
|
||||||
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
||||||
var matchFilesIterator = matchFiles.GetEnumerator();
|
var matchFilesIterator = matchFiles.GetEnumerator();
|
||||||
matchFilesIterator.MoveNext();
|
matchFilesIterator.MoveNext();
|
||||||
|
8
AsbCloudInfrastructure/Services/ICachedCrudService.cs
Normal file
8
AsbCloudInfrastructure/Services/ICachedCrudService.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services
|
||||||
|
{
|
||||||
|
public interface ICachedCrudService<Tdto> where Tdto : IId
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
|
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
var entities = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
var entities = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
||||||
var dto = entities.ToDictionary(e=>e.Id, e=>e.Name);
|
var dto = entities.ToDictionary(e => e.Id, e => e.Name);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Services.Cache;
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Mapster;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -139,6 +139,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (!wellOperations.Any())
|
if (!wellOperations.Any())
|
||||||
return new StatWellDto()
|
return new StatWellDto()
|
||||||
{
|
{
|
||||||
|
Id = idWell,
|
||||||
Caption = well.Caption,
|
Caption = well.Caption,
|
||||||
WellType = wellType.Caption
|
WellType = wellType.Caption
|
||||||
};
|
};
|
||||||
@ -329,7 +330,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
foreach (var race in races)
|
foreach (var race in races)
|
||||||
{
|
{
|
||||||
dDepth += race.EndWellDepth;
|
dDepth += race.EndWellDepth;
|
||||||
for (var i = race.Operations.Count -1; i > 0 ; i--)
|
for (var i = race.Operations.Count - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
if (race.Operations[i].IdCategory == idOperationBhaUp)
|
if (race.Operations[i].IdCategory == idOperationBhaUp)
|
||||||
dHours += race.Operations[i].Hours;
|
dHours += race.Operations[i].Hours;
|
||||||
|
@ -80,8 +80,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public async Task<WellDto> GetAsync(int idWell, CancellationToken token)
|
public async Task<WellDto> GetAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = await db.Wells
|
var entity = await db.Wells
|
||||||
.Include(w=>w.Cluster)
|
.Include(w => w.Cluster)
|
||||||
.ThenInclude(c=>c.Deposit)
|
.ThenInclude(c => c.Deposit)
|
||||||
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
@ -100,8 +100,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public async Task<IEnumerable<CompanyDto>> GetCompaniesAsync(int idWell, CancellationToken token)
|
public async Task<IEnumerable<CompanyDto>> GetCompaniesAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var well = await db.Wells
|
var well = await db.Wells
|
||||||
.Include(w=>w.RelationCompaniesWells)
|
.Include(w => w.RelationCompaniesWells)
|
||||||
.ThenInclude(r=>r.Company)
|
.ThenInclude(r => r.Company)
|
||||||
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
var companies = well.RelationCompaniesWells.Select(r => r.Company);
|
var companies = well.RelationCompaniesWells.Select(r => r.Company);
|
||||||
|
47
AsbCloudInfrastructure/Services/_CachedCrudService.cs
Normal file
47
AsbCloudInfrastructure/Services/_CachedCrudService.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services
|
||||||
|
{
|
||||||
|
public class _CachedCrudService<Tdto, TModel> : ICachedCrudService<Tdto>
|
||||||
|
where TModel : class, AsbCloudDb.Model.IId
|
||||||
|
where Tdto : AsbCloudApp.Data.IId
|
||||||
|
{
|
||||||
|
private readonly CacheTable<TModel> cache;
|
||||||
|
|
||||||
|
public _CachedCrudService(IAsbCloudDbContext db, Cache.CacheDb cacheDb)
|
||||||
|
{
|
||||||
|
cache = cacheDb.GetCachedTable<TModel>((DbContext)db);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<PaginationContainer<Tdto>> GetAsync(int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var count = cache.Count();
|
||||||
|
var result = new PaginationContainer<Tdto> { Skip = skip, Take = take, Count = count };
|
||||||
|
if (count <= skip)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var items = await cache.WhereAsync(token).ConfigureAwait(false);
|
||||||
|
|
||||||
|
result.Items.AddRange(items.OrderBy(i => i.Id).Skip(skip).Take(take).Select(i => Convert(i)));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Task<Tdto> GetAsync(int id, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Tdto Convert(TModel src) => src.Adapt<Tdto>();
|
||||||
|
|
||||||
|
public virtual TModel Convert(Tdto src) => src.Adapt<TModel>();
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminClusterController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminClusterController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/cluster")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminClusterController : CrudController<ClusterDto, ICrudService<ClusterDto>>
|
||||||
|
{
|
||||||
|
public AdminClusterController(ICrudService<ClusterDto> service)
|
||||||
|
:base(service)
|
||||||
|
{
|
||||||
|
service.Incledes.Add("Wells");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminCompanyController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminCompanyController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/company")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminCompanyController : CrudController<CompanyDto, ICrudService<CompanyDto>>
|
||||||
|
{
|
||||||
|
public AdminCompanyController(ICrudService<CompanyDto> service)
|
||||||
|
: base(service)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminDepositController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminDepositController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/deposit")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminDepositController : CrudController<DepositDto, ICrudService<DepositDto>>
|
||||||
|
{
|
||||||
|
public AdminDepositController(ICrudService<DepositDto> service)
|
||||||
|
:base(service)
|
||||||
|
{
|
||||||
|
service.Incledes.Add("Clusters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminTelemetryController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminTelemetryController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/telemetry")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminTelemetryController : CrudController<TelemetryDto, ICrudService<TelemetryDto>>
|
||||||
|
{
|
||||||
|
public AdminTelemetryController(ICrudService<TelemetryDto> service)
|
||||||
|
: base(service)
|
||||||
|
{
|
||||||
|
service.Incledes.Add("Well");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminUserController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminUserController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/user")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminUserController : CrudController<UserDto, ICrudService<UserDto>>
|
||||||
|
{
|
||||||
|
public AdminUserController(ICrudService<UserDto> service)
|
||||||
|
: base(service)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminUserRoleController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminUserRoleController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/user/role")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminUserRoleController : CrudController<UserRoleDto, ICrudService<UserRoleDto>>
|
||||||
|
{
|
||||||
|
public AdminUserRoleController(ICrudService<UserRoleDto> service)
|
||||||
|
: base(service)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
AsbCloudWebApi/Controllers/AdminWellController.cs
Normal file
19
AsbCloudWebApi/Controllers/AdminWellController.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/admin/well")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class AdminWellController : CrudController<WellDto, ICrudService<WellDto>>
|
||||||
|
{
|
||||||
|
public AdminWellController(ICrudService<WellDto> service)
|
||||||
|
:base(service)
|
||||||
|
{
|
||||||
|
service.Incledes.Add("Telemetry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,54 +1,114 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// CRUD контроллер для админки.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="TService"></typeparam>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public abstract class CrudController<T, TService> : ControllerBase
|
public abstract class CrudController<T, TService> : ControllerBase
|
||||||
where T : IId
|
where T : IId
|
||||||
where TService : ICrudService<T>
|
where TService : ICrudService<T>
|
||||||
{
|
{
|
||||||
protected readonly TService service;
|
protected readonly TService service;
|
||||||
|
|
||||||
|
public List<string> Roles { get; } = new List<string> { "Администратор" };
|
||||||
|
|
||||||
public CrudController(TService service)
|
public CrudController(TService service)
|
||||||
{
|
{
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/<CrudController>/5
|
/// <summary>
|
||||||
|
/// Получить страницу с записями в PaginationContainer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="skip">пропустить skip записей</param>
|
||||||
|
/// <param name="take">получить take записей</param>
|
||||||
|
/// <param name="token">CancellationToken</param>
|
||||||
|
/// <returns>страница с записями в PaginationContainer</returns>
|
||||||
|
[HttpGet()]
|
||||||
|
public virtual async Task<IActionResult> GetPage(int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!Roles.Any(role => User.IsInRole(role)))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await service.GetPageAsync(skip, take, token).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить одну запись по Id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id записи</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>запись</returns>
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
|
public virtual async Task<IActionResult> Get(int id, CancellationToken token = default)
|
||||||
public virtual IActionResult Get(int id, CancellationToken token = default)
|
|
||||||
{
|
{
|
||||||
var result = service.GetAsync(id, token).ConfigureAwait(false);
|
if (!Roles.Any(role => User.IsInRole(role)))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await service.GetAsync(id, token).ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<CrudController>
|
/// <summary>
|
||||||
|
/// Добавить запись
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">запись</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>1 - добавлено, 0 - нет</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public virtual IActionResult Insert([FromBody] T value, CancellationToken token = default)
|
public virtual async Task<IActionResult> Insert([FromBody] T value, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var result = service.InsertAsync(value, token).ConfigureAwait(false);
|
if (!Roles.Any(role => User.IsInRole(role)))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await service.InsertAsync(value, token).ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<CrudController>/5
|
/// <summary>
|
||||||
|
/// Редактировать запись по id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id записи</param>
|
||||||
|
/// <param name="value">запись</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>1 - успешно отредактировано, 0 - нет</returns>
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public virtual IActionResult Put(int id, [FromBody] T value, CancellationToken token = default)
|
public virtual async Task<IActionResult> Put(int id, [FromBody] T value, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var result = service.UpdateAsync(value, token).ConfigureAwait(false);
|
if (!Roles.Any(role => User.IsInRole(role)))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await service.UpdateAsync(id, value, token).ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<CrudController>/5
|
/// <summary>
|
||||||
|
/// Удалить запись по id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id записи</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>1 - успешно удалено, 0 - нет</returns>
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public virtual IActionResult Delete(int id, CancellationToken token = default)
|
public virtual async Task<IActionResult> Delete(int id, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var result = service.DeleteAsync(id, token).ConfigureAwait(false);
|
if (!Roles.Any(role => User.IsInRole(role)))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await service.DeleteAsync(id, token).ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user