forked from ddrilling/AsbCloudServer
Merge branch 'master' of https://bitbucket.org/autodrilling/asbcloudserver
This commit is contained in:
commit
3017d6d990
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class ClusterDto : IMapPoint
|
||||
public class ClusterDto : IMapPoint, IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class CompanyDto
|
||||
public class CompanyDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class DepositDto : IMapPoint
|
||||
public class DepositDto : IMapPoint, IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class EventDto
|
||||
public class EventDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class FileInfoDto
|
||||
public class FileInfoDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int IdWell { get; set; }
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class MeasureDto
|
||||
public class MeasureDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace AsbCloudApp.Data
|
||||
/// <summary>
|
||||
/// Сообщение для frontend
|
||||
/// </summary>
|
||||
public class MessageDto
|
||||
public class MessageDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class PlanFactBase<T>
|
||||
{
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Lines container for Time Vs Depth chart
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class ReportPropertiesDto
|
||||
public class ReportPropertiesDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class StatClusterDto //: ClusterDto
|
||||
public class StatClusterDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
|
@ -1,8 +1,8 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class StatSectionDto : PlanFactBase<StatOperationsDto>
|
||||
public class StatSectionDto : PlanFactBase<StatOperationsDto>, IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public string Caption { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class StatWellDto //: WellDto
|
||||
public class StatWellDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Caption { get; set; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class TelemetryAnalysisDto
|
||||
public class TelemetryAnalysisDto : IId
|
||||
{
|
||||
public int Id { 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>
|
||||
public class TelemetryMessageDto
|
||||
public class TelemetryMessageDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class TelemetryOperationDto
|
||||
public class TelemetryOperationDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class TelemetryUserDto
|
||||
public class TelemetryUserDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class UserDto : UserBaseDto
|
||||
public class UserDto : UserBaseDto, IId
|
||||
{
|
||||
public int Id { 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? Longitude { get; set; }
|
||||
public string WellType { get; set; }
|
||||
public TelemetryDto Telemetry { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
int ChangePassword(int idUser, string newPassword);
|
||||
int ChangePassword(string userLogin, string newPassword);
|
||||
Task<UserTokenDto> LoginAsync(string login,
|
||||
Task<UserTokenDto> LoginAsync(string login,
|
||||
string password, CancellationToken token = default);
|
||||
|
||||
string Refresh(ClaimsPrincipal user);
|
||||
|
@ -7,13 +7,13 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IClusterService
|
||||
{
|
||||
Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany,
|
||||
CancellationToken token );
|
||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
||||
int depositId, CancellationToken token );
|
||||
Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany,
|
||||
CancellationToken token);
|
||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
||||
int depositId, CancellationToken token);
|
||||
Task<IEnumerable<ClusterDto>> GetClustersAsync(int idCompany,
|
||||
CancellationToken token);
|
||||
Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany,
|
||||
Task<IEnumerable<WellDto>> GetWellsAsync(int idCompany,
|
||||
int clusterId, CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,15 @@ namespace AsbCloudApp.Services
|
||||
public interface ICrudService<Tdto>
|
||||
where Tdto : Data.IId
|
||||
{
|
||||
Task<Tdto> GetAsync(int id, CancellationToken token = default);
|
||||
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);
|
||||
List<string> Incledes { get; }
|
||||
|
||||
Task<int> DeleteAsync(int id, 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);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IDataService
|
||||
{
|
||||
Task<IEnumerable<DataSaubBaseDto>> GetAsync(int idWell, DateTime dateBegin = default,
|
||||
Task<IEnumerable<DataSaubBaseDto>> GetAsync(int idWell, DateTime dateBegin = default,
|
||||
double intervalSec = 600d, int approxPointsCount = 1024,
|
||||
CancellationToken token = default);
|
||||
|
||||
|
@ -7,7 +7,7 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IEventService
|
||||
{
|
||||
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
||||
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
||||
CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -8,9 +8,9 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IMessageService
|
||||
{
|
||||
Task<PaginationContainer<MessageDto>> GetMessagesAsync(int idWell,
|
||||
IEnumerable<int> categoryids = null, DateTime begin = default,
|
||||
DateTime end = default, string searchString = default,
|
||||
Task<PaginationContainer<MessageDto>> GetMessagesAsync(int idWell,
|
||||
IEnumerable<int> categoryids = null, DateTime begin = default,
|
||||
DateTime end = default, string searchString = default,
|
||||
int skip = 0, int take = 32, CancellationToken token = default);
|
||||
Task<DatesRangeDto> GetMessagesDatesRangeAsync(int idWell,
|
||||
CancellationToken token = default);
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
@ -28,7 +28,7 @@ namespace AsbCloudApp.Services
|
||||
Task<int> InsertRangeAsync(int idWell,
|
||||
IEnumerable<WellOperationDto> wellOperationDtos, CancellationToken token);
|
||||
|
||||
Task<int> UpdateAsync(int idWell, int idOperation, WellOperationDto item,
|
||||
Task<int> UpdateAsync(int idWell, int idOperation, WellOperationDto item,
|
||||
CancellationToken token);
|
||||
|
||||
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token);
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.Common;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@ -41,11 +41,15 @@ namespace AsbCloudDb.Model
|
||||
//var context = new AsbCloudDbContext(options);
|
||||
|
||||
public AsbCloudDbContext() : base()
|
||||
{ }
|
||||
{
|
||||
Database.Migrate();
|
||||
}
|
||||
|
||||
public AsbCloudDbContext(DbContextOptions<AsbCloudDbContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
{
|
||||
Database.Migrate();
|
||||
}
|
||||
|
||||
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>{
|
||||
new WellSectionType{ Id = 1, Caption = "Пилотный ствол"},
|
||||
new WellSectionType{ Id = 2, Caption = "Направление"},
|
||||
@ -301,15 +306,17 @@ namespace AsbCloudDb.Model
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity<WellType>(entity => {
|
||||
entity.HasData(new List<WellType> {
|
||||
modelBuilder.Entity<WellType>(entity =>
|
||||
{
|
||||
entity.HasData(new List<WellType> {
|
||||
new WellType{ Id = 1, Caption = "Наклонно-направленная"},
|
||||
new WellType{ Id = 2, Caption = "Горизонтальная"},
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MeasureCategory>(entity => {
|
||||
entity.HasData(new List<MeasureCategory> {
|
||||
modelBuilder.Entity<MeasureCategory>(entity =>
|
||||
{
|
||||
entity.HasData(new List<MeasureCategory> {
|
||||
new MeasureCategory{ Id = 1, Name = "Показатели бурового раствора", ShortName = "Раствор"},
|
||||
new MeasureCategory{ Id = 2, Name = "Шламограмма", ShortName = "Шламограмма"},
|
||||
new MeasureCategory{ Id = 3, Name = "ННБ", ShortName = "ННБ"},
|
||||
|
@ -7,7 +7,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_company_type")]
|
||||
public partial class CompanyType
|
||||
public partial class CompanyType : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// For well related entities
|
||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_relation_company_well"), Comment("отношение скважин и компаний")]
|
||||
public partial class RelationCompanyWell: IIdWell
|
||||
public partial class RelationCompanyWell : IIdWell
|
||||
{
|
||||
[Column("id_well")]
|
||||
public int IdWell { get; set; }
|
||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_report_property"), Comment("Отчеты с данными по буровым")]
|
||||
public class ReportProperty: IId, IIdWell
|
||||
public class ReportProperty : IId, IIdWell
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
@ -7,7 +7,7 @@ namespace AsbCloudDb.Model
|
||||
{
|
||||
|
||||
[Table("t_telemetry_analysis"), Comment("События на скважине")]
|
||||
public class TelemetryAnalysis
|
||||
public class TelemetryAnalysis : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
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.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -7,11 +7,8 @@ using System.Text.Json.Serialization;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_well_operation"), Comment("Данные по операциям на скважине")]
|
||||
public class WellOperation
|
||||
public class WellOperation : IId
|
||||
{
|
||||
public WellOperation ShallowCopy() =>
|
||||
(WellOperation) MemberwiseClone();
|
||||
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_well_operation_category"), Comment("Справочник операций на скважине")]
|
||||
public class WellOperationCategory
|
||||
public class WellOperationCategory : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
@ -8,7 +8,7 @@ using System.Text.Json.Serialization;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_well_section_type"), Comment("конструкция секции скважины")]
|
||||
public class WellSectionType
|
||||
public class WellSectionType : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
@ -8,7 +8,7 @@ using System.Text.Json.Serialization;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_well_type"), Comment("конструкция скважины")]
|
||||
public class WellType
|
||||
public class WellType : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
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 System.Collections.Generic;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AsbCloudDb.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudDbDemoData
|
||||
{
|
||||
@ -12,7 +12,7 @@ namespace AsbCloudDbDemoData
|
||||
Console.WriteLine("Заполнить БД тестовыми данными? y/n");
|
||||
string result = Console.ReadLine();
|
||||
|
||||
if(result != "y")
|
||||
if (result != "y")
|
||||
{
|
||||
Console.WriteLine("Хорошо, в другой раз.");
|
||||
return;
|
||||
@ -299,7 +299,7 @@ namespace AsbCloudDbDemoData
|
||||
else
|
||||
Console.WriteLine("Ошибка при добавлении данных");
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
@ -41,6 +41,15 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IMeasureService, MeasureService>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ namespace Mapster
|
||||
eachAfterMapAction(dest, item);
|
||||
yield return dest;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ namespace AsbCloudInfrastructure.Services.Cache
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
// TODO: figure out what the well
|
||||
// TODO: figure out what the hell
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
var dbEntities = context.Set<TEntity>().AsNoTracking().ToList();
|
||||
cached.AddRange(dbEntities);
|
||||
|
@ -1,7 +1,9 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -16,46 +18,79 @@ namespace AsbCloudInfrastructure.Services
|
||||
protected readonly IAsbCloudDbContext context;
|
||||
protected readonly DbSet<TModel> dbSet;
|
||||
|
||||
public List<string> Incledes { get; } = new List<string>();
|
||||
|
||||
public CrudServiceBase(IAsbCloudDbContext context)
|
||||
{
|
||||
this.context = context;
|
||||
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()
|
||||
.FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
|
||||
var dto = entity.Adapt<Tdto>();
|
||||
var query = GetQueryWithIncludes();
|
||||
var count = await query
|
||||
.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;
|
||||
}
|
||||
|
||||
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 dbEntity = dbSet.Add(newEntity);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
return dbEntity.Entity.Adapt<Tdto>();
|
||||
var query = GetQueryWithIncludes();
|
||||
var entity = await query
|
||||
.FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
|
||||
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 dbEntities = new Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TModel>[newItems.Count()];
|
||||
|
||||
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>());
|
||||
var entity = Convert(item);
|
||||
dbSet.Add(entity);
|
||||
return context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
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 dbEntity = dbSet.Update(newEntity);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
return dbEntity.Entity.Adapt<Tdto>();
|
||||
var entities = items.Select(i => Convert(i));
|
||||
dbSet.AddRange(entities);
|
||||
return context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
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)
|
||||
@ -76,5 +111,17 @@ namespace AsbCloudInfrastructure.Services
|
||||
dbSet.RemoveRange(entities);
|
||||
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.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
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
|
||||
{
|
||||
@ -39,7 +36,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (matchFiles is not null && matchFiles.Any()) {
|
||||
if (matchFiles is not null && matchFiles.Any())
|
||||
{
|
||||
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
||||
var matchFilesIterator = matchFiles.GetEnumerator();
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Mapster;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
@ -138,7 +138,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
if (!wellOperations.Any())
|
||||
return new StatWellDto()
|
||||
{
|
||||
{
|
||||
Id = idWell,
|
||||
Caption = well.Caption,
|
||||
WellType = wellType.Caption
|
||||
};
|
||||
@ -174,7 +175,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
StatSectionDto section = new StatSectionDto
|
||||
{
|
||||
Id = id,
|
||||
Caption = sectionType.Caption,
|
||||
Caption = sectionType.Caption,
|
||||
Plan = CalcSectionStat(operationsPlan, id),
|
||||
Fact = CalcSectionStat(operationsFact, id),
|
||||
};
|
||||
@ -201,7 +202,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
.Where(o => o.IdWellSectionType == idSectionType)
|
||||
.OrderBy(o => o.Start)
|
||||
.ThenBy(o => o.WellDepth);
|
||||
|
||||
|
||||
return CalcStat(sectionOperations);
|
||||
}
|
||||
|
||||
@ -329,7 +330,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
foreach (var race in races)
|
||||
{
|
||||
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)
|
||||
dHours += race.Operations[i].Hours;
|
||||
@ -468,8 +469,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
return m;
|
||||
}
|
||||
|
||||
private static readonly Action<WellOperationDto, WellOperation> WellOperationDtoMutation = (WellOperationDto dest, WellOperation source) =>
|
||||
{
|
||||
private static readonly Action<WellOperationDto, WellOperation> WellOperationDtoMutation = (WellOperationDto dest, WellOperation source) =>
|
||||
{
|
||||
dest.CategoryName = source.OperationCategory?.Name;
|
||||
dest.WellSectionTypeName = source.WellSectionType?.Caption;
|
||||
};
|
||||
|
@ -80,8 +80,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
public async Task<WellDto> GetAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var entity = await db.Wells
|
||||
.Include(w=>w.Cluster)
|
||||
.ThenInclude(c=>c.Deposit)
|
||||
.Include(w => w.Cluster)
|
||||
.ThenInclude(c => c.Deposit)
|
||||
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@ -100,8 +100,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
public async Task<IEnumerable<CompanyDto>> GetCompaniesAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = await db.Wells
|
||||
.Include(w=>w.RelationCompaniesWells)
|
||||
.ThenInclude(r=>r.Company)
|
||||
.Include(w => w.RelationCompaniesWells)
|
||||
.ThenInclude(r => r.Company)
|
||||
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
||||
.ConfigureAwait(false);
|
||||
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.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
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
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// CRUD контроллер для админки.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TService"></typeparam>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public abstract class CrudController<T, TService> : ControllerBase
|
||||
where T : IId
|
||||
where TService : ICrudService<T>
|
||||
{
|
||||
protected readonly TService service;
|
||||
|
||||
public List<string> Roles { get; } = new List<string> { "Администратор" };
|
||||
|
||||
public CrudController(TService 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}")]
|
||||
|
||||
public virtual IActionResult Get(int id, CancellationToken token = default)
|
||||
public virtual async Task<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);
|
||||
}
|
||||
|
||||
// POST api/<CrudController>
|
||||
/// <summary>
|
||||
/// Добавить запись
|
||||
/// </summary>
|
||||
/// <param name="value">запись</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>1 - добавлено, 0 - нет</returns>
|
||||
[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);
|
||||
}
|
||||
|
||||
// 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}")]
|
||||
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);
|
||||
}
|
||||
|
||||
// DELETE api/<CrudController>/5
|
||||
/// <summary>
|
||||
/// Удалить запись по id
|
||||
/// </summary>
|
||||
/// <param name="id">id записи</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>1 - успешно удалено, 0 - нет</returns>
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user