Implemented domain order. Fixed some bugs

This commit is contained in:
Marcel Baumgartner
2023-04-11 21:36:25 +02:00
parent dacf9f606f
commit 3189f901a8
9 changed files with 278 additions and 15 deletions

View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
using Moonlight.App.Database.Entities;
namespace Moonlight.App.Models.Forms;
public class DomainOrderDataModel
{
[Required(ErrorMessage = "You need to specify a name")]
[MaxLength(32, ErrorMessage = "The max lenght for the name is 32 characters")]
[RegularExpression(@"^[a-z]+$", ErrorMessage = "The name should only consist of lower case characters")]
public string Name { get; set; } = "";
[Required(ErrorMessage = "You need to specify a shared domain")]
public SharedDomain SharedDomain { get; set; }
}

View File

@@ -48,6 +48,28 @@ public class DomainService
);
}
public Task<Domain> Create(string domain, SharedDomain sharedDomain, User user)
{
if (DomainRepository.Get().Where(x => x.SharedDomain.Id == sharedDomain.Id).Any(x => x.Name == domain))
throw new DisplayException("A domain with this name does already exist for this shared domain");
var res = DomainRepository.Add(new()
{
Name = domain,
SharedDomain = sharedDomain,
Owner = user
});
return Task.FromResult(res);
}
public Task Delete(Domain domain)
{
DomainRepository.Delete(domain);
return Task.CompletedTask;
}
public async Task<Zone[]>
GetAvailableDomains() // This method returns all available domains which are not added as a shared domain
{