This commit is contained in:
2020-08-10 19:28:16 +00:00
parent 98a7d77069
commit 6ce9ce4d8f
5 changed files with 74 additions and 15 deletions

View File

@@ -96,16 +96,6 @@ namespace AyaNova.Api.Controllers
}
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// var asText = Newtonsoft.Json.JsonConvert.SerializeObject(
// o,
// Newtonsoft.Json.Formatting.None,
// new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver(new string[] { "Concurrency", "Id", "LogoId" }) });
// var bytes = System.Text.Encoding.UTF8.GetBytes(asText);
// var file = new FileContentResult(bytes, "application/octet-stream");
// file.FileDownloadName = Util.FileUtil.StringToSafeFileName(o.Name) + ".json";
// return file;
}
@@ -148,7 +138,7 @@ namespace AyaNova.Api.Controllers
await ct.SaveChangesAsync();
}
var file = Request.Form.Files[0];
var file = Request.Form.Files[0];
//var file=files[0];
using (var memoryStream = new MemoryStream())
@@ -176,5 +166,58 @@ namespace AyaNova.Api.Controllers
}
return Accepted();
}
/// <summary>
/// Delete logo
/// </summary>
/// <param name="size"></param>
/// <returns>NoContent</returns>
[Authorize]
[HttpDelete("{size}")]
public async Task<IActionResult> DeleteLogo([FromRoute] string size)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Global))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (string.IsNullOrWhiteSpace(size))
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, "size", "Size is required and must be one of 'small', 'medium' or 'large'"));
size = size.ToLowerInvariant();
if (size != "small" && size != "medium" && size != "large")
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, "size", "Size parameter must be one of 'small', 'medium' or 'large'"));
//get the one and only logo object
var logo = await ct.Logo.FirstOrDefaultAsync();
if (logo != null)
{
switch (size)
{
case "small":
logo.Small = null;
logo.SmallType = string.Empty;
break;
case "medium":
logo.Medium = null;
logo.MediumType = string.Empty;
break;
case "large":
logo.Large = null;
logo.LargeType = string.Empty;
break;
}
await ct.SaveChangesAsync();
}
return NoContent();
}
}
}