Остались мелкие недочеты в моделях бд

This commit is contained in:
DyCTaTOR 2024-04-26 00:03:46 +04:00
parent 93f012e03b
commit 846f54e663
3 changed files with 34 additions and 31 deletions

View File

@ -65,48 +65,55 @@ namespace UniversityBusinessLogic.BusinessLogics
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
return true; return true;
} }
public bool ScoreUpdate(AttestationBindingModel model, AttestationScore newScore) public bool ScoreUpdate(AttestationBindingModel model, AttestationScore newScore)
{ {
CheckModel(model); CheckModel(model);
if (model.Score + 1 != newScore)
if (!Enum.IsDefined(typeof(AttestationScore), newScore))
{ {
_logger.LogWarning("Status update to " + newScore.ToString() + " operation failed. Order status incorrect."); _logger.LogWarning("Score update to " + newScore.ToString() + " operation failed. Attestation status incorrect.");
return false; return false;
} }
model.Score = newScore;
if (model.Score == AttestationScore.Выдан)
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
if (_attestationStorage.Update(model) == null) if (_attestationStorage.Update(model) == null)
{ {
model.Score--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }
model.Score = newScore;
return true; return true;
} }
public bool TakeOrderInWork(OrderBindingModel model) public bool SetPass(AttestationBindingModel model)
{ {
return StatusUpdate(model, OrderStatus.Выполняется); return ScoreUpdate(model, AttestationScore.Зачёт);
} }
public bool DeliveryOrder(OrderBindingModel model) public bool SetNotPass(AttestationBindingModel model)
{ {
return StatusUpdate(model, OrderStatus.Готов); return ScoreUpdate(model, AttestationScore.Незачёт);
} }
public bool FinishOrder(OrderBindingModel model) public bool SetTwo(AttestationBindingModel model)
{ {
return StatusUpdate(model, OrderStatus.Выдан); return ScoreUpdate(model, AttestationScore.Неудовлетворительно);
}
public bool SetThree(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Удовлетворительно);
}
public bool SetFour(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Хорошо);
}
public bool SetFive(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Отлично);
} }
private void CheckModel(OrderBindingModel model, bool withParams = true) private void CheckModel(AttestationBindingModel model, bool withParams = true)
{ {
if (model == null) if (model == null)
{ {
@ -116,21 +123,17 @@ namespace UniversityBusinessLogic.BusinessLogics
{ {
return; return;
} }
if (model.WorkId < 0) if (string.IsNullOrEmpty(model.FormOfEvaluation))
{ {
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId)); throw new ArgumentNullException("Не выбрана форма оценивания", nameof(model.FormOfEvaluation));
} }
if (model.Count <= 0) if (model.StudentId <= 0)
{ {
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); throw new ArgumentNullException("Некорректный идентификатор студента", nameof(model.StudentId));
} }
_logger.LogInformation("Attestation. AttestationId:{Id}.FormOfEvaluation:{FormOfEvaluation}. StudentId: { StudentId}",
if (model.Sum <= 0) model.Id, model.FormOfEvaluation, model.StudentId);
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
} }
} }
} }

View File

@ -15,10 +15,10 @@ namespace UniversityContracts.BusinessLogicsContracts
bool CreateAttestation(AttestationBindingModel model); bool CreateAttestation(AttestationBindingModel model);
bool SetPass(AttestationBindingModel model); bool SetPass(AttestationBindingModel model);
bool SetNotPass(AttestationBindingModel model); bool SetNotPass(AttestationBindingModel model);
bool Set(AttestationBindingModel model); bool SetTwo(AttestationBindingModel model);
bool Set(AttestationBindingModel model); bool SetThree(AttestationBindingModel model);
bool Set(AttestationBindingModel model); bool SetFour(AttestationBindingModel model);
bool SetNotCredit(AttestationBindingModel model); bool SetFive(AttestationBindingModel model);
} }
} }

View File

@ -12,7 +12,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR
optionsBuilder.UseSqlServer(@"Data Source=(localdb)\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }