Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CategoryDto Get(Guid id) {
}

[HttpPost]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
public async Task<IActionResult> Post([FromBody] CategoryDto category) {
try {
var entity = _mapper.Map<Category>(category);
Expand All @@ -51,7 +51,7 @@ public async Task<IActionResult> Post([FromBody] CategoryDto category) {


[HttpPut("{id}")]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
public async Task<IActionResult> Put(Guid id, [FromBody] CategoryDto categoryDto) {
try {
if (id != categoryDto.Id)
Expand All @@ -67,7 +67,7 @@ public async Task<IActionResult> Put(Guid id, [FromBody] CategoryDto categoryDto
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
public async Task<IActionResult> Delete(Guid id) {
try {
var category = _repository.Get(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public FoodDto Get(Guid id)
}

[HttpPost]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
public async Task<IActionResult> Post([FromBody] FoodDto foodDto)
{
var food = _mapper.Map<Food>(foodDto);
Expand All @@ -65,14 +65,14 @@ public async Task<IActionResult> Post([FromBody] FoodDto foodDto)

[HttpPost]
[Route("UploadFoodImage")]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
public Task Post([Bind] List<IFormFile> files, [Bind] string foodId)
{
return _foodPictureService.UploadAndCreatePictures(files, foodId);
}

[HttpPut("{id}")]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
[ProducesResponseType(304)]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
Expand Down Expand Up @@ -105,7 +105,7 @@ public async Task<IActionResult> Put(Guid id, [FromBody] FoodDto foodDto)
}

[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
// [Authorize(Roles = "Admin")]
public async Task<IActionResult> Delete(Guid id)
{
var food = _repository.Get(id);
Expand Down
19 changes: 10 additions & 9 deletions dotnet_3/cs/rest/NCS/Controllers/NcsRestController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using Microsoft.AspNetCore.Mvc;
using NCS.Imp;

Expand All @@ -12,7 +13,7 @@ public class NcsRestController : ControllerBase
[Produces("application/json")]
public IActionResult CheckTriangle(int a, int b, int c)
{
var dto = new Dto {ResultAsInt = TriangleClassification.Classify(a, b, c)};
var dto = new Dto {Result = TriangleClassification.Classify(a, b, c).ToString()};

return Ok(dto);
}
Expand All @@ -26,7 +27,7 @@ public IActionResult Bessj(int n, double x)
return BadRequest();
}

var dto = new Dto {ResultAsDouble = new Bessj().BessjFunction(n, x)};
var dto = new Dto {Result = new Bessj().BessjFunction(n, x).ToString(CultureInfo.InvariantCulture)};

return Ok(dto);
}
Expand All @@ -37,13 +38,13 @@ public IActionResult Expint(int n, double x)
{
try
{
var dto = new Dto {ResultAsDouble = Imp.Expint.Exe(n, x)};
var dto = new Dto {Result = Imp.Expint.Exe(n, x).ToString(CultureInfo.InvariantCulture)};

return Ok(dto);
}
catch (Exception e)
{
return BadRequest(e);
return BadRequest(e.Message);
}
}

Expand All @@ -58,13 +59,13 @@ public IActionResult Fisher(int m, int n, double x)

try
{
var dto = new Dto {ResultAsDouble = Imp.Fisher.Exe(m, n, x)};
var dto = new Dto {Result = Imp.Fisher.Exe(m, n, x).ToString(CultureInfo.InvariantCulture)};

return Ok(dto);
}
catch (Exception e)
{
return BadRequest(e);
return BadRequest(e.Message);
}
}

Expand All @@ -78,13 +79,13 @@ public IActionResult Gammq(double a, double x)

var gammq = new Gammq();

dto.ResultAsDouble = gammq.Exe(a, x);
dto.Result = gammq.Exe(a, x).ToString(CultureInfo.InvariantCulture);

return Ok(dto);
}
catch (Exception e)
{
return BadRequest(e);
return BadRequest(e.Message);
}
}

Expand All @@ -99,7 +100,7 @@ public IActionResult Remainder(int a, int b)
return BadRequest();
}

var dto = new Dto {ResultAsInt = Imp.Remainder.Exe(a, b)};
var dto = new Dto {Result = Imp.Remainder.Exe(a, b).ToString()};

return Ok(dto);
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet_3/cs/rest/NCS/Dto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ namespace NCS
{
public class Dto
{
public int? ResultAsInt { get; set; }

public double? ResultAsDouble { get; set; }
// public int? ResultAsInt { get; set; }
//
// public double? ResultAsDouble { get; set; }
public string Result { get; set; }
}
}
42 changes: 26 additions & 16 deletions dotnet_3/cs/rest/SCS/Imp/Calc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@ public static string Subject(string op, double arg1 , double arg2 )
{
op = op.ToLower();

var result = op switch
{
"pi" => Math.PI,
"e" => Math.E,
"sqrt" => Math.Sqrt(arg1),
"log" => Math.Log(arg1),
"sine" => Math.Sin(arg1),
"cosine" => Math.Cos(arg1),
"tangent" => Math.Tan(arg1),
"plus" => arg1 + arg2,
"subtract" => arg1 - arg2,
"multiply" => arg1 * arg2,
"divide" => arg1 / arg2,
_ => 0.0
};

double result;
if (op == "pi")
result = Math.PI;
else if (op == "e")
result = Math.E;
else if (op == "sqrt")
result = Math.Sqrt(arg1);
else if (op == "log")
result = Math.Log(arg1);
else if (op == "sine")
result = Math.Sin(arg1);
else if (op == "cosine")
result = Math.Cos(arg1);
else if (op == "tangent")
result = Math.Tan(arg1);
else if (op == "plus")
result = arg1 + arg2;
else if (op == "subtract")
result = arg1 - arg2;
else if (op == "multiply")
result = arg1 * arg2;
else if (op == "divide")
result = arg1 / arg2;
else
result = 0.0;

return "" + result;
}
}
Expand Down
29 changes: 12 additions & 17 deletions dotnet_3/cs/rest/SCS/Imp/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@ public static string Subject(string name, string val, string site)
val = val.ToLower();
site = site.ToLower();
var result = 0;

switch (name)
{
case "userid":
{
if (val.Length > 6) {
if ("user".Equals(val[..4])) {
result = 1;
}
}

break;
if (name == "userid") {
if (val.Length > 6) {
if ("user".Equals(val[..4])) {
result = 1;
}
}
case "session" when "am".Equals(val) && "abc.com".Equals(site):
result = 1;
break;
case "session":
result = 2;
break;
}
else if (name == "session" && ("am".Equals(val) && "abc.com".Equals(site))) {
result = 1;
}
else if (name == "session") {
result = 2;
}

return "" + result;
}
}
Expand Down
62 changes: 23 additions & 39 deletions dotnet_3/cs/rest/SCS/Imp/DateParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,29 @@ public static string Subject(string dayName, string monthName)
result = 1;
}

switch (monthName)
{
case "jan":
result += 1;
break;
case "feb":
result += 2;
break;
case "mar":
result += 3;
break;
case "apr":
result += 4;
break;
case "may":
result += 5;
break;
case "jun":
result += 6;
break;
case "jul":
result += 7;
break;
case "aug":
result += 8;
break;
case "sep":
result += 9;
break;
case "oct":
result += 10;
break;
case "nov":
result += 11;
break;
case "dec":
result += 12;
break;
}
if (monthName == "jan")
result += 1;
else if (monthName == "feb")
result += 2;
else if (monthName == "mar")
result += 3;
else if (monthName == "apr")
result += 4;
else if (monthName == "may")
result += 5;
else if (monthName == "jun")
result += 6;
else if (monthName == "jul")
result += 7;
else if (monthName == "aug")
result += 8;
else if (monthName == "sep")
result += 9;
else if (monthName == "oct")
result += 10;
else if (monthName == "nov")
result += 11;
else if (monthName == "dec") result += 12;

return "" + result;
}
Expand Down
70 changes: 23 additions & 47 deletions dotnet_3/cs/rest/SCS/Imp/FileSuffix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,34 @@ public static string Subject(string directory, string file)
if (lastPart <= 0) return "" + result;

var suffix = fileParts[lastPart];

switch (directory)
{
//Console.WriteLine("{0}, {1}", directory, suffix);
case "text":
{
if ("txt".Equals(suffix))
{
result = 1;
}

break;
if (directory == "text") {
if ("txt".Equals(suffix)) {
result = 1;
}
case "acrobat":
{
if ("pdf".Equals(suffix))
{
//print("acrobat");
result = 2;
}

break;
}
else if (directory == "acrobat") {
if ("pdf".Equals(suffix)) {
//print("acrobat");
result = 2;
}
case "word":
{
if ("doc".Equals(suffix))
{
//print("word");
result = 3;
}

break;
}
else if (directory == "word") {
if ("doc".Equals(suffix)) {
//print("word");
result = 3;
}
case "bin":
{
if ("exe".Equals(suffix))
{
//print("bin");
result = 4;
}

break;
}
else if (directory == "bin") {
if ("exe".Equals(suffix)) {
//print("bin");
result = 4;
}
case "lib":
{
if ("dll".Equals(suffix))
{
//print("lib");
result = 5;
}

break;
}
else if (directory == "lib") {
if ("dll".Equals(suffix)) {
//print("lib");
result = 5;
}
}

Expand Down
Loading