added product and wishlist model

This commit is contained in:
AndriiSyrotenko 2023-10-15 22:14:31 +00:00
parent 16fd49af3f
commit bd8df1444a
6 changed files with 47 additions and 28 deletions

View File

@ -0,0 +1,20 @@
namespace ShoppingAssistantWebClient.Web.Models;
public class ProductModel
{
public required string Id {get; set;}
public required string Url {get; set;}
public required string Name {get; set;}
public required string Description {get; set;}
public required double Rating {get; set;}
public required string[] ImagesUrls {get; set;}
public required bool WasOpened {get; set;}
public required string WishlistId {get; set;}
}

View File

@ -0,0 +1,12 @@
namespace ShoppingAssistantWebClient.Web.Models;
public class WishlistModel
{
public required string Id {get; set;}
public required string Name {get; set;}
public required string Type {get; set;}
public required string CreateById {get; set;}
}

View File

@ -84,9 +84,6 @@
<label class="rating">@Html.DisplayFor(modelproduct => product.Rating)</label> <label class="rating">@Html.DisplayFor(modelproduct => product.Rating)</label>
@{ @{
string price = "N/A"; string price = "N/A";
if(!(product.Price is null)) {
price = "$" + product.Price.ToString();
}
} }
<label class="price-label">@price</label> <label class="price-label">@price</label>
</div> </div>

View File

@ -1,14 +1,16 @@
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using ShoppingAssistantWebClient.Web.Models;
namespace ShoppingAssistantWebClient.Web.Pages namespace ShoppingAssistantWebClient.Web.Pages
{ {
public class CartModel : PageModel public class CartModel : PageModel
{ {
public List<Product> products = new List<Product> { public List<ProductModel> products = new List<ProductModel> {
new Product {Description = "HDMI cabel HDMI cabel HDMI cabel HDMI cabel HDMI cabel HDMI cabelHDMI cabel", Rating = 4.0, Price = 12}, new ProductModel {Id = "0", Url = "some link", Name = "HDMI", Description = "super mega hdmi cabel", Rating = 3.8, ImagesUrls = new string[] {"link"}, WasOpened = false, WishlistId = "0"},
new Product {Description = "super mega hdmi cabel", Rating = 3.8, Price = 13.11}, new ProductModel {Id = "1", Url = "some link", Name = "HDMI", Description = "super mega hdmi cabel", Rating = 3.8, ImagesUrls = new string[] {"link"}, WasOpened = false, WishlistId = "1"},
new Product {Description = "", Rating = 4.0} new ProductModel {Id = "2", Url = "some link", Name = "HDMI", Description = "super mega hdmi cabel", Rating = 3.8, ImagesUrls = new string[] {"link"}, WasOpened = false, WishlistId = "2"}
}; };
public void OnGet() public void OnGet()
@ -16,10 +18,4 @@ namespace ShoppingAssistantWebClient.Web.Pages
} }
} }
public class Product {
public string Description {get; set;}
public double? Rating {get; set;}
public double? Price {get; set;}
}
} }

View File

@ -45,7 +45,7 @@
<th> </th> <th> </th>
<th style="text-align: left;">Chat name</th> <th style="text-align: left;">Chat name</th>
<th>Type</th> <th>Type</th>
<th>Time</th> <th>CreatedById</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -58,7 +58,7 @@
</form> </form>
<td style="text-align: left">@Html.DisplayFor(modelItem => item.Name)</td> <td style="text-align: left">@Html.DisplayFor(modelItem => item.Name)</td>
<td>@Html.DisplayFor(modelItem => item.Type)</td> <td>@Html.DisplayFor(modelItem => item.Type)</td>
<td>@Html.DisplayFor(modelItem => item.Date)</td> <td>@Html.DisplayFor(modelItem => item.CreateById)</td>
<form method="post" asp-page="Wishlist"> <form method="post" asp-page="Wishlist">
<td><input type="image" src="~/assets/shopping-cart.png" asp-page-handler="MoveToChat"></td> <td><input type="image" src="~/assets/shopping-cart.png" asp-page-handler="MoveToChat"></td>
</form> </form>

View File

@ -1,34 +1,28 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using ShoppingAssistantWebClient.Web.Models;
namespace ShoppingAssistantWebClient.Web.Pages namespace ShoppingAssistantWebClient.Web.Pages
{ {
public class WishlistModel : PageModel public class WishlistModel : PageModel
{ {
public List<Wishlist> wishlist = new List<Wishlist>{ public List<Models.WishlistModel> wishlist = new List<Models.WishlistModel>{
new Wishlist {Id = 0, Name = "Chat1", Type="product", Date="21.09.2023"}, new Models.WishlistModel {Id = "0", Name = "Chat1", Type="product", CreateById="0"},
new Wishlist {Id = 1, Name = "Chat2", Type="gift", Date="29.09.2023"}, new Models.WishlistModel {Id = "1", Name = "Chat2", Type="gift", CreateById="1"},
new Wishlist {Id = 2, Name = "Chat3", Type="product", Date="02.10.2023"} new Models.WishlistModel {Id = "2", Name = "Chat3", Type="product", CreateById="2"}
}; };
public void OnGet() public void OnGet()
{ {
} }
public void OnPostDelete(int id) { public void OnPostDelete(string id) {
var item = wishlist.FirstOrDefault(wishlist => wishlist.Id == id); var item = wishlist.FirstOrDefault(wishlist => wishlist.Id == id);
wishlist.RemoveAt(id); wishlist.RemoveAt(Int32.Parse(id));
} }
public IActionResult OnPostMoveToChat() { public IActionResult OnPostMoveToChat() {
return RedirectToPage("Index"); return RedirectToPage("Index");
} }
} }
public class Wishlist {
public int Id {get; set;}
public string Name {get; set;}
public string Type {get; set;}
public string Date {get; set;}
}
} }