deprecate Product in favour of SimilarProduct
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7db10ab6c0
commit
0dfead8388
|
@ -65,7 +65,13 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
IList<Similar> s = await dbctx.Similar.Where(p_item => p_item.prod_id == id).ToListAsync();
|
IList<Similar> s = await dbctx.Similar.Where(p_item => p_item.prod_id == id).ToListAsync();
|
||||||
IList<Product> similar = product.Products;
|
IList<SimilarProduct> similar = new List<SimilarProduct>();
|
||||||
|
foreach (var prod in product.Products) {
|
||||||
|
SimilarProduct sp = new SimilarProduct();
|
||||||
|
sp.id = prod.id;
|
||||||
|
sp.Selected = prod.Selected;
|
||||||
|
similar.Add(sp);
|
||||||
|
}
|
||||||
foreach (var s_item in s)
|
foreach (var s_item in s)
|
||||||
{
|
{
|
||||||
var prodpls = await dbctx.Product.Where(p_item => p_item.id == s_item.prod_id).FirstOrDefaultAsync();
|
var prodpls = await dbctx.Product.Where(p_item => p_item.id == s_item.prod_id).FirstOrDefaultAsync();
|
||||||
|
@ -78,9 +84,7 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(similar != null){
|
item.Similar = similar;
|
||||||
item.Similar = similar;
|
|
||||||
}
|
|
||||||
ViewData["ImageSrc"] = new SelectList(dbctx.Product, "ImageSrc", item.ImageSrc);
|
ViewData["ImageSrc"] = new SelectList(dbctx.Product, "ImageSrc", item.ImageSrc);
|
||||||
return View(item);
|
return View(item);
|
||||||
}
|
}
|
||||||
|
@ -109,18 +113,28 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
||||||
item.ImageSrc = product.ImageSrc;
|
item.ImageSrc = product.ImageSrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<Product> p = product.Similar;
|
if (product.Similar != null) {
|
||||||
if(p != null){
|
IList<SimilarProduct> similar = new List<SimilarProduct>();
|
||||||
foreach (var prod in p)
|
foreach (var prod in product.Similar) {
|
||||||
{
|
SimilarProduct sp = new SimilarProduct();
|
||||||
if(prod.Selected){
|
sp.id = prod.id;
|
||||||
Similar s = new Similar();
|
sp.Selected = prod.Selected;
|
||||||
s.prod_id = item.id;
|
similar.Add(sp);
|
||||||
s.similar_prod_id = prod.id;
|
}
|
||||||
var res = dbctx.Similar.Add(s);
|
if(similar.Count > 0){
|
||||||
} else {
|
foreach (var prod in similar)
|
||||||
Similar s = dbctx.Similar.Where(p_item => p_item.prod_id == item.id && p_item.similar_prod_id != prod.id).FirstOrDefault();
|
{
|
||||||
var res = dbctx.Similar.Remove(s);
|
if(prod.Selected){
|
||||||
|
Similar s = new Similar();
|
||||||
|
s.prod_id = item.id;
|
||||||
|
s.similar_prod_id = prod.id;
|
||||||
|
var res = dbctx.Similar.Add(s);
|
||||||
|
} else {
|
||||||
|
Similar s = dbctx.Similar.Where(p_item => p_item.prod_id == item.id && p_item.similar_prod_id != prod.id).FirstOrDefault();
|
||||||
|
if (s != null) {
|
||||||
|
dbctx.Similar.Remove(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
@using pwt_0x01_ng.Areas.Admin.Controllers;
|
@using pwt_0x01_ng.Areas.Admin.Controllers;
|
||||||
@model Product
|
@model Product
|
||||||
@{
|
@{
|
||||||
IList<Product> similar,products;
|
IList<Product> products;
|
||||||
similar = new List<Product>();
|
IList<SimilarProduct> similar;
|
||||||
products = (IList<Product>)ViewData["prods"];
|
products = (IList<Product>)ViewData["prods"];
|
||||||
|
similar = new List<SimilarProduct>();
|
||||||
if((!String.IsNullOrEmpty(ViewBag.Action))||(!String.IsNullOrWhiteSpace(ViewBag.Action)))
|
if((!String.IsNullOrEmpty(ViewBag.Action))||(!String.IsNullOrWhiteSpace(ViewBag.Action)))
|
||||||
{
|
{
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace pwt_0x01_ng.Models
|
||||||
[StringLength(50, ErrorMessage = "{0} length must be between {2} and {1}.", MinimumLength = 1)]
|
[StringLength(50, ErrorMessage = "{0} length must be between {2} and {1}.", MinimumLength = 1)]
|
||||||
public string ImageAlt { get; set; }
|
public string ImageAlt { get; set; }
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public IList<Product> Similar { get; set; }
|
public IList<SimilarProduct> Similar { get; set; }
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public bool Selected { get; set; }
|
public bool Selected { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,15 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||||
namespace pwt_0x01_ng.Models
|
namespace pwt_0x01_ng.Models
|
||||||
{
|
{
|
||||||
[Table(nameof(Similar))]
|
[Table(nameof(Similar))]
|
||||||
public class Similar : Entity
|
public class Similar
|
||||||
{
|
{
|
||||||
|
[Required]
|
||||||
|
[Key]
|
||||||
|
public int id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int prod_id { get; set; }
|
public int prod_id { get; set; }
|
||||||
[ForeignKey(nameof(Product))]
|
[ForeignKey(nameof(Product))]
|
||||||
[Required]
|
[Required]
|
||||||
public int similar_prod_id { get; set; }
|
public int similar_prod_id { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace pwt_0x01_ng.Models
|
||||||
|
{
|
||||||
|
public class SimilarViewModel
|
||||||
|
{
|
||||||
|
public IList<Similar> Similar { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue