- Заголовок
- Свойство
- Единицы
DTO заголовка:
Код: Выделить всё
public class HeaderDTO
{
public string Phone { get; set; } = null!;
public string? Source { get; set; }
public string? Address { get; set; }
public string? Country { get; set; }
public string? ShipTo { get; set; }
public virtual ICollection
Properties { get; set; } = new List();
}
Код: Выделить всё
public class PropertyDTO
{
public string? Floor { get; set; }
public string? Area { get; set; }
public int Window { get; set; }
public string Products { get; set; } = null!;
public string? Login { get; set; }
public string? ShipTo { get; set; }
public int? Flag { get; set; }
public virtual ICollection Units { get; set; } = new List();
}
Код: Выделить всё
public class UnitDTO
{
public string? UniqueName { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public int Panel { get; set; }
public int? Belah { get; set; }
public string? Img1 { get; set; }
public string? Img2 { get; set; }
public string? Img3 { get; set; }
public List? products;
}
Как я могу выполнить итерацию по классу единиц измерения.
Я пробовал для вызова функции Include, но она недопустима в данном контексте.
Любые рекомендации по решению этой проблемы будут очень признательны.
Код: Выделить всё
[HttpPost("SOPPOST")]
public async Task CreateHeaders(HeaderDTO hdto)
{
var header = new HeaderDTO
{
Address = hdto.Address,
Country = hdto.Country,
Phone = hdto.Phone,
ShipTo = hdto.ShipTo,
Source = hdto.Source
};
var phoneVerify = _context.TDataHeaders.Count(x => x.Phone == header.Phone);
var headerImport = new TDataHeader
{
Address = header.Address,
Country = header.Country,
Phone = header.Phone,
ShipTo = header.ShipTo,
Source = header.Source
};
//if (phoneVerify == 0)
//{
// await _context.TDataHeaders.AddAsync(headerImport);
//}
foreach (var prop in hdto.Properties)
{
var property = new TDataProperty
{
Floor = prop.Floor,
Area = prop.Area,
Windows = prop.Windows,
Flag = prop.Flag,
Login = prop.Login,
Products = prop.Products,
ShipTo = prop.ShipTo,
Header = headerImport
};
foreach (var unit in prop.Units)
{
var unitModel = new TDataUnit
{
Belah = unit.Belah,
Height = unit.Height,
Width = unit.Width,
Panel = unit.Panel,
Img1 = unit.Img1,
Img2 = unit.Img2,
Img3 = unit.Img3,
UniqueName = prop.Floor + "-" + prop.Area + "-" + prop.Windows,
Property = property
};
await _context.TDataUnits.AddRangeAsync(unitModel);
}
await _context.TDataProperties.AddRangeAsync(property);
}
await _context.SaveChangesAsync();
return Ok("Posted");
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... hild-class
Мобильная версия