├── App.razor ├── Controllers ├── PizzaController.cs └── WeatherForecastController.cs ├── Data ├── AppDbContext.cs └── Migrations │ ├── 20230422174632_initials.Designer.cs │ ├── 20230422174632_initials.cs │ ├── 20230422175804_UpdateTables.Designer.cs │ ├── 20230422175804_UpdateTables.cs │ └── AppDbContextModelSnapshot.cs ├── DataModels ├── MyOrdersModel.cs ├── OrderModel.cs ├── PizzaModel.cs └── Response.cs ├── Models └── Pizza.cs ├── Pages ├── AdministrationComponent.razor ├── Error.cshtml ├── Error.cshtml.cs ├── Index.razor ├── MyOrders.razor ├── PizzaList.razor └── _Host.cshtml ├── PizzaBay.csproj ├── PizzaBay.csproj.user ├── PizzaBay.sln ├── PizzaBayServer.csproj ├── PizzaBayServer.csproj.user ├── PizzaLogic.csproj ├── Program.cs ├── Properties └── launchSettings.json ├── README.md ├── Services ├── IOrderService.cs ├── IService.cs ├── OrderService.cs └── Service.cs ├── _Imports.razor ├── appsettings.Development.json └── appsettings.json /App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /Controllers/PizzaController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc; 3 | using PizzaBayServer.Services; 4 | using PizzaLogic.DataModels; 5 | using PizzaLogic.Models; 6 | 7 | namespace PizzaBayServer.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | [ApiController] 11 | public class PizzaController : ControllerBase 12 | { 13 | private readonly IService service; 14 | 15 | public PizzaController(IService service) 16 | { 17 | this.service = service; 18 | } 19 | 20 | //Piza 21 | [HttpPost] 22 | public async Task> AddPizza(Pizza model) 23 | { 24 | if (model != null) 25 | return Ok(await service.AddPizza(model)); 26 | return BadRequest(); 27 | } 28 | 29 | [HttpGet] 30 | public async Task>> GetPizzas() 31 | { 32 | var pizzas = await service.GetPizzas(); 33 | if (pizzas != null) 34 | return Ok(pizzas); 35 | return BadRequest(new Response { Success = false, Message = "No data found" }); 36 | } 37 | 38 | [HttpGet("{id:int}")] 39 | public async Task> GetPizza(int id) 40 | { 41 | if (id > 0) 42 | { 43 | return Ok(await service.GetPizza(id)); 44 | } 45 | return BadRequest("Sorry Error occured"); 46 | } 47 | [HttpDelete("{id:int}")] 48 | public async Task> DeletePizza(int id) 49 | { 50 | if (id > 0) 51 | { 52 | return Ok(await service.DeletePizza(id)); 53 | } 54 | return BadRequest("Sorry Error occured"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace PizzaBayServer.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Data/AppDbContext.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.EntityFrameworkCore; 3 | using PizzaLogic.Models; 4 | 5 | namespace Server.Data 6 | { 7 | public class AppDbContext : DbContext 8 | { 9 | public AppDbContext(DbContextOptions options) : base(options) 10 | { 11 | } 12 | public DbSet Pizzas { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Data/Migrations/20230422174632_initials.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using Server.Data; 8 | 9 | #nullable disable 10 | 11 | namespace PizzaBayServer.Data.Migrations 12 | { 13 | [DbContext(typeof(AppDbContext))] 14 | [Migration("20230422174632_initials")] 15 | partial class initials 16 | { 17 | /// 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "7.0.5") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 26 | 27 | modelBuilder.Entity("PizzaLogic.Models.Pizza", b => 28 | { 29 | b.Property("Id") 30 | .ValueGeneratedOnAdd() 31 | .HasColumnType("int"); 32 | 33 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 34 | 35 | b.Property("Description") 36 | .HasColumnType("nvarchar(max)"); 37 | 38 | b.Property("ExtraLargePrice") 39 | .HasColumnType("float"); 40 | 41 | b.Property("Image") 42 | .HasColumnType("nvarchar(max)"); 43 | 44 | b.Property("LargePrice") 45 | .HasColumnType("float"); 46 | 47 | b.Property("MediumPrice") 48 | .HasColumnType("float"); 49 | 50 | b.Property("Name") 51 | .HasColumnType("nvarchar(max)"); 52 | 53 | b.Property("SmallPrice") 54 | .HasColumnType("float"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Pizzas"); 59 | }); 60 | 61 | modelBuilder.Entity("PizzaLogic.Models.Size", b => 62 | { 63 | b.Property("Id") 64 | .ValueGeneratedOnAdd() 65 | .HasColumnType("int"); 66 | 67 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 68 | 69 | b.Property("Name") 70 | .HasColumnType("nvarchar(max)"); 71 | 72 | b.Property("Number") 73 | .HasColumnType("int"); 74 | 75 | b.HasKey("Id"); 76 | 77 | b.ToTable("Sizes"); 78 | }); 79 | #pragma warning restore 612, 618 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Data/Migrations/20230422174632_initials.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace PizzaBayServer.Data.Migrations 6 | { 7 | /// 8 | public partial class initials : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.CreateTable( 14 | name: "Pizzas", 15 | columns: table => new 16 | { 17 | Id = table.Column(type: "int", nullable: false) 18 | .Annotation("SqlServer:Identity", "1, 1"), 19 | Name = table.Column(type: "nvarchar(max)", nullable: true), 20 | Image = table.Column(type: "nvarchar(max)", nullable: true), 21 | Description = table.Column(type: "nvarchar(max)", nullable: true), 22 | SmallPrice = table.Column(type: "float", nullable: false), 23 | MediumPrice = table.Column(type: "float", nullable: false), 24 | LargePrice = table.Column(type: "float", nullable: false), 25 | ExtraLargePrice = table.Column(type: "float", nullable: false) 26 | }, 27 | constraints: table => 28 | { 29 | table.PrimaryKey("PK_Pizzas", x => x.Id); 30 | }); 31 | 32 | migrationBuilder.CreateTable( 33 | name: "Sizes", 34 | columns: table => new 35 | { 36 | Id = table.Column(type: "int", nullable: false) 37 | .Annotation("SqlServer:Identity", "1, 1"), 38 | Number = table.Column(type: "int", nullable: false), 39 | Name = table.Column(type: "nvarchar(max)", nullable: true) 40 | }, 41 | constraints: table => 42 | { 43 | table.PrimaryKey("PK_Sizes", x => x.Id); 44 | }); 45 | } 46 | 47 | /// 48 | protected override void Down(MigrationBuilder migrationBuilder) 49 | { 50 | migrationBuilder.DropTable( 51 | name: "Pizzas"); 52 | 53 | migrationBuilder.DropTable( 54 | name: "Sizes"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Data/Migrations/20230422175804_UpdateTables.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using Server.Data; 8 | 9 | #nullable disable 10 | 11 | namespace PizzaBayServer.Data.Migrations 12 | { 13 | [DbContext(typeof(AppDbContext))] 14 | [Migration("20230422175804_UpdateTables")] 15 | partial class UpdateTables 16 | { 17 | /// 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "7.0.5") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 26 | 27 | modelBuilder.Entity("PizzaLogic.Models.Pizza", b => 28 | { 29 | b.Property("Id") 30 | .ValueGeneratedOnAdd() 31 | .HasColumnType("int"); 32 | 33 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 34 | 35 | b.Property("Description") 36 | .HasColumnType("nvarchar(max)"); 37 | 38 | b.Property("ExtraLargePrice") 39 | .HasColumnType("float"); 40 | 41 | b.Property("Image") 42 | .HasColumnType("nvarchar(max)"); 43 | 44 | b.Property("LargePrice") 45 | .HasColumnType("float"); 46 | 47 | b.Property("MediumPrice") 48 | .HasColumnType("float"); 49 | 50 | b.Property("Name") 51 | .HasColumnType("nvarchar(max)"); 52 | 53 | b.Property("SmallPrice") 54 | .HasColumnType("float"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Pizzas"); 59 | }); 60 | #pragma warning restore 612, 618 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Data/Migrations/20230422175804_UpdateTables.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace PizzaBayServer.Data.Migrations 6 | { 7 | /// 8 | public partial class UpdateTables : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.DropTable( 14 | name: "Sizes"); 15 | } 16 | 17 | /// 18 | protected override void Down(MigrationBuilder migrationBuilder) 19 | { 20 | migrationBuilder.CreateTable( 21 | name: "Sizes", 22 | columns: table => new 23 | { 24 | Id = table.Column(type: "int", nullable: false) 25 | .Annotation("SqlServer:Identity", "1, 1"), 26 | Name = table.Column(type: "nvarchar(max)", nullable: true), 27 | Number = table.Column(type: "int", nullable: false) 28 | }, 29 | constraints: table => 30 | { 31 | table.PrimaryKey("PK_Sizes", x => x.Id); 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Data/Migrations/AppDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 6 | using Server.Data; 7 | 8 | #nullable disable 9 | 10 | namespace PizzaBayServer.Data.Migrations 11 | { 12 | [DbContext(typeof(AppDbContext))] 13 | partial class AppDbContextModelSnapshot : ModelSnapshot 14 | { 15 | protected override void BuildModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder 19 | .HasAnnotation("ProductVersion", "7.0.5") 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 21 | 22 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 23 | 24 | modelBuilder.Entity("PizzaLogic.Models.Pizza", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("int"); 29 | 30 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 31 | 32 | b.Property("Description") 33 | .HasColumnType("nvarchar(max)"); 34 | 35 | b.Property("ExtraLargePrice") 36 | .HasColumnType("float"); 37 | 38 | b.Property("Image") 39 | .HasColumnType("nvarchar(max)"); 40 | 41 | b.Property("LargePrice") 42 | .HasColumnType("float"); 43 | 44 | b.Property("MediumPrice") 45 | .HasColumnType("float"); 46 | 47 | b.Property("Name") 48 | .HasColumnType("nvarchar(max)"); 49 | 50 | b.Property("SmallPrice") 51 | .HasColumnType("float"); 52 | 53 | b.HasKey("Id"); 54 | 55 | b.ToTable("Pizzas"); 56 | }); 57 | #pragma warning restore 612, 618 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /DataModels/MyOrdersModel.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace PizzaLogic.DataModels 3 | { 4 | public class MyOrdersModel 5 | { 6 | public int PizzaId { get; set; } 7 | public string? Name { get; set; } 8 | public string? Image { get; set; } 9 | public string? SizeName { get; set; } 10 | public double Price { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DataModels/OrderModel.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | namespace PizzaLogic.DataModels 4 | { 5 | public class OrderModel 6 | { 7 | public int PizzaId { get; set; } 8 | public double PizzaPrice { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DataModels/PizzaModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace PizzaLogic.DataModels 10 | { 11 | public class PizzaModel 12 | { 13 | public int Id { get; set; } 14 | [Required] 15 | public string? Name { get; set; } 16 | [Required] 17 | public string? Image { get; set; } 18 | [Required] 19 | public string? Description { get; set; } 20 | [DataType(DataType.Currency)] 21 | [Required] 22 | public double SmallPrice { get; set; } = 1.99; 23 | [DataType(DataType.Currency)] 24 | [Required] 25 | public double MediumPrice { get; set; } = 2.99; 26 | [DataType(DataType.Currency)] 27 | [Required] 28 | public double LargePrice { get; set; } = 3.99; 29 | [DataType(DataType.Currency)] 30 | [Required] 31 | public double ExtraLargePrice { get; set; } = 4.99; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /DataModels/Response.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace PizzaLogic.DataModels 3 | { 4 | public class Response 5 | { 6 | public bool Success { get; set; } = true; 7 | public string Message { get; set; } = "Proccess Done!"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Models/Pizza.cs: -------------------------------------------------------------------------------- 1 |  2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace PizzaLogic.Models 5 | { 6 | public class Pizza 7 | { 8 | public int Id { get; set; } 9 | 10 | public string? Name { get; set; } 11 | public string? Image { get; set; } 12 | public string? Description { get; set; } 13 | public double SmallPrice { get; set; } 14 | public double MediumPrice { get; set; } 15 | public double LargePrice { get; set; } 16 | public double ExtraLargePrice { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Pages/AdministrationComponent.razor: -------------------------------------------------------------------------------- 1 | @page "/manage" 2 | @page "/manage/{id:int}" 3 | @inject HttpClient httpClient 4 | @inject IJSRuntime JS 5 | @inject NavigationManager navigationManager 6 | 7 | @*Dialog box*@ 8 |
9 | 10 | 11 |
12 | @if (Id > 0) 13 | { 14 |

Update Pizza

15 | } 16 | else 17 | { 18 |

Add Pizza

19 | } 20 |
21 | 22 |
23 |
24 | 25 | 26 |
27 | 28 | 29 | 30 |
31 |
32 | 33 | 34 | 35 |
36 |
37 |
38 |
39 |
40 | 41 | 42 |
43 |
44 |
45 |
46 |
47 | 48 | 49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | 57 | 58 |
59 |
60 |
61 |
62 |
63 | 64 | 65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |   @uploadMessage 73 | 74 | 75 |
76 |
77 |
78 |
79 |
80 | 81 |
82 |
83 |
84 |
85 | @if (Id > 0) 86 | { 87 | 90 | 93 | } 94 | else 95 | { 96 | 99 | 102 | 105 | } 106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | 114 | @*SfGrid component*@ 115 | 116 |
117 |
118 |
119 | 120 |
121 |
122 |
123 |
124 | @{ 125 | var SearchTool = new List() { "Add", "Edit", "Delete", "Update", "Cancel", "Search", "Print", "ExcelExport", "PdfExport", "CsvExport" }; 126 | } 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 141 | 142 | 143 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 |
160 | 161 |
162 | 163 | @code { 164 | [Parameter] public int Id { get; set; } 165 | 166 | SfGrid? sfGrid; 167 | 168 | string uploadMessage = string.Empty; 169 | private bool IsVisible { get; set; } = false; 170 | 171 | List pizzas = new(); 172 | PizzaModel pizza = new(); 173 | 174 | protected override async Task OnInitializedAsync() 175 | { 176 | await GetPizzas(); 177 | if (Id > 0) 178 | { 179 | var result = await httpClient.GetFromJsonAsync($"api/pizza/{Id}"); 180 | pizza = await ConvertPizzaToPizzaModel(result!); 181 | OpenDialog(); 182 | } 183 | } 184 | 185 | protected override async Task OnParametersSetAsync() 186 | { 187 | if (Id > 0) 188 | { 189 | var result = await httpClient.GetFromJsonAsync($"api/pizza/{Id}"); 190 | pizza = await ConvertPizzaToPizzaModel(result!); 191 | OpenDialog(); 192 | } 193 | 194 | } 195 | 196 | private async Task ConvertPizzaToPizzaModel(Pizza model) 197 | { 198 | var r = new PizzaModel 199 | { 200 | Id = model.Id, 201 | Name = model.Name, 202 | Description = model.Description, 203 | SmallPrice = model.SmallPrice, 204 | MediumPrice = model.MediumPrice, 205 | LargePrice = model.LargePrice, 206 | ExtraLargePrice = model.ExtraLargePrice, 207 | Image = model.Image 208 | }; 209 | return r; 210 | } 211 | private async Task ConvertPizzaModelToPizza(PizzaModel model) 212 | { 213 | var r = new Pizza 214 | { 215 | Id = model.Id, 216 | Name = model.Name, 217 | Description = model.Description, 218 | SmallPrice = model.SmallPrice, 219 | MediumPrice = model.MediumPrice, 220 | LargePrice = model.LargePrice, 221 | ExtraLargePrice = model.ExtraLargePrice, 222 | Image = model.Image 223 | }; 224 | return r; 225 | } 226 | 227 | private void OpenDialog() 228 | { 229 | this.IsVisible = true; 230 | } 231 | private void HandleDialogClick() 232 | { 233 | navigationManager.NavigateTo("/manage"); 234 | ClearModel(); 235 | OpenDialog(); 236 | } 237 | 238 | private void ClearModel() 239 | { 240 | pizza.Name = null!; 241 | pizza.Description = null; 242 | pizza.Image = null; 243 | pizza.SmallPrice = 0.00; 244 | pizza.MediumPrice = 0.00; 245 | pizza.LargePrice = 0.00; 246 | pizza.ExtraLargePrice = 0.00; 247 | } 248 | 249 | private void CancelClick() 250 | { 251 | this.IsVisible = false; 252 | } 253 | 254 | private async Task HandleAdd() 255 | { 256 | var model = await ConvertPizzaModelToPizza(pizza); 257 | var result = await httpClient.PostAsJsonAsync("api/pizza", model); 258 | var response = await result.Content.ReadFromJsonAsync(); 259 | await GetPizzas(); 260 | sfGrid?.Refresh(); 261 | await JS.InvokeVoidAsync("alert", response!.Message); 262 | 263 | } 264 | 265 | private async Task OnFileChange(InputFileChangeEventArgs e) 266 | { 267 | var format = ""; uploadMessage = ""; 268 | if (e.File.Name.ToLower().Contains(".jpg")) 269 | { 270 | format = "image/jpg"; 271 | } 272 | else if (e.File.Name.ToLower().Contains(".jpeg")) 273 | { 274 | format = "image/jpeg"; 275 | } 276 | else if (e.File.Name.ToLower().Contains(".png")) 277 | { 278 | format = "image/png"; 279 | } 280 | else 281 | { 282 | uploadMessage = "Invalid file selected (jpg, jpeg, png only)"; 283 | return; 284 | } 285 | var resizeImage = await e.File.RequestImageFileAsync(format, 100, 100); 286 | var buffer = new byte[resizeImage.Size]; 287 | await resizeImage.OpenReadStream().ReadAsync(buffer); 288 | var imageData = $"data:{format};base64,{Convert.ToBase64String(buffer)}"; 289 | pizza.Image = imageData; 290 | } 291 | 292 | private async Task GetPizzas() 293 | { 294 | pizzas = await httpClient.GetFromJsonAsync>("api/pizza"); 295 | } 296 | 297 | public async void ActionBeginHandler(ActionEventArgs Args) 298 | { 299 | if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) 300 | { 301 | if (Args.Data.Name != null && Args.Data.Description != null && Args.Data.SmallPrice > 0 && Args.Data.MediumPrice > 0 302 | && Args.Data.LargePrice > 0 && Args.Data.ExtraLargePrice > 0) 303 | { 304 | var result = await httpClient.PostAsJsonAsync("api/pizza", Args.Data); 305 | var response = await result.Content.ReadFromJsonAsync(); 306 | await JS.InvokeVoidAsync("alert", response!.Message); 307 | await GetPizzas(); 308 | sfGrid?.Refresh(); 309 | } 310 | else 311 | { 312 | await JS.InvokeVoidAsync("alert", "All fields required"); 313 | } 314 | } 315 | 316 | if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)) 317 | { 318 | var result = await httpClient.DeleteAsync($"api/pizza/{Args.Data.Id}"); 319 | var response = await result.Content.ReadFromJsonAsync(); 320 | await JS.InvokeVoidAsync("alert", response!.Message); 321 | await GetPizzas(); 322 | sfGrid?.Refresh(); 323 | } 324 | } 325 | } 326 | 327 | 328 | 329 | 330 | 331 | -------------------------------------------------------------------------------- /Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model PizzaBay.Pages.ErrorModel 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Error 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Error.

19 |

An error occurred while processing your request.

20 | 21 | @if (Model.ShowRequestId) 22 | { 23 |

24 | Request ID: @Model.RequestId 25 |

26 | } 27 | 28 |

Development Mode

29 |

30 | Swapping to the Development environment displays detailed information about the error that occurred. 31 |

32 |

33 | The Development environment shouldn't be enabled for deployed applications. 34 | It can result in displaying sensitive information from exceptions to end users. 35 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 36 | and restarting the app. 37 |

38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.AspNetCore.Mvc.RazorPages; 3 | using System.Diagnostics; 4 | 5 | namespace PizzaBay.Pages 6 | { 7 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 8 | [IgnoreAntiforgeryToken] 9 | public class ErrorModel : PageModel 10 | { 11 | public string? RequestId { get; set; } 12 | 13 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 14 | 15 | private readonly ILogger _logger; 16 | 17 | public ErrorModel(ILogger logger) 18 | { 19 | _logger = logger; 20 | } 21 | 22 | public void OnGet() 23 | { 24 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @page "/{id:int}" 3 | @if (Id > 0) 4 | { 5 | 6 | } 7 | else 8 | { 9 | 10 | } 11 | 12 | 13 | @code { 14 | [Parameter] public int Id { get; set; } 15 | } -------------------------------------------------------------------------------- /Pages/MyOrders.razor: -------------------------------------------------------------------------------- 1 | @page "/my-orders" 2 | @using PizzaBay.Services; 3 | @inject IOrderService orderService 4 | @inject IJSRuntime JS 5 | 6 |
7 | @if (myOrdersList != null && myOrdersList.Count() != 0) 8 | { 9 | var SearchTool = new List() { "Delete", "Search" }; 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | @{ 21 | var count = (context as AggregateTemplateContext); 22 |
23 |

No. Ordering: @count!.Count

24 |
25 | } 26 |
27 |
28 |
29 |
30 | 31 | 32 | 33 | 34 | @{ 35 | var grandTotal = (context as AggregateTemplateContext); 36 |
37 |

Total: Gh¢ @grandTotal!.Sum

38 |
39 | } 40 |
41 |
42 |
43 |
44 |
45 | 46 | 47 | 53 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 | } 69 | else 70 | { 71 |
72 |

No Pizza Ordered

73 |

Order Now!

74 |
75 | } 76 |
77 | 78 | 79 | 80 | @code { 81 | SfGrid? sfGrid; 82 | string Message = string.Empty; 83 | List myOrdersList = new(); 84 | 85 | protected override async Task OnAfterRenderAsync(bool firstRender) 86 | { 87 | if (firstRender) 88 | await GetOderedData(); 89 | } 90 | 91 | private async Task GetOderedData() 92 | { 93 | myOrdersList = await orderService.GetOrders(); 94 | StateHasChanged(); 95 | } 96 | 97 | public async void ActionBeginHandler(ActionEventArgs Args) 98 | { 99 | if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)) 100 | { 101 | var result = await orderService.DeleteOrder(Args.Data.PizzaId); 102 | await JS.InvokeVoidAsync("alert", $"{result.Message}"); 103 | await GetOderedData(); sfGrid?.Refresh(); 104 | } 105 | } 106 | 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Pages/PizzaList.razor: -------------------------------------------------------------------------------- 1 | @using PizzaBay.Services; 2 | 3 | @inject HttpClient httpClient 4 | @inject ILocalStorageService localStorageService 5 | @inject IJSRuntime JS 6 | @inject IOrderService orderService 7 | 8 |
9 | 10 | 11 |
Order Pizza
12 | 13 | @if (pizza != null) 14 | { 15 | 16 |
17 |
18 | @{ 19 |

Choose Size

20 | string small = "Small ( ¢" + pizza.SmallPrice.ToString("0.00") + " )"; 21 | string medium = "Medium ( ¢" + pizza.MediumPrice.ToString("0.00") + " )"; 22 | string large = "Large ( ¢" + pizza.LargePrice.ToString("0.00") + " )"; 23 | string extralarge = "Extra Large ( ¢" + pizza.ExtraLargePrice.ToString("0.00") + " )"; 24 | } 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 |
34 |
@pizza.Description
35 |
36 |
37 |
38 | } 39 |
40 |
41 | 42 | 43 | 44 | 45 |
46 | 47 | @if (pizzas != null) 48 | { 49 | foreach (var item in pizzas) 50 | { 51 | 52 | 60 | 61 | } 62 | } 63 | 64 | @code { 65 | [Parameter] public int Id { get; set; } 66 | SfDialog? sfDialog; 67 | 68 | private string stringChecked = "0"; 69 | private bool IsVisible { get; set; } = false; 70 | 71 | List pizzas = new(); 72 | Pizza pizza = new(); 73 | 74 | protected override async Task OnInitializedAsync() 75 | { 76 | await GetPizzas(); 77 | } 78 | 79 | private async Task GetPizzas() 80 | { 81 | pizzas = await httpClient.GetFromJsonAsync>("api/pizza"); 82 | } 83 | 84 | private async Task HandlePizzaClick(int id) 85 | { 86 | pizza = await httpClient.GetFromJsonAsync($"api/pizza/{id}"); 87 | this.IsVisible = true; 88 | 89 | } 90 | 91 | protected override async Task OnParametersSetAsync() 92 | { 93 | if (Id > 0) 94 | await HandlePizzaClick(Id); 95 | } 96 | 97 | private void CancelClick() 98 | { 99 | this.IsVisible = false; 100 | } 101 | 102 | private async Task AddToListClick(int id) 103 | { 104 | this.IsVisible = true; 105 | if (Convert.ToDouble(stringChecked) > 0) 106 | { 107 | var orderModel = new OrderModel { PizzaId = id, PizzaPrice = Convert.ToDouble(stringChecked) }; 108 | var result = await orderService.AddOrder(orderModel); 109 | stringChecked = "0"; 110 | await JS.InvokeVoidAsync("alert", result.Message); 111 | } 112 | else { await JS.InvokeVoidAsync("alert", "Please select Pizza Size"); } 113 | } 114 | 115 | private void onValueChange(ChangeArgs args) 116 | { 117 | stringChecked = args.Value; 118 | } 119 | } 120 | 121 | 122 | 123 | 129 | -------------------------------------------------------------------------------- /Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using Microsoft.AspNetCore.Components.Web 3 | @namespace PizzaBay.Pages 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | An error has occurred. This application may no longer respond until reloaded. 28 | 29 | 30 | An unhandled exception has occurred. See browser dev tools for details. 31 | 32 | Reload 33 | 🗙 34 |
35 | 36 | 37 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /PizzaBay.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /PizzaBay.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | https 5 | 6 | -------------------------------------------------------------------------------- /PizzaBay.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33606.364 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzaBay", "PizzaBay\PizzaBay.csproj", "{82B9970B-2312-4633-A6AA-451C11EDE456}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzaBayServer", "PizzaBayServer\PizzaBayServer.csproj", "{10C08E38-756F-4594-AFC0-446796E8F17A}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzaLogic", "PizzaLogic\PizzaLogic.csproj", "{96B17DD2-FB44-459E-A551-DD72B8EDAE6E}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {82B9970B-2312-4633-A6AA-451C11EDE456}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {82B9970B-2312-4633-A6AA-451C11EDE456}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {82B9970B-2312-4633-A6AA-451C11EDE456}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {82B9970B-2312-4633-A6AA-451C11EDE456}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {10C08E38-756F-4594-AFC0-446796E8F17A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {10C08E38-756F-4594-AFC0-446796E8F17A}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {10C08E38-756F-4594-AFC0-446796E8F17A}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {10C08E38-756F-4594-AFC0-446796E8F17A}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {96B17DD2-FB44-459E-A551-DD72B8EDAE6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {96B17DD2-FB44-459E-A551-DD72B8EDAE6E}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {96B17DD2-FB44-459E-A551-DD72B8EDAE6E}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {96B17DD2-FB44-459E-A551-DD72B8EDAE6E}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {48F198DF-412B-461B-942F-AD5104101B48} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /PizzaBayServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | all 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /PizzaBayServer.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | https 5 | ApiControllerEmptyScaffolder 6 | root/Common/Api 7 | 8 | -------------------------------------------------------------------------------- /PizzaLogic.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Net.Http.Headers; 3 | using PizzaBayServer.Services; 4 | using Server.Data; 5 | 6 | var builder = WebApplication.CreateBuilder(args); 7 | 8 | // Add services to the container. 9 | 10 | builder.Services.AddControllers(); 11 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 12 | builder.Services.AddEndpointsApiExplorer(); 13 | builder.Services.AddSwaggerGen(); 14 | 15 | builder.Services.AddDbContext(Options => 16 | { 17 | Options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")); 18 | }); 19 | builder.Services.AddScoped(); 20 | var app = builder.Build(); 21 | 22 | // Configure the HTTP request pipeline. 23 | if (app.Environment.IsDevelopment()) 24 | { 25 | app.UseSwagger(); 26 | app.UseSwaggerUI(); 27 | app.UseCors(policy => 28 | { 29 | policy.WithOrigins("http://localhost:7266", "https://localhost:7266") //do not add the forward slash at end 30 | .AllowAnyMethod() 31 | .WithHeaders(HeaderNames.ContentType); 32 | }); 33 | } 34 | 35 | app.UseHttpsRedirection(); 36 | 37 | app.UseAuthorization(); 38 | 39 | app.MapControllers(); 40 | 41 | app.Run(); 42 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:53661", 8 | "sslPort": 44312 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5283", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7073;http://localhost:5283", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NET 7 Pizza Ordering Shop in Blazor Server - Full Project
2 | 3 | /*Follow Netcode-Hub*/
4 | https://netcodehub.blogspot.com
5 | https://github.com/Netcode-Hub
6 | https://twitter.com/NetcodeHub | Twitter
7 | https://web.facebook.com/NetcodeHub | Facebook
8 | https://www.linkedin.com/in/netcode-hub-90b188258/ | LinkedIn
9 | 10 | /*You can buy a coffee for me to support the channel*/ ☕️
11 | https://www.buymeacoffee.com/NetcodeHub
12 | 13 | PLEASE DO NOT FOGET TO STAR THIS REPOSITORY
14 | -------------------------------------------------------------------------------- /Services/IOrderService.cs: -------------------------------------------------------------------------------- 1 | using PizzaLogic.DataModels; 2 | 3 | namespace PizzaBay.Services 4 | { 5 | public interface IOrderService 6 | { 7 | event Action OnChange; 8 | int Count { get; set; } 9 | Task AddOrder(OrderModel model); 10 | Task RefreshCount(); 11 | Task> GetOrders(); 12 | Task DeleteOrder(int id); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Services/IService.cs: -------------------------------------------------------------------------------- 1 | using PizzaLogic.DataModels; 2 | using PizzaLogic.Models; 3 | 4 | namespace PizzaBayServer.Services 5 | { 6 | public interface IService 7 | { 8 | Task AddPizza(Pizza model); 9 | Task> GetPizzas(); 10 | Task GetPizza(int id); 11 | Task DeletePizza(int id); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Services/OrderService.cs: -------------------------------------------------------------------------------- 1 | using Blazored.LocalStorage; 2 | using PizzaLogic.DataModels; 3 | using PizzaLogic.Models; 4 | 5 | namespace PizzaBay.Services 6 | { 7 | public class OrderService : IOrderService 8 | { 9 | private readonly ILocalStorageService localStorageService; 10 | private readonly HttpClient httpClient; 11 | 12 | public OrderService(ILocalStorageService localStorageService, HttpClient httpClient) 13 | { 14 | this.localStorageService = localStorageService; 15 | this.httpClient = httpClient; 16 | } 17 | 18 | public int Count { get; set; } 19 | 20 | public event Action? OnChange; 21 | 22 | public async Task AddOrder(OrderModel model) 23 | { 24 | var orderModel = new OrderModel { PizzaId = model.PizzaId, PizzaPrice = Convert.ToDouble(model.PizzaPrice) }; 25 | 26 | var MyOrder = await localStorageService.GetItemAsync>("MyOrder"); 27 | if (MyOrder == null) 28 | { 29 | MyOrder = new List { orderModel }; 30 | await localStorageService.SetItemAsync("MyOrder", MyOrder); 31 | await InvokeAndCount(); 32 | return new Response { Success = true, Message = "Order created successfully" }; 33 | 34 | } 35 | else 36 | { 37 | var checkEx = MyOrder.FirstOrDefault(i => i.PizzaId == orderModel.PizzaId); 38 | if (checkEx != null) 39 | { 40 | if (checkEx.PizzaPrice != orderModel.PizzaPrice) 41 | { 42 | MyOrder.Remove(checkEx); 43 | MyOrder.Add(orderModel); 44 | await localStorageService.SetItemAsync("MyOrder", MyOrder); 45 | await InvokeAndCount(); 46 | return new Response { Success = true, Message = "Order updated successfully" }; 47 | } 48 | } 49 | else 50 | { 51 | MyOrder.Add(orderModel); 52 | await localStorageService.SetItemAsync("MyOrder", MyOrder); 53 | await InvokeAndCount(); 54 | return new Response { Success = true, Message = "Order created successfully" }; 55 | } 56 | } 57 | 58 | return new Response { Success = false, Message = "Order Added already" }; 59 | } 60 | 61 | private async Task InvokeAndCount() 62 | { 63 | Count = (await localStorageService.GetItemAsync>("MyOrder")).Count(); 64 | OnChange?.Invoke(); 65 | } 66 | 67 | public async Task RefreshCount() 68 | { 69 | try 70 | { 71 | Count = (await localStorageService.GetItemAsync>("MyOrder")).Count(); 72 | OnChange?.Invoke(); 73 | return Count; 74 | } 75 | catch (Exception ex) { return 0; } 76 | 77 | } 78 | 79 | public async Task> GetOrders() 80 | { 81 | var myOrdersList = new List(); 82 | var myOrders = await localStorageService.GetItemAsync>("MyOrder"); 83 | 84 | if (myOrders != null && myOrders.Count() > 0) 85 | { 86 | foreach (var item in myOrders) 87 | { 88 | var r = await httpClient.GetFromJsonAsync($"api/pizza/{item.PizzaId}"); 89 | if (r != null) 90 | { 91 | if (Convert.ToDouble(r.SmallPrice) == Convert.ToDouble(item.PizzaPrice) 92 | || Convert.ToDouble(r.MediumPrice) == Convert.ToDouble(item.PizzaPrice) 93 | || Convert.ToDouble(r.LargePrice) == Convert.ToDouble(item.PizzaPrice) 94 | || Convert.ToDouble(r.ExtraLargePrice) == Convert.ToDouble(item.PizzaPrice)) 95 | { 96 | string sizeName = string.Empty; 97 | if (Convert.ToDouble(r.SmallPrice) == Convert.ToDouble(item.PizzaPrice)) 98 | { 99 | sizeName = "Small"; 100 | } 101 | else if (Convert.ToDouble(r.MediumPrice) == Convert.ToDouble(item.PizzaPrice)) 102 | { 103 | sizeName = "Medium"; 104 | } 105 | else if (Convert.ToDouble(r.LargePrice) == Convert.ToDouble(item.PizzaPrice)) 106 | { 107 | sizeName = "Large"; 108 | } 109 | else if (Convert.ToDouble(r.ExtraLargePrice) == Convert.ToDouble(item.PizzaPrice)) 110 | { 111 | sizeName = "Extra Large"; 112 | } 113 | 114 | var myOrderlist = new MyOrdersModel 115 | { 116 | PizzaId = r.Id, 117 | Name = r.Name, 118 | Image = r.Image, 119 | Price = item.PizzaPrice, 120 | SizeName = sizeName 121 | }; 122 | myOrdersList.Add(myOrderlist); 123 | } 124 | } 125 | } 126 | return myOrdersList; 127 | } 128 | return null!; 129 | } 130 | 131 | public async Task DeleteOrder(int id) 132 | { 133 | var myOrders = await localStorageService.GetItemAsync>("MyOrder"); 134 | var r = myOrders.FirstOrDefault(i => i.PizzaId == id); 135 | if (r != null) 136 | { 137 | myOrders.Remove(r); 138 | await localStorageService.SetItemAsync("MyOrder", myOrders); 139 | await InvokeAndCount(); 140 | return new Response { Success = true, Message = "Order deleted successfully" }; 141 | } 142 | return new Response { Success = false, Message = "Error Occured : Order not found" }; 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Services/Service.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using PizzaLogic.DataModels; 3 | using PizzaLogic.Models; 4 | using Server.Data; 5 | 6 | namespace PizzaBayServer.Services 7 | { 8 | public class Service : IService 9 | { 10 | private readonly AppDbContext appDbContext; 11 | 12 | public Service(AppDbContext appDbContext) 13 | { 14 | this.appDbContext = appDbContext; 15 | } 16 | 17 | //pizza 18 | public async Task AddPizza(Pizza model) 19 | { 20 | if (model != null) 21 | { 22 | if (model.Id > 0) 23 | { 24 | var result = await GetPizza(model.Id); 25 | if (result != null) 26 | { 27 | result.Name = model.Name; 28 | result.Description = model.Description; 29 | result.SmallPrice = model.SmallPrice; 30 | result.MediumPrice = model.MediumPrice; 31 | result.LargePrice = model.LargePrice; 32 | result.ExtraLargePrice = model.ExtraLargePrice; 33 | result.Image = model.Image; 34 | await appDbContext.SaveChangesAsync(); 35 | return new Response { Success = true, Message = $"{model.Name} updated successfully" }; 36 | } 37 | return new Response { Success = false, Message = $"Error occured, {model.Name} not found" }; 38 | } 39 | else 40 | { 41 | var checkEx = await appDbContext.Pizzas.Where(i => i.Name!.ToLower().Equals(model.Name!.ToLower())) 42 | .FirstOrDefaultAsync(); 43 | if (checkEx == null) 44 | { 45 | appDbContext.Pizzas.Add(model); await appDbContext.SaveChangesAsync(); 46 | return new Response(); 47 | } 48 | return new Response { Success = false, Message = "Already added" }; 49 | } 50 | } 51 | return new Response { Success = false, Message = "All fields required" }; 52 | 53 | } 54 | 55 | public async Task> GetPizzas() 56 | { 57 | return await appDbContext.Pizzas.ToListAsync(); 58 | } 59 | 60 | public async Task GetPizza(int id) 61 | { 62 | var result = await appDbContext.Pizzas.FirstOrDefaultAsync(i => i.Id == id); 63 | return result!; 64 | } 65 | public async Task DeletePizza(int id) 66 | { 67 | var result = await GetPizza(id); 68 | if (result != null) 69 | { 70 | appDbContext.Pizzas.Remove(result); await appDbContext.SaveChangesAsync(); 71 | return new Response { Success = true, Message = $"{result.Name} deleted successfully" }; 72 | } 73 | return new Response { Success = false, Message = "Error occured! Pizza not found" }; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.JSInterop 9 | @using PizzaBay 10 | @using PizzaBay.Shared 11 | @using Syncfusion.Blazor 12 | @using Syncfusion.Blazor.Navigations 13 | @using PizzaBay.Pages 14 | @using Syncfusion.Blazor.Buttons 15 | @using Blazored.LocalStorage; 16 | @using PizzaLogic.DataModels; 17 | @using PizzaLogic.Models; 18 | @using Syncfusion.Blazor.Grids 19 | @using Syncfusion.Blazor.Popups 20 | @using Syncfusion.Blazor.DropDowns 21 | @using Syncfusion.Blazor.Inputs; 22 | -------------------------------------------------------------------------------- /appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=(local); Database=PizzaForYoutube; Trusted_Connection=true; Trust Server Certificate=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft.AspNetCore": "Warning" 9 | } 10 | }, 11 | "AllowedHosts": "*" 12 | } 13 | --------------------------------------------------------------------------------