SweetA 1.2.3

dotnet add package SweetA --version 1.2.3
                    
NuGet\Install-Package SweetA -Version 1.2.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SweetA" Version="1.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SweetA" Version="1.2.3" />
                    
Directory.Packages.props
<PackageReference Include="SweetA" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SweetA --version 1.2.3
                    
#r "nuget: SweetA, 1.2.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SweetA@1.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SweetA&version=1.2.3
                    
Install as a Cake Addin
#tool nuget:?package=SweetA&version=1.2.3
                    
Install as a Cake Tool

_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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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