Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor syntax issues fixed
  • Loading branch information
Shiko1st authored and leotsarev committed May 5, 2022
commit 01f51268a37c073d6d66fa0f2a64156343cd7987
12 changes: 5 additions & 7 deletions src/JoinRpg.Dal.Impl/Repositories/ClaimPredicates.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Data.Entity.SqlServer;
using System.Linq.Expressions;
using JoinRpg.Data.Interfaces.Claims;
using JoinRpg.DataModel;
Expand Down Expand Up @@ -47,10 +46,9 @@ public static Expression<Func<Claim, bool>> GetClaimStatusPredicate(ClaimStatusS

public static Expression<Func<Claim, bool>> GetMyClaim(int userId) => claim => claim.PlayerUserId == userId;

public static Expression<Func<Claim, bool>> GetInGroupPredicate(int[] characterGroupsIds) =>
claim => (claim.CharacterGroupId != null && characterGroupsIds.Contains(claim.CharacterGroupId.Value))
||
(claim.Character != null &&
characterGroupsIds.Any(id => claim.Character.ParentGroupsImpl.ListIds.Contains(id.ToString()))));
}
public static Expression<Func<Claim, bool>> GetInGroupPredicate(int[] characterGroupsIds) =>
claim => (claim.CharacterGroupId != null
&& characterGroupsIds.Contains(claim.CharacterGroupId.Value))
|| (claim.Character != null
&& characterGroupsIds.Any(id => claim.Character.ParentGroupsImpl.ListIds.Contains(id.ToString())));
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
_ = builder.UseTestServer();
}

protected override void Dispose(bool disposing)
{
var context = Services.GetRequiredService<MyDbContext>();
_ = context.Database.EnsureDeleted();
base.Dispose(disposing);
}
protected override void Dispose(bool disposing)
{
var context = Services.GetRequiredService<MyDbContext>();
_ = context.Database.EnsureDeleted();
base.Dispose(disposing);
}
}
78 changes: 38 additions & 40 deletions src/JoinRpg.Portal/Infrastructure/ModelStateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,45 @@ internal static class ModelStateExtensions
//TODO messages from resources
public static void AddException(this ModelStateDictionary dict, Exception exception)
{
switch (exception)
{
case ValidationException validation:
var errorMessage = validation.ValidationResult.ErrorMessage ?? "Validation error";
dict.AddModelError("", errorMessage);
if (validation.Source is not null)
{
dict.AddModelError(validation.Source, errorMessage);
}
return;

switch (exception)
{
case ValidationException validation:
var errorMessage = validation.ValidationResult.ErrorMessage ?? "Validation error";
dict.AddModelError("", errorMessage);
if (validation.Source is not null)
{
dict.AddModelError(validation.Source, errorMessage);
}
return;

case FieldRequiredException required:
dict.AddModelError("", required.FieldName + " is required");
dict.AddModelError(required.FieldName, " required");
return;
case ClaimWrongStatusException _:
case ProjectDeactivedException _:
case ClaimAlreadyPresentException _:
case ClaimTargetIsNotAcceptingClaims _:
case MasterHasResponsibleException _:
case CharacterShouldNotHaveClaimsException _:
case CharacterGroupShouldNotHaveClaimsException _:
case JoinRpgEntityNotFoundException _:
case JoinRpgCharacterBrokenStateException _:
dict.AddModelError("", exception.Message);
return;
case JoinRpgNameFieldDeleteException _:
dict.AddModelError("",
"Невозможно удалить поле, потому что оно привязано к имени персонажа");
return;
case JoinFieldScheduleShouldBeUniqueException _:
dict.AddModelError("", "Невозможно добавить второе поле с настройками расписания");
return;
case JoinRpgProjectException _:
dict.AddModelError("", exception.Message);
return;
default:
dict.AddModelError("", exception.ToString());
break;
}
case FieldRequiredException required:
dict.AddModelError("", required.FieldName + " is required");
dict.AddModelError(required.FieldName, " required");
return;
case ClaimWrongStatusException _:
case ProjectDeactivedException _:
case ClaimAlreadyPresentException _:
case ClaimTargetIsNotAcceptingClaims _:
case MasterHasResponsibleException _:
case CharacterShouldNotHaveClaimsException _:
case CharacterGroupShouldNotHaveClaimsException _:
case JoinRpgEntityNotFoundException _:
case JoinRpgCharacterBrokenStateException _:
dict.AddModelError("", exception.Message);
return;
case JoinRpgNameFieldDeleteException _:
dict.AddModelError("",
"Невозможно удалить поле, потому что оно привязано к имени персонажа");
return;
case JoinFieldScheduleShouldBeUniqueException _:
dict.AddModelError("", "Невозможно добавить второе поле с настройками расписания");
return;
case JoinRpgProjectException _:
dict.AddModelError("", exception.Message);
return;
default:
dict.AddModelError("", exception.ToString());
break;
}
}
}