forked from ddrilling/AsbCloudServer
Проверка создания суточного рапорта: если он есть в базе, то нужно возвращать ошибку
This commit is contained in:
parent
0d16d09ad7
commit
4545325a93
@ -76,19 +76,26 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
|||||||
if (well is null || well.Timezone is null)
|
if (well is null || well.Timezone is null)
|
||||||
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
||||||
|
|
||||||
|
var startDateOnly = new DateOnly(startDate.Date.Year, startDate.Date.Month, startDate.Date.Day);
|
||||||
|
|
||||||
|
var entity = await db.DailyReports
|
||||||
|
.FirstOrDefaultAsync(r => r.IdWell == idWell && r.StartDate == startDateOnly, token);
|
||||||
|
if (entity is not null)
|
||||||
|
throw new ArgumentInvalidException("daily report already exists", nameof(idWell));
|
||||||
|
|
||||||
var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1);
|
var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1);
|
||||||
var contractor = well.Companies.FirstOrDefault(company => company.IdCompanyType == 2);
|
var contractor = well.Companies.FirstOrDefault(company => company.IdCompanyType == 2);
|
||||||
|
|
||||||
var entity = new AsbCloudDb.Model.DailyReport.DailyReport
|
entity = new AsbCloudDb.Model.DailyReport.DailyReport
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
StartDate = new DateOnly(startDate.Date.Year, startDate.Date.Month, startDate.Date.Day),
|
StartDate = startDateOnly,
|
||||||
Info = new DailyReportInfo() {
|
Info = new DailyReportInfo() {
|
||||||
Head = new Head()
|
Head = new Head()
|
||||||
{
|
{
|
||||||
ReportDate = startDate.Date,
|
ReportDate = startDate.Date,
|
||||||
WellName = well.Caption,
|
WellName = well.Caption,
|
||||||
ClusterName = well.Cluster,
|
ClusterName = well?.Cluster ?? String.Empty,
|
||||||
Customer = customer?.Caption ?? String.Empty,
|
Customer = customer?.Caption ?? String.Empty,
|
||||||
Contractor = contractor?.Caption ?? String.Empty,
|
Contractor = contractor?.Caption ?? String.Empty,
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
using AsbCloudApp.Data.DailyReport;
|
using AsbCloudApp.Data.DailyReport;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services.Trajectory;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -72,8 +76,17 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> AddAsync(int idWell, [Required] DateTime startDate, CancellationToken token = default)
|
public async Task<IActionResult> AddAsync(int idWell, [Required] DateTime startDate, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var result = await dailyReportService.AddAsync(idWell, startDate, token);
|
try
|
||||||
return Ok(result);
|
{
|
||||||
|
var result = await dailyReportService.AddAsync(idWell, startDate, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (ArgumentInvalidException ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user