SweetA 1.2.3
dotnet add package SweetA --version 1.2.3
NuGet\Install-Package SweetA -Version 1.2.3
<PackageReference Include="SweetA" Version="1.2.3" />
<PackageVersion Include="SweetA" Version="1.2.3" />
<PackageReference Include="SweetA" />
paket add SweetA --version 1.2.3
#r "nuget: SweetA, 1.2.3"
#:package SweetA@1.2.3
#addin nuget:?package=SweetA&version=1.2.3
#tool nuget:?package=SweetA&version=1.2.3
_DbModels
public class Product
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PId { get; set; }
public String PName { get; set; }
public int Price { get; set; }
public bool IsAviable { get; set; }
public DateTime Pdate { get; set; }
public string Image { get; set; }
public virtual IList<Details> Details { get; set; }
}
public class Color
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CId { get; set; }
public string CName { get; set; }
public virtual IList<Details> Details { get; set; }
}
public class Details
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int DId { get; set; }
[ForeignKey("Product")]
public int PId { get; set; }
[ForeignKey("Color")]
public int CId { get; set; }
public virtual Product Product { get; set; }
public virtual Color Color { get; set; }
}
public class ProductDbContext : DbContext
{
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Color> Colors { get; set; }
public virtual DbSet<Details> Details { get; set; }
}
_Web.config
<connectionStrings>
<add name="ProductDbContext" connectionString="Data Source=DESKTOP-VKO9DF8;initial catalog=R62ProductDatabase;integrated security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
_ProductVM
public class ProductVM
{
public ProductVM()
{
this.Details = new List<Details>();
}
public int PId { get; set; }
[Required, DisplayName("Product Name")]
public string PName { get; set; }
public int Price { get; set; }
[DisplayName("Is Available")]
public bool IsAviable { get; set; }
[DisplayName("Launch Date")]
public DateTime Pdate { get; set; }
public string Image { get; set; }
public HttpPostedFileBase ImageFile { get; set; }
public virtual List<Details> Details { get; set; }
}
_ProductsController
public ActionResult Index()
{
var products = db.Products.OrderByDescending(p => p.PId).ToList();
foreach (var product in products)
{
db.Entry(product).Collection(p => p.Details).Load();
foreach (var detail in product.Details)
{
db.Entry(detail).Reference(d => d.Color).Load();
}
}
return View(products);
}
[HttpGet]
public ActionResult Create()
{
return PartialView("Create");
}
[HttpPost]
public ActionResult Create(ProductVM productVM, int[] CId)
{
if (ModelState.IsValid)
{
var product = new Product()
{
PName = productVM.PName,
IsAviable = productVM.IsAviable,
Pdate = productVM.Pdate,
Price = productVM.Price,
};
HttpPostedFileBase file = productVM.ImageFile;
if (file != null)
{
string filename = Path.Combine("/Images/", DateTime.Now.Ticks.ToString() + Path.GetExtension(file.FileName));
file.SaveAs(Server.MapPath(filename));
product.Image = filename;
}
foreach (var i in CId)
{
var d = new Details()
{
Product = product,
PId = product.PId,
CId = i
};
db.Details.Add(d);
}
db.SaveChanges();
return RedirectToAction("Index");
}
return View(productVM);
}
public ActionResult AddColor(int? id)
{
ViewBag.Color = new SelectList(db.Colors.ToList(), "CId", "CName", id ?? 0);
return PartialView("AddColor");
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.2.3 | 180 | 3/10/2025 |