From 4545325a93bd9cb932d7b6bf48b19ee9be8b8f09 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 9 Mar 2023 09:55:53 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D1=80=D1=82=D0=B0:=20=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20=D0=BE=D0=BD=20=D0=B5=D1=81=D1=82=D1=8C=20=D0=B2=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=B5,=20=D1=82=D0=BE=20=D0=BD=D1=83=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DailyReport/DailyReportService.cs | 13 ++++++++++--- .../Controllers/DailyReportController.cs | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 392b3f83..2a093f5b 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -76,19 +76,26 @@ namespace AsbCloudInfrastructure.Services.DailyReport if (well is null || well.Timezone is null) 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 contractor = well.Companies.FirstOrDefault(company => company.IdCompanyType == 2); - var entity = new AsbCloudDb.Model.DailyReport.DailyReport + entity = new AsbCloudDb.Model.DailyReport.DailyReport { IdWell = idWell, - StartDate = new DateOnly(startDate.Date.Year, startDate.Date.Month, startDate.Date.Day), + StartDate = startDateOnly, Info = new DailyReportInfo() { Head = new Head() { ReportDate = startDate.Date, WellName = well.Caption, - ClusterName = well.Cluster, + ClusterName = well?.Cluster ?? String.Empty, Customer = customer?.Caption ?? String.Empty, Contractor = contractor?.Caption ?? String.Empty, } diff --git a/AsbCloudWebApi/Controllers/DailyReportController.cs b/AsbCloudWebApi/Controllers/DailyReportController.cs index 1664832e..dde14461 100644 --- a/AsbCloudWebApi/Controllers/DailyReportController.cs +++ b/AsbCloudWebApi/Controllers/DailyReportController.cs @@ -1,10 +1,14 @@ using AsbCloudApp.Data.DailyReport; +using AsbCloudApp.Exceptions; using AsbCloudApp.Services; +using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services.Trajectory; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.IO; using System.Threading; using System.Threading.Tasks; @@ -72,8 +76,17 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task AddAsync(int idWell, [Required] DateTime startDate, CancellationToken token = default) { - var result = await dailyReportService.AddAsync(idWell, startDate, token); - return Ok(result); + try + { + var result = await dailyReportService.AddAsync(idWell, startDate, token); + return Ok(result); + } + catch (ArgumentInvalidException ex) + { + return BadRequest(ex.Message); + } + + }