change enum serialization (#68)

whatever

Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2020-10-25 20:03:27 +01:00
parent 976498dc50
commit 515f236632
4 changed files with 20 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using System.IO; using System;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -63,8 +64,15 @@ namespace InternshipSystem.Api.Controllers
.Include(i => i.Documentation) .Include(i => i.Documentation)
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); .FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
internship.AddNewDocument(documentRequest.Description, documentRequest.Type); try
await _context.SaveChangesAsync(cancellationToken); {
internship.AddNewDocument(documentRequest.Description, documentRequest.Type);
await _context.SaveChangesAsync(cancellationToken);
}
catch (ArgumentException e)
{
return BadRequest(e.Message);
}
return Ok(); return Ok();
} }

View File

@ -72,7 +72,7 @@ namespace InternshipSystem.Api.Controllers
var edition = var edition =
await Context.Editions await Context.Editions
.Where(e => e.Id == id) .Where(e => e.Id == id)
.ProjectTo<EditionResult?>(Mapper.ConfigurationProvider) .ProjectTo<EditionResult>(Mapper.ConfigurationProvider)
.FirstOrDefaultAsync(token); .FirstOrDefaultAsync(token);
if (edition == null) if (edition == null)

View File

@ -2,7 +2,7 @@
namespace InternshipSystem.Api.Result namespace InternshipSystem.Api.Result
{ {
public struct EditionResult public class EditionResult
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime EditionStart { get; set; } public DateTime EditionStart { get; set; }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using InternshipSystem.Core.ValueObject; using InternshipSystem.Core.ValueObject;
@ -31,6 +32,11 @@ namespace InternshipSystem.Core.Entity.Internship
public void AddNewDocument(string description, DocumentType type) public void AddNewDocument(string description, DocumentType type)
{ {
if (Documentation.Any(d => d.Type == type))
{
throw new ArgumentException("Internship already has a document of given type");
}
var document = new Document var document = new Document
{ {
Description = description, Description = description,