V10: fix build warnings in Web.BackOffice (#12479)
* Run code cleanup * Start manual run * Finish dotnet format + manual cleanup * Fix up after merge * Fix substrings changed to [..] Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core;
|
||||
@@ -13,160 +10,160 @@ using Umbraco.Cms.Web.Common.Attributes;
|
||||
using Umbraco.Cms.Web.Common.Authorization;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
namespace Umbraco.Cms.Web.BackOffice.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// An API controller used for dealing with member groups
|
||||
/// </summary>
|
||||
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
||||
[Authorize(Policy = AuthorizationPolicies.TreeAccessMemberGroups)]
|
||||
[ParameterSwapControllerActionSelector(nameof(GetById), "id", typeof(int), typeof(Guid), typeof(Udi))]
|
||||
public class MemberGroupController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
/// <summary>
|
||||
/// An API controller used for dealing with member groups
|
||||
/// </summary>
|
||||
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
||||
[Authorize(Policy = AuthorizationPolicies.TreeAccessMemberGroups)]
|
||||
[ParameterSwapControllerActionSelector(nameof(GetById), "id", typeof(int), typeof(Guid), typeof(Udi))]
|
||||
public class MemberGroupController : UmbracoAuthorizedJsonController
|
||||
private readonly ILocalizedTextService _localizedTextService;
|
||||
private readonly IMemberGroupService _memberGroupService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public MemberGroupController(
|
||||
IMemberGroupService memberGroupService,
|
||||
IUmbracoMapper umbracoMapper,
|
||||
ILocalizedTextService localizedTextService)
|
||||
{
|
||||
private readonly ILocalizedTextService _localizedTextService;
|
||||
private readonly IMemberGroupService _memberGroupService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
_memberGroupService = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService));
|
||||
_umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
|
||||
_localizedTextService =
|
||||
localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
|
||||
}
|
||||
|
||||
public MemberGroupController(
|
||||
IMemberGroupService memberGroupService,
|
||||
IUmbracoMapper umbracoMapper,
|
||||
ILocalizedTextService localizedTextService)
|
||||
/// <summary>
|
||||
/// Gets the member group json for the member group id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<MemberGroupDisplay?> GetById(int id)
|
||||
{
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(id);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
_memberGroupService = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService));
|
||||
_umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
|
||||
_localizedTextService =
|
||||
localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the member group json for the member group id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<MemberGroupDisplay?> GetById(int id)
|
||||
{
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(id);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
MemberGroupDisplay? dto = _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
return dto;
|
||||
}
|
||||
|
||||
MemberGroupDisplay? dto = _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
return dto;
|
||||
/// <summary>
|
||||
/// Gets the member group json for the member group guid
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<MemberGroupDisplay?> GetById(Guid id)
|
||||
{
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(id);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the member group json for the member group guid
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<MemberGroupDisplay?> GetById(Guid id)
|
||||
{
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(id);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
}
|
||||
|
||||
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
/// <summary>
|
||||
/// Gets the member group json for the member group udi
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<MemberGroupDisplay?> GetById(Udi id)
|
||||
{
|
||||
var guidUdi = id as GuidUdi;
|
||||
if (guidUdi == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the member group json for the member group udi
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<MemberGroupDisplay?> GetById(Udi id)
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(guidUdi.Guid);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
var guidUdi = id as GuidUdi;
|
||||
if (guidUdi == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(guidUdi.Guid);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
public IEnumerable<MemberGroupDisplay> GetByIds([FromQuery] int[] ids)
|
||||
=> _memberGroupService.GetByIds(ids).Select(_umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>).WhereNotNull();
|
||||
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public IActionResult DeleteById(int id)
|
||||
public IEnumerable<MemberGroupDisplay> GetByIds([FromQuery] int[] ids)
|
||||
=> _memberGroupService.GetByIds(ids).Select(_umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>)
|
||||
.WhereNotNull();
|
||||
|
||||
[HttpDelete]
|
||||
[HttpPost]
|
||||
public IActionResult DeleteById(int id)
|
||||
{
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(id);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetById(id);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_memberGroupService.Delete(memberGroup);
|
||||
return Ok();
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
public IEnumerable<MemberGroupDisplay> GetAllGroups()
|
||||
=> _memberGroupService.GetAll()
|
||||
.Select(_umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>).WhereNotNull();
|
||||
_memberGroupService.Delete(memberGroup);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
public MemberGroupDisplay? GetEmpty()
|
||||
public IEnumerable<MemberGroupDisplay> GetAllGroups()
|
||||
=> _memberGroupService.GetAll()
|
||||
.Select(_umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>).WhereNotNull();
|
||||
|
||||
public MemberGroupDisplay? GetEmpty()
|
||||
{
|
||||
var item = new MemberGroup();
|
||||
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(item);
|
||||
}
|
||||
|
||||
public bool IsMemberGroupNameUnique(int id, string? oldName, string? newName)
|
||||
{
|
||||
if (newName == oldName)
|
||||
{
|
||||
var item = new MemberGroup();
|
||||
return _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(item);
|
||||
return true; // name hasn't changed
|
||||
}
|
||||
|
||||
public bool IsMemberGroupNameUnique(int id, string? oldName, string? newName)
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetByName(newName);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
if (newName == oldName)
|
||||
{
|
||||
return true; // name hasn't changed
|
||||
}
|
||||
|
||||
IMemberGroup? memberGroup = _memberGroupService.GetByName(newName);
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return true; // no member group found
|
||||
}
|
||||
|
||||
return memberGroup.Id == id;
|
||||
return true; // no member group found
|
||||
}
|
||||
|
||||
public ActionResult<MemberGroupDisplay?> PostSave(MemberGroupSave saveModel)
|
||||
return memberGroup.Id == id;
|
||||
}
|
||||
|
||||
public ActionResult<MemberGroupDisplay?> PostSave(MemberGroupSave saveModel)
|
||||
{
|
||||
var id = saveModel.Id is not null ? int.Parse(saveModel.Id.ToString()!, CultureInfo.InvariantCulture) : default;
|
||||
IMemberGroup? memberGroup = id > 0 ? _memberGroupService.GetById(id) : new MemberGroup();
|
||||
if (memberGroup == null)
|
||||
{
|
||||
var id = saveModel.Id is not null ? int.Parse(saveModel.Id.ToString()!, CultureInfo.InvariantCulture) : default;
|
||||
IMemberGroup? memberGroup = id > 0 ? _memberGroupService.GetById(id) : new MemberGroup();
|
||||
if (memberGroup == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if (IsMemberGroupNameUnique(memberGroup.Id, memberGroup.Name, saveModel.Name))
|
||||
{
|
||||
memberGroup.Name = saveModel.Name;
|
||||
_memberGroupService.Save(memberGroup);
|
||||
if (IsMemberGroupNameUnique(memberGroup.Id, memberGroup.Name, saveModel.Name))
|
||||
{
|
||||
memberGroup.Name = saveModel.Name;
|
||||
_memberGroupService.Save(memberGroup);
|
||||
|
||||
MemberGroupDisplay? display = _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
MemberGroupDisplay? display = _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
|
||||
display?.AddSuccessNotification(
|
||||
_localizedTextService.Localize("speechBubbles", "memberGroupSavedHeader"),
|
||||
string.Empty);
|
||||
display?.AddSuccessNotification(
|
||||
_localizedTextService.Localize("speechBubbles", "memberGroupSavedHeader"),
|
||||
string.Empty);
|
||||
|
||||
return display;
|
||||
}
|
||||
else
|
||||
{
|
||||
MemberGroupDisplay? display = _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
display?.AddErrorNotification(
|
||||
_localizedTextService.Localize("speechBubbles", "memberGroupNameDuplicate"),
|
||||
string.Empty);
|
||||
return display;
|
||||
}
|
||||
else
|
||||
{
|
||||
MemberGroupDisplay? display = _umbracoMapper.Map<IMemberGroup, MemberGroupDisplay>(memberGroup);
|
||||
display?.AddErrorNotification(
|
||||
_localizedTextService.Localize("speechBubbles", "memberGroupNameDuplicate"),
|
||||
string.Empty);
|
||||
|
||||
return display;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user