Files
mixtape/zero.Debug/Controllers/TestController.cs
T

254 lines
6.7 KiB
C#
Raw Normal View History

2020-05-22 21:19:49 +02:00
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
2020-05-22 21:19:49 +02:00
using Microsoft.Extensions.DependencyInjection;
2020-09-08 14:33:31 +02:00
using Newtonsoft.Json;
2020-09-13 12:58:12 +02:00
using Raven.Client.Documents.Session;
using System;
2020-05-21 23:44:43 +02:00
using System.Collections.Generic;
using System.Linq;
2020-05-21 23:44:43 +02:00
using System.Threading.Tasks;
2020-09-13 12:58:12 +02:00
using zero.Commerce.Api;
using zero.Commerce.Entities;
2020-05-21 23:44:43 +02:00
using zero.Core.Api;
using zero.Core.Entities;
2020-08-27 11:41:40 +02:00
using zero.Core.Extensions;
2020-08-26 11:10:52 +02:00
using zero.Core.Utils;
using zero.Web.Filters;
2020-05-21 23:44:43 +02:00
namespace zero.Debug.Controllers
{
[ServiceFilter(typeof(ModelStateValidationFilterAttribute))]
2020-05-21 23:44:43 +02:00
public class TestController : Controller
{
private readonly IActionDescriptorCollectionProvider _actionDescriptorCollectionProvider;
2020-05-21 23:44:43 +02:00
2020-05-24 18:40:30 +02:00
public TestController(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
2020-05-21 23:44:43 +02:00
{
_actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
2020-05-21 23:44:43 +02:00
}
2020-05-22 21:19:49 +02:00
[HttpGet]
public IActionResult Services()
{
List<object> items = new List<object>();
foreach (var service in Startup.Services)
{
if (!service.ServiceType.FullName.StartsWith("zero.") && (service.ImplementationType == null || !service.ImplementationType.FullName.StartsWith("zero.")))
{
continue;
}
items.Add(new
{
name = service.ServiceType.FullName,
lifetime = service.Lifetime,
instance = service.ImplementationType?.FullName
});
}
2020-05-25 16:15:33 +02:00
return Json(new
{
count = items.Count,
items
2020-09-08 14:33:31 +02:00
}, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.None
2020-05-25 16:15:33 +02:00
});
2020-05-22 21:19:49 +02:00
}
2020-05-24 19:05:59 +02:00
[HttpGet]
2020-05-24 20:52:09 +02:00
public async Task<IActionResult> GetTranslations([FromServices] ITranslationsApi api)
2020-05-24 19:05:59 +02:00
{
2020-05-24 20:52:09 +02:00
return Json(await api.GetAll());
2020-05-24 19:05:59 +02:00
}
2020-08-26 11:10:52 +02:00
2020-05-22 21:19:49 +02:00
[HttpGet]
public IActionResult Things([FromServices] IValidator<Application> appValidator)
{
return Ok();
}
2020-08-27 11:41:40 +02:00
[HttpGet]
public IActionResult Clone([FromServices] IRecycledEntity blueprint)
{
IRecycledEntity entity = blueprint.Clone();
return Json(entity);
}
[HttpPost]
public IActionResult SaveTest([FromBody] IPage model) => Json(model);
2020-08-27 11:41:40 +02:00
[HttpGet]
public IActionResult Routes()
{
var routes = _actionDescriptorCollectionProvider.ActionDescriptors.Items.ToList();
if (routes != null && routes.Any())
{
return Json(routes);
}
return Json(new string [0]);
}
2020-09-13 12:58:12 +02:00
[HttpGet]
public async Task<IActionResult> AddOrder([FromServices] IOrdersApi ordersApi)
{
OrderAddress address = new OrderAddress()
{
Email = "cee@live.at",
FirstName = "Tobias",
LastName = "Klika",
Company = "brothers Klika OG",
Gender = Gender.Male,
VatNo = "ATU68334803",
PhoneNumber = "+43 660 2594892",
Address = "Laabstraße 9",
AddressLine1 = "Top 2",
Zip = "5280",
City = "Braunau am Inn",
Country = "Österreich",
CountryId = "countries.256-A"
};
OrderAddress shippingAddress = new OrderAddress()
{
Email = "cee@live.at",
FirstName = "Tobias",
LastName = "Klika",
Company = "brothers Klika OG",
Gender = Gender.Male,
VatNo = "ATU68334803",
PhoneNumber = "+43 660 2594892",
Address = "Salzburger Strasse 44",
Zip = "5280",
City = "Braunau am Inn",
Country = "Österreich",
CountryId = "countries.256-A"
};
Order order = new Order()
{
2020-09-14 00:39:47 +02:00
ChannelId = "channels.1-A",
Name = "23-0002",
Number = "23-0002",
2020-09-13 12:58:12 +02:00
LanguageId = "languages.2-A",
CurrencyId = "currencies.33-A",
State = OrderState.Completed,
DetailStateId = "orderDetailStates.3-A",
2020-09-13 12:58:12 +02:00
StateHistory = new List<IOrderStateHistoryItem>()
{
new OrderStateHistoryItem()
{
CreatedDate = DateTimeOffset.Now,
State = OrderState.Open,
DetailStateId = "orderDetailStates.3-A"
2020-09-13 12:58:12 +02:00
}
},
IsRequest = false,
CustomerId = "customers.1-A",
CustomerNote = "Danke für die Hilfe. Das war wirklich dringend nötig <3",
AssignedToUserId = "users.1-A",
Address = address,
Positions = new List<IOrderPosition>()
{
new OrderPosition()
{
Label = "Flex-Druck",
Price = 1.99m,
Quantity = 2,
TaxRate = 12
}
},
Items = new List<IOrderItem>()
{
new OrderItem()
{
Id = IdGenerator.Create(),
ProductId = "products.1-A",
2020-09-15 15:10:30 +02:00
VariantId = "4a5ddabc-8158-43f5-90eb-1d115cc062cc",
2020-09-13 12:58:12 +02:00
Name = "Nike Jersey 2.0",
Description = "Polyester / XS",
Sort = 0,
Quantity = 3,
Discount = 0,
Price = 17,
TaxRate = 20
},
new OrderItem()
{
Id = IdGenerator.Create(),
ProductId = "products.1-A",
2020-09-15 15:10:30 +02:00
VariantId = "4a5ddabc-8158-43f5-90eb-1d115cc062cc",
2020-09-13 12:58:12 +02:00
Name = "Nike Jersey 2.0",
Description = "Polyester / s",
Sort = 1,
Quantity = 1,
Discount = 5,
Price = 12,
TaxRate = 20
}
},
Price = 72.98m
};
order.Shipping = new OrderShipping()
{
Name = "Österreichische Post",
ShippingOptionId = "shippingOptions.1-A",
Price = 7.99m,
Lines = new Dictionary<string, string>()
{
{ "Postfach", "7-A" }
},
Address = shippingAddress,
Deliveries = new List<IOrderDelivery>()
{
new OrderDelivery()
{
CreatedDate = DateTimeOffset.Now,
TrackingNumber = "1035304005500970252807",
TrackingUrl = "https://www.post.at/sv/sendungsdetails?snr=1035304005500970252807",
Description = "Waren sind im Lager 2 (Regal 23)",
ShipmentDate = DateTimeOffset.Now.AddDays(2),
Items = new Dictionary<string, int>()
{
{ order.Items[0].Id, 2 },
{ order.Items[1].Id, 1 }
}
},
new OrderDelivery()
{
CreatedDate = DateTimeOffset.Now,
ShipmentDate = DateTimeOffset.Now.AddDays(4),
Items = new Dictionary<string, int>()
{
{ order.Items[0].Id, 1 }
}
}
}
};
2020-09-13 12:58:12 +02:00
return Json(await ordersApi.Save(order));
}
}
internal class RouteModel
{
public string Name { get; set; }
public string Template { get; set; }
2020-05-21 23:44:43 +02:00
}
}