repository)
13 | {
14 | this.repository = repository;
15 | }
16 |
17 | public IActionResult Index(Guid? id)
18 | {
19 | if (id == null)
20 | {
21 | var customers = repository.All();
22 |
23 | return View(customers);
24 | }
25 | else
26 | {
27 | var customer = repository.Get(id.Value);
28 |
29 | return View(new[] { customer });
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 | Error.
7 | An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID: @Model.RequestId
13 |
14 | }
15 |
16 | Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
22 |
23 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/Views/Customer/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All customers";
5 | }
6 |
7 | Customers
8 |
9 | @foreach (var customer in Model)
10 | {
11 |
12 |
13 |
14 | Customer
15 | @customer.Name
16 |
17 |
)
18 |
19 |
@customer.ShippingAddress
20 |
@customer.City
21 |
@customer.PostalCode
22 |
@customer.Country
23 |
24 |
More details
25 |
26 |
27 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Filip Ekberg
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/wwwroot/lib/jquery-validation/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright Jörn Zaefferer
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2018 Twitter, Inc.
4 | Copyright (c) 2011-2018 The Bootstrap Authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2018 Twitter, Inc.
4 | Copyright (c) 2011-2018 The Bootstrap Authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2018 Twitter, Inc.
4 | Copyright (c) 2011-2018 The Bootstrap Authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2018 Twitter, Inc.
4 | Copyright (c) 2011-2018 The Bootstrap Authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2018 Twitter, Inc.
4 | Copyright (c) 2011-2018 The Bootstrap Authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/wwwroot/lib/bootstrap/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2011-2018 Twitter, Inc.
4 | Copyright (c) 2011-2018 The Bootstrap Authors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/Views/Shared/_ValidationScriptsPartial.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Infrastructure/Repositories/OrderRepository.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using MyShop.Domain.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 |
8 | namespace MyShop.Infrastructure.Repositories
9 | {
10 | public class OrderRepository : GenericRepository
11 | {
12 | public OrderRepository(ShoppingContext context) : base(context)
13 | {
14 | }
15 |
16 | public override IEnumerable Find(Expression> predicate)
17 | {
18 | return context.Orders
19 | .Include(order => order.LineItems)
20 | .ThenInclude(lineItem => lineItem.Product)
21 | .Where(predicate).ToList();
22 | }
23 |
24 | public override Order Update(Order entity)
25 | {
26 | var order = context.Orders
27 | .Include(o => o.LineItems)
28 | .ThenInclude(lineItem => lineItem.Product)
29 | .Single(o => o.OrderId == entity.OrderId);
30 |
31 | order.OrderDate = entity.OrderDate;
32 | order.LineItems = entity.LineItems;
33 |
34 | return base.Update(order);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Infrastructure/Repositories/OrderRepository.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using MyShop.Domain.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 |
8 | namespace MyShop.Infrastructure.Repositories
9 | {
10 | public class OrderRepository : GenericRepository
11 | {
12 | public OrderRepository(ShoppingContext context) : base(context)
13 | {
14 | }
15 |
16 | public override IEnumerable Find(Expression> predicate)
17 | {
18 | return context.Orders
19 | .Include(order => order.LineItems)
20 | .ThenInclude(lineItem => lineItem.Product)
21 | .Where(predicate).ToList();
22 | }
23 |
24 | public override Order Update(Order entity)
25 | {
26 | var order = context.Orders
27 | .Include(o => o.LineItems)
28 | .ThenInclude(lineItem => lineItem.Product)
29 | .Single(o => o.OrderId == entity.OrderId);
30 |
31 | order.OrderDate = entity.OrderDate;
32 | order.LineItems = entity.LineItems;
33 |
34 | return base.Update(order);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Infrastructure/Repositories/OrderRepository.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using MyShop.Domain.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 |
8 | namespace MyShop.Infrastructure.Repositories
9 | {
10 | public class OrderRepository : GenericRepository
11 | {
12 | public OrderRepository(ShoppingContext context) : base(context)
13 | {
14 | }
15 |
16 | public override IEnumerable Find(Expression> predicate)
17 | {
18 | return context.Orders
19 | .Include(order => order.LineItems)
20 | .ThenInclude(lineItem => lineItem.Product)
21 | .Where(predicate).ToList();
22 | }
23 |
24 | public override Order Update(Order entity)
25 | {
26 | var order = context.Orders
27 | .Include(o => o.LineItems)
28 | .ThenInclude(lineItem => lineItem.Product)
29 | .Single(o => o.OrderId == entity.OrderId);
30 |
31 | order.OrderDate = entity.OrderDate;
32 | order.LineItems = entity.LineItems;
33 |
34 | return base.Update(order);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Infrastructure/Repositories/OrderRepository.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using MyShop.Domain.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 |
8 | namespace MyShop.Infrastructure.Repositories
9 | {
10 | public class OrderRepository : GenericRepository
11 | {
12 | public OrderRepository(ShoppingContext context) : base(context)
13 | {
14 | }
15 |
16 | public override IEnumerable Find(Expression> predicate)
17 | {
18 | return context.Orders
19 | .Include(order => order.LineItems)
20 | .ThenInclude(lineItem => lineItem.Product)
21 | .Where(predicate).ToList();
22 | }
23 |
24 | public override Order Update(Order entity)
25 | {
26 | var order = context.Orders
27 | .Include(o => o.LineItems)
28 | .ThenInclude(lineItem => lineItem.Product)
29 | .Single(o => o.OrderId == entity.OrderId);
30 |
31 | order.OrderDate = entity.OrderDate;
32 | order.LineItems = entity.LineItems;
33 |
34 | return base.Update(order);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Infrastructure/Repositories/OrderRepository.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using MyShop.Domain.Models;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 |
8 | namespace MyShop.Infrastructure.Repositories
9 | {
10 | public class OrderRepository : GenericRepository
11 | {
12 | public OrderRepository(ShoppingContext context) : base(context)
13 | {
14 | }
15 |
16 | public override IEnumerable Find(Expression> predicate)
17 | {
18 | return context.Orders
19 | .Include(order => order.LineItems)
20 | .ThenInclude(lineItem => lineItem.Product)
21 | .Where(predicate).ToList();
22 | }
23 |
24 | public override Order Update(Order entity)
25 | {
26 | var order = context.Orders
27 | .Include(o => o.LineItems)
28 | .ThenInclude(lineItem => lineItem.Product)
29 | .Single(o => o.OrderId == entity.OrderId);
30 |
31 | order.OrderDate = entity.OrderDate;
32 | order.LineItems = entity.LineItems;
33 |
34 | return base.Update(order);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/Views/Order/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All orders";
5 | }
6 |
7 | Orders
8 |
9 | @foreach (var order in Model)
10 | {
11 |
12 |
13 |
14 | Order #
15 | @order.OrderId
16 |
17 |
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Views/Order/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All orders";
5 | }
6 |
7 | Orders
8 |
9 | @foreach (var order in Model)
10 | {
11 |
12 |
13 |
14 | Order #
15 | @order.OrderId
16 |
17 |
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/Views/Order/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All orders";
5 | }
6 |
7 | Orders
8 |
9 | @foreach (var order in Model)
10 | {
11 |
12 |
13 |
14 | Order #
15 | @order.OrderId
16 |
17 |
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/Views/Order/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All orders";
5 | }
6 |
7 | Orders
8 |
9 | @foreach (var order in Model)
10 | {
11 |
12 |
13 |
14 | Order #
15 | @order.OrderId
16 |
17 |
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/Views/Order/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All orders";
5 | }
6 |
7 | Orders
8 |
9 | @foreach (var order in Model)
10 | {
11 |
12 |
13 |
14 | Order #
15 | @order.OrderId
16 |
17 |
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/Views/Order/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "All orders";
5 | }
6 |
7 | Orders
8 |
9 | @foreach (var order in Model)
10 | {
11 |
12 |
13 |
14 | Order #
15 | @order.OrderId
16 |
17 |
34 |
35 |
36 | }
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Infrastructure/Repositories/GenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MyShop.Infrastructure.Repositories
7 | {
8 | public abstract class GenericRepository
9 | : IRepository where T : class
10 | {
11 | protected ShoppingContext context;
12 |
13 | public GenericRepository(ShoppingContext context)
14 | {
15 | this.context = context;
16 | }
17 |
18 | public virtual T Add(T entity)
19 | {
20 | return context
21 | .Add(entity)
22 | .Entity;
23 | }
24 |
25 | public virtual IEnumerable Find(Expression> predicate)
26 | {
27 | return context.Set()
28 | .AsQueryable()
29 | .Where(predicate).ToList();
30 | }
31 |
32 | public virtual T Get(Guid id)
33 | {
34 | return context.Find(id);
35 | }
36 |
37 | public virtual IEnumerable All()
38 | {
39 | return context.Set()
40 | .ToList();
41 | }
42 |
43 | public virtual T Update(T entity)
44 | {
45 | return context.Update(entity)
46 | .Entity;
47 | }
48 |
49 | public void SaveChanges()
50 | {
51 | context.SaveChanges();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Infrastructure/Repositories/GenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MyShop.Infrastructure.Repositories
7 | {
8 | public abstract class GenericRepository : IRepository where T : class
9 | {
10 | protected ShoppingContext context;
11 |
12 | public GenericRepository(ShoppingContext context)
13 | {
14 | this.context = context;
15 | }
16 |
17 | public virtual T Add(T entity)
18 | {
19 | return context
20 | .Add(entity)
21 | .Entity;
22 | }
23 |
24 | public virtual IEnumerable Find(Expression> predicate)
25 | {
26 | return context.Set()
27 | .AsQueryable()
28 | .Where(predicate).ToList();
29 | }
30 |
31 | public virtual T Get(Guid id)
32 | {
33 | return context.Find(id);
34 | }
35 |
36 | public virtual IEnumerable All()
37 | {
38 | return context.Set()
39 | .AsQueryable()
40 | .ToList();
41 | }
42 |
43 | public virtual T Update(T entity)
44 | {
45 | return context.Update(entity)
46 | .Entity;
47 | }
48 |
49 | public void SaveChanges()
50 | {
51 | context.SaveChanges();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Infrastructure/Repositories/GenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MyShop.Infrastructure.Repositories
7 | {
8 | public abstract class GenericRepository : IRepository where T : class
9 | {
10 | protected ShoppingContext context;
11 |
12 | public GenericRepository(ShoppingContext context)
13 | {
14 | this.context = context;
15 | }
16 |
17 | public virtual T Add(T entity)
18 | {
19 | return context
20 | .Add(entity)
21 | .Entity;
22 | }
23 |
24 | public virtual IEnumerable Find(Expression> predicate)
25 | {
26 | return context.Set()
27 | .AsQueryable()
28 | .Where(predicate).ToList();
29 | }
30 |
31 | public virtual T Get(Guid id)
32 | {
33 | return context.Find(id);
34 | }
35 |
36 | public virtual IEnumerable All()
37 | {
38 | return context.Set()
39 | .AsQueryable()
40 | .ToList();
41 | }
42 |
43 | public virtual T Update(T entity)
44 | {
45 | return context.Update(entity)
46 | .Entity;
47 | }
48 |
49 | public void SaveChanges()
50 | {
51 | context.SaveChanges();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Infrastructure/Repositories/GenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MyShop.Infrastructure.Repositories
7 | {
8 | public abstract class GenericRepository : IRepository where T : class
9 | {
10 | protected ShoppingContext context;
11 |
12 | public GenericRepository(ShoppingContext context)
13 | {
14 | this.context = context;
15 | }
16 |
17 | public virtual T Add(T entity)
18 | {
19 | return context
20 | .Add(entity)
21 | .Entity;
22 | }
23 |
24 | public virtual IEnumerable Find(Expression> predicate)
25 | {
26 | return context.Set()
27 | .AsQueryable()
28 | .Where(predicate).ToList();
29 | }
30 |
31 | public virtual T Get(Guid id)
32 | {
33 | return context.Find(id);
34 | }
35 |
36 | public virtual IEnumerable All()
37 | {
38 | return context.Set()
39 | .AsQueryable()
40 | .ToList();
41 | }
42 |
43 | public virtual T Update(T entity)
44 | {
45 | return context.Update(entity)
46 | .Entity;
47 | }
48 |
49 | public void SaveChanges()
50 | {
51 | context.SaveChanges();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Infrastructure/Repositories/GenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 |
6 | namespace MyShop.Infrastructure.Repositories
7 | {
8 | public abstract class GenericRepository : IRepository where T : class
9 | {
10 | protected ShoppingContext context;
11 |
12 | public GenericRepository(ShoppingContext context)
13 | {
14 | this.context = context;
15 | }
16 |
17 | public virtual T Add(T entity)
18 | {
19 | return context
20 | .Add(entity)
21 | .Entity;
22 | }
23 |
24 | public virtual IEnumerable Find(Expression> predicate)
25 | {
26 | return context.Set()
27 | .AsQueryable()
28 | .Where(predicate).ToList();
29 | }
30 |
31 | public virtual T Get(Guid id)
32 | {
33 | return context.Find(id);
34 | }
35 |
36 | public virtual IEnumerable All()
37 | {
38 | return context.Set()
39 | .AsQueryable()
40 | .ToList();
41 | }
42 |
43 | public virtual T Update(T entity)
44 | {
45 | return context.Update(entity)
46 | .Entity;
47 | }
48 |
49 | public void SaveChanges()
50 | {
51 | context.SaveChanges();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Provide sufficient contrast against white background */
11 | a {
12 | color: #0366d6;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22 | color: #fff;
23 | background-color: #1b6ec2;
24 | border-color: #1861ac;
25 | }
26 |
27 | /* Sticky footer styles
28 | -------------------------------------------------- */
29 | html {
30 | font-size: 14px;
31 | }
32 | @media (min-width: 768px) {
33 | html {
34 | font-size: 16px;
35 | }
36 | }
37 |
38 | .border-top {
39 | border-top: 1px solid #e5e5e5;
40 | }
41 | .border-bottom {
42 | border-bottom: 1px solid #e5e5e5;
43 | }
44 |
45 | .box-shadow {
46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47 | }
48 |
49 | button.accept-policy {
50 | font-size: 1rem;
51 | line-height: inherit;
52 | }
53 |
54 | /* Sticky footer styles
55 | -------------------------------------------------- */
56 | html {
57 | position: relative;
58 | min-height: 100%;
59 | }
60 |
61 | body {
62 | /* Margin bottom by footer height */
63 | margin-bottom: 60px;
64 | }
65 | .footer {
66 | position: absolute;
67 | bottom: 0;
68 | width: 100%;
69 | white-space: nowrap;
70 | line-height: 60px; /* Vertically center the text there */
71 | }
72 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Provide sufficient contrast against white background */
11 | a {
12 | color: #0366d6;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22 | color: #fff;
23 | background-color: #1b6ec2;
24 | border-color: #1861ac;
25 | }
26 |
27 | /* Sticky footer styles
28 | -------------------------------------------------- */
29 | html {
30 | font-size: 14px;
31 | }
32 | @media (min-width: 768px) {
33 | html {
34 | font-size: 16px;
35 | }
36 | }
37 |
38 | .border-top {
39 | border-top: 1px solid #e5e5e5;
40 | }
41 | .border-bottom {
42 | border-bottom: 1px solid #e5e5e5;
43 | }
44 |
45 | .box-shadow {
46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47 | }
48 |
49 | button.accept-policy {
50 | font-size: 1rem;
51 | line-height: inherit;
52 | }
53 |
54 | /* Sticky footer styles
55 | -------------------------------------------------- */
56 | html {
57 | position: relative;
58 | min-height: 100%;
59 | }
60 |
61 | body {
62 | /* Margin bottom by footer height */
63 | margin-bottom: 60px;
64 | }
65 | .footer {
66 | position: absolute;
67 | bottom: 0;
68 | width: 100%;
69 | white-space: nowrap;
70 | line-height: 60px; /* Vertically center the text there */
71 | }
72 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Provide sufficient contrast against white background */
11 | a {
12 | color: #0366d6;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22 | color: #fff;
23 | background-color: #1b6ec2;
24 | border-color: #1861ac;
25 | }
26 |
27 | /* Sticky footer styles
28 | -------------------------------------------------- */
29 | html {
30 | font-size: 14px;
31 | }
32 | @media (min-width: 768px) {
33 | html {
34 | font-size: 16px;
35 | }
36 | }
37 |
38 | .border-top {
39 | border-top: 1px solid #e5e5e5;
40 | }
41 | .border-bottom {
42 | border-bottom: 1px solid #e5e5e5;
43 | }
44 |
45 | .box-shadow {
46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47 | }
48 |
49 | button.accept-policy {
50 | font-size: 1rem;
51 | line-height: inherit;
52 | }
53 |
54 | /* Sticky footer styles
55 | -------------------------------------------------- */
56 | html {
57 | position: relative;
58 | min-height: 100%;
59 | }
60 |
61 | body {
62 | /* Margin bottom by footer height */
63 | margin-bottom: 60px;
64 | }
65 | .footer {
66 | position: absolute;
67 | bottom: 0;
68 | width: 100%;
69 | white-space: nowrap;
70 | line-height: 60px; /* Vertically center the text there */
71 | }
72 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Provide sufficient contrast against white background */
11 | a {
12 | color: #0366d6;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22 | color: #fff;
23 | background-color: #1b6ec2;
24 | border-color: #1861ac;
25 | }
26 |
27 | /* Sticky footer styles
28 | -------------------------------------------------- */
29 | html {
30 | font-size: 14px;
31 | }
32 | @media (min-width: 768px) {
33 | html {
34 | font-size: 16px;
35 | }
36 | }
37 |
38 | .border-top {
39 | border-top: 1px solid #e5e5e5;
40 | }
41 | .border-bottom {
42 | border-bottom: 1px solid #e5e5e5;
43 | }
44 |
45 | .box-shadow {
46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47 | }
48 |
49 | button.accept-policy {
50 | font-size: 1rem;
51 | line-height: inherit;
52 | }
53 |
54 | /* Sticky footer styles
55 | -------------------------------------------------- */
56 | html {
57 | position: relative;
58 | min-height: 100%;
59 | }
60 |
61 | body {
62 | /* Margin bottom by footer height */
63 | margin-bottom: 60px;
64 | }
65 | .footer {
66 | position: absolute;
67 | bottom: 0;
68 | width: 100%;
69 | white-space: nowrap;
70 | line-height: 60px; /* Vertically center the text there */
71 | }
72 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Provide sufficient contrast against white background */
11 | a {
12 | color: #0366d6;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22 | color: #fff;
23 | background-color: #1b6ec2;
24 | border-color: #1861ac;
25 | }
26 |
27 | /* Sticky footer styles
28 | -------------------------------------------------- */
29 | html {
30 | font-size: 14px;
31 | }
32 | @media (min-width: 768px) {
33 | html {
34 | font-size: 16px;
35 | }
36 | }
37 |
38 | .border-top {
39 | border-top: 1px solid #e5e5e5;
40 | }
41 | .border-bottom {
42 | border-bottom: 1px solid #e5e5e5;
43 | }
44 |
45 | .box-shadow {
46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47 | }
48 |
49 | button.accept-policy {
50 | font-size: 1rem;
51 | line-height: inherit;
52 | }
53 |
54 | /* Sticky footer styles
55 | -------------------------------------------------- */
56 | html {
57 | position: relative;
58 | min-height: 100%;
59 | }
60 |
61 | body {
62 | /* Margin bottom by footer height */
63 | margin-bottom: 60px;
64 | }
65 | .footer {
66 | position: absolute;
67 | bottom: 0;
68 | width: 100%;
69 | white-space: nowrap;
70 | line-height: 60px; /* Vertically center the text there */
71 | }
72 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/wwwroot/css/site.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | /* Provide sufficient contrast against white background */
11 | a {
12 | color: #0366d6;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22 | color: #fff;
23 | background-color: #1b6ec2;
24 | border-color: #1861ac;
25 | }
26 |
27 | /* Sticky footer styles
28 | -------------------------------------------------- */
29 | html {
30 | font-size: 14px;
31 | }
32 | @media (min-width: 768px) {
33 | html {
34 | font-size: 16px;
35 | }
36 | }
37 |
38 | .border-top {
39 | border-top: 1px solid #e5e5e5;
40 | }
41 | .border-bottom {
42 | border-bottom: 1px solid #e5e5e5;
43 | }
44 |
45 | .box-shadow {
46 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
47 | }
48 |
49 | button.accept-policy {
50 | font-size: 1rem;
51 | line-height: inherit;
52 | }
53 |
54 | /* Sticky footer styles
55 | -------------------------------------------------- */
56 | html {
57 | position: relative;
58 | min-height: 100%;
59 | }
60 |
61 | body {
62 | /* Margin bottom by footer height */
63 | margin-bottom: 60px;
64 | }
65 | .footer {
66 | position: absolute;
67 | bottom: 0;
68 | width: 100%;
69 | white-space: nowrap;
70 | line-height: 60px; /* Vertically center the text there */
71 | }
72 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Program.cs:
--------------------------------------------------------------------------------
1 | using MyShop.Domain.Models;
2 | using MyShop.Infrastructure;
3 |
4 | var builder = WebApplication.CreateBuilder(args);
5 |
6 | // Add services to the container.
7 | builder.Services.AddControllersWithViews();
8 |
9 | var app = builder.Build();
10 |
11 | CreateInitialDatabase();
12 |
13 | // Configure the HTTP request pipeline.
14 | if (!app.Environment.IsDevelopment())
15 | {
16 | app.UseExceptionHandler("/Order/Error");
17 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
18 | app.UseHsts();
19 | }
20 |
21 | app.UseHttpsRedirection();
22 | app.UseStaticFiles();
23 |
24 | app.UseRouting();
25 |
26 | app.UseAuthorization();
27 |
28 | app.MapControllerRoute(
29 | name: "default",
30 | pattern: "{controller=Order}/{action=Index}/{id?}");
31 |
32 | app.Run();
33 |
34 |
35 | void CreateInitialDatabase()
36 | {
37 | using (var context = new ShoppingContext())
38 | {
39 | context.Database.EnsureDeleted();
40 | context.Database.EnsureCreated();
41 |
42 | var camera = new Product { Name = "Canon EOS 70D", Price = 599m };
43 | var microphone = new Product { Name = "Shure SM7B", Price = 245m };
44 | var light = new Product { Name = "Key Light", Price = 59.99m };
45 | var phone = new Product { Name = "Android Phone", Price = 259.59m };
46 | var speakers = new Product { Name = "5.1 Speaker System", Price = 799.99m };
47 |
48 | context.Products.Add(camera);
49 | context.Products.Add(microphone);
50 | context.Products.Add(light);
51 | context.Products.Add(phone);
52 | context.Products.Add(speakers);
53 |
54 | context.SaveChanges();
55 | }
56 | }
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/wwwroot/lib/jquery/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/jquery/jquery
6 |
7 | The following license applies to all parts of this software except as
8 | documented below:
9 |
10 | ====
11 |
12 | Permission is hereby granted, free of charge, to any person obtaining
13 | a copy of this software and associated documentation files (the
14 | "Software"), to deal in the Software without restriction, including
15 | without limitation the rights to use, copy, modify, merge, publish,
16 | distribute, sublicense, and/or sell copies of the Software, and to
17 | permit persons to whom the Software is furnished to do so, subject to
18 | the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be
21 | included in all copies or substantial portions of the Software.
22 |
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 |
31 | ====
32 |
33 | All files located in the node_modules and external directories are
34 | externally maintained libraries used by this software which have their
35 | own licenses; we recommend you read them, as their terms may differ from
36 | the terms above.
37 |
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web.Tests/OrderControllerTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Moq;
3 | using MyShop.Domain.Models;
4 | using MyShop.Infrastructure.Repositories;
5 | using MyShop.Web.Controllers;
6 | using MyShop.Web.Models;
7 | using System;
8 |
9 | namespace MyShop.Web.Tests
10 | {
11 | [TestClass]
12 | public class OrderControllerTests
13 | {
14 | [TestMethod]
15 | public void CanCreateOrderWithCorrectModel()
16 | {
17 | // ARRANGE
18 | var orderRepository = new Mock>();
19 | var productRepository = new Mock>();
20 | var customerRepository = new Mock>();
21 |
22 | var orderController = new OrderController(
23 | orderRepository.Object,
24 | productRepository.Object
25 | );
26 |
27 | var createOrderModel = new CreateOrderModel
28 | {
29 | Customer = new CustomerModel
30 | {
31 | Name = "Filip Ekberg",
32 | ShippingAddress = "Test address",
33 | City = "Gothenburg",
34 | PostalCode = "43317",
35 | Country = "Sweden"
36 | },
37 | LineItems = new []
38 | {
39 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 10 },
40 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 2 },
41 | }
42 | };
43 |
44 | // ACT
45 |
46 | orderController.Create(createOrderModel);
47 |
48 | // ASSERT
49 |
50 | orderRepository.Verify(r => r.Add(It.IsAny()), Times.AtLeastOnce());
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web.Tests/OrderControllerTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Moq;
3 | using MyShop.Domain.Models;
4 | using MyShop.Infrastructure.Repositories;
5 | using MyShop.Web.Controllers;
6 | using MyShop.Web.Models;
7 | using System;
8 |
9 | namespace MyShop.Web.Tests
10 | {
11 | [TestClass]
12 | public class OrderControllerTests
13 | {
14 | [TestMethod]
15 | public void CanCreateOrderWithCorrectModel()
16 | {
17 | // ARRANGE
18 | var orderRepository = new Mock>();
19 | var productRepository = new Mock>();
20 | var customerRepository = new Mock>();
21 |
22 | var orderController = new OrderController(
23 | orderRepository.Object,
24 | productRepository.Object
25 | );
26 |
27 | var createOrderModel = new CreateOrderModel
28 | {
29 | Customer = new CustomerModel
30 | {
31 | Name = "Filip Ekberg",
32 | ShippingAddress = "Test address",
33 | City = "Gothenburg",
34 | PostalCode = "43317",
35 | Country = "Sweden"
36 | },
37 | LineItems = new []
38 | {
39 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 10 },
40 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 2 },
41 | }
42 | };
43 |
44 | // ACT
45 |
46 | orderController.Create(createOrderModel);
47 |
48 | // ASSERT
49 |
50 | orderRepository.Verify(r => r.Add(It.IsAny()),
51 | Times.AtLeastOnce());
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/Views/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
33 |
41 | }
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Views/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
33 |
41 | }
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web/Views/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
33 |
41 | }
--------------------------------------------------------------------------------
/src/03/Start_Here/MyShop.Web/Views/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
33 |
41 | }
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web/Views/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
33 |
41 | }
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web/Views/Shared/_CookieConsentPartial.cshtml:
--------------------------------------------------------------------------------
1 | @using Microsoft.AspNetCore.Http.Features
2 |
3 | @{
4 | var consentFeature = Context.Features.Get();
5 | var showBanner = !consentFeature?.CanTrack ?? false;
6 | var cookieString = consentFeature?.CreateConsentCookie();
7 | }
8 |
9 | @if (showBanner)
10 | {
11 |
33 |
41 | }
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Infrastructure/UnitOfWork.cs:
--------------------------------------------------------------------------------
1 | using MyShop.Domain.Models;
2 | using MyShop.Infrastructure.Repositories;
3 |
4 | namespace MyShop.Infrastructure
5 | {
6 | public interface IUnitOfWork
7 | {
8 | IRepository CustomerRepository { get; }
9 | IRepository OrderRepository { get; }
10 | IRepository ProductRepository { get; }
11 |
12 | void SaveChanges();
13 | }
14 |
15 | public class UnitOfWork : IUnitOfWork
16 | {
17 | private ShoppingContext context;
18 |
19 | public UnitOfWork(ShoppingContext context)
20 | {
21 | this.context = context;
22 | }
23 |
24 | private IRepository customerRepository;
25 | public IRepository CustomerRepository
26 | {
27 | get
28 | {
29 | if (customerRepository == null)
30 | {
31 | customerRepository = new CustomerRepository(context);
32 | }
33 |
34 | return customerRepository;
35 | }
36 | }
37 |
38 | private IRepository orderRepository;
39 | public IRepository OrderRepository
40 | {
41 | get
42 | {
43 | if(orderRepository == null)
44 | {
45 | orderRepository = new OrderRepository(context);
46 | }
47 |
48 | return orderRepository;
49 | }
50 | }
51 |
52 | private IRepository productRepository;
53 | public IRepository ProductRepository
54 | {
55 | get
56 | {
57 | if (productRepository == null)
58 | {
59 | productRepository = new ProductRepository(context);
60 | }
61 |
62 | return productRepository;
63 | }
64 | }
65 |
66 | public void SaveChanges()
67 | {
68 | context.SaveChanges();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Infrastructure/UnitOfWork.cs:
--------------------------------------------------------------------------------
1 | using MyShop.Domain.Models;
2 | using MyShop.Infrastructure.Repositories;
3 |
4 | namespace MyShop.Infrastructure
5 | {
6 | public interface IUnitOfWork
7 | {
8 | IRepository CustomerRepository { get; }
9 | IRepository OrderRepository { get; }
10 | IRepository ProductRepository { get; }
11 |
12 | void SaveChanges();
13 | }
14 |
15 | public class UnitOfWork : IUnitOfWork
16 | {
17 | private ShoppingContext context;
18 |
19 | public UnitOfWork(ShoppingContext context)
20 | {
21 | this.context = context;
22 | }
23 |
24 | private IRepository customerRepository;
25 | public IRepository CustomerRepository
26 | {
27 | get
28 | {
29 | if (customerRepository == null)
30 | {
31 | customerRepository = new CustomerRepository(context);
32 | }
33 |
34 | return customerRepository;
35 | }
36 | }
37 |
38 | private IRepository orderRepository;
39 | public IRepository OrderRepository
40 | {
41 | get
42 | {
43 | if(orderRepository == null)
44 | {
45 | orderRepository = new OrderRepository(context);
46 | }
47 |
48 | return orderRepository;
49 | }
50 | }
51 |
52 | private IRepository productRepository;
53 | public IRepository ProductRepository
54 | {
55 | get
56 | {
57 | if (productRepository == null)
58 | {
59 | productRepository = new ProductRepository(context);
60 | }
61 |
62 | return productRepository;
63 | }
64 | }
65 |
66 | public void SaveChanges()
67 | {
68 | context.SaveChanges();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Infrastructure/UnitOfWork.cs:
--------------------------------------------------------------------------------
1 | using MyShop.Domain.Models;
2 | using MyShop.Infrastructure.Repositories;
3 |
4 | namespace MyShop.Infrastructure
5 | {
6 | public interface IUnitOfWork
7 | {
8 | IRepository CustomerRepository { get; }
9 | IRepository OrderRepository { get; }
10 | IRepository ProductRepository { get; }
11 |
12 | void SaveChanges();
13 | }
14 |
15 | public class UnitOfWork : IUnitOfWork
16 | {
17 | private ShoppingContext context;
18 |
19 | public UnitOfWork(ShoppingContext context)
20 | {
21 | this.context = context;
22 | }
23 |
24 | private IRepository customerRepository;
25 | public IRepository CustomerRepository
26 | {
27 | get
28 | {
29 | if (customerRepository == null)
30 | {
31 | customerRepository = new CustomerRepository(context);
32 | }
33 |
34 | return customerRepository;
35 | }
36 | }
37 |
38 | private IRepository orderRepository;
39 | public IRepository OrderRepository
40 | {
41 | get
42 | {
43 | if(orderRepository == null)
44 | {
45 | orderRepository = new OrderRepository(context);
46 | }
47 |
48 | return orderRepository;
49 | }
50 | }
51 |
52 | private IRepository productRepository;
53 | public IRepository ProductRepository
54 | {
55 | get
56 | {
57 | if (productRepository == null)
58 | {
59 | productRepository = new ProductRepository(context);
60 | }
61 |
62 | return productRepository;
63 | }
64 | }
65 |
66 | public void SaveChanges()
67 | {
68 | context.SaveChanges();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/03/Completed/MyShop.Web.Tests/OrderControllerTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using Moq;
4 | using MyShop.Domain.Models;
5 | using MyShop.Infrastructure;
6 | using MyShop.Infrastructure.Repositories;
7 | using MyShop.Web.Controllers;
8 | using MyShop.Web.Models;
9 | using System;
10 |
11 | namespace MyShop.Web.Tests
12 | {
13 | [TestClass]
14 | public class OrderControllerTests
15 | {
16 | [TestMethod]
17 | public void CanCreateOrderWithCorrectModel()
18 | {
19 | // ARRANGE
20 | var orderRepository = new Mock>();
21 | var productRepository = new Mock>();
22 | var customerRepository = new Mock>();
23 | var unitOfWork = new Mock();
24 |
25 | unitOfWork.Setup(uow => uow.CustomerRepository).Returns(() => customerRepository.Object);
26 | unitOfWork.Setup(uow => uow.OrderRepository).Returns(() => orderRepository.Object);
27 | unitOfWork.Setup(uow => uow.ProductRepository).Returns(() => productRepository.Object);
28 |
29 | var orderController = new OrderController(unitOfWork.Object);
30 |
31 | var createOrderModel = new CreateOrderModel
32 | {
33 | Customer = new CustomerModel
34 | {
35 | Name = "Filip Ekberg",
36 | ShippingAddress = "Test address",
37 | City = "Gothenburg",
38 | PostalCode = "43317",
39 | Country = "Sweden"
40 | },
41 | LineItems = new []
42 | {
43 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 10 },
44 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 2 },
45 | }
46 | };
47 |
48 | // ACT
49 |
50 | orderController.Create(createOrderModel);
51 |
52 | // ASSERT
53 |
54 | orderRepository.Verify(r => r.Add(It.IsAny()), Times.AtLeastOnce());
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Web.Tests/OrderControllerTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using Moq;
4 | using MyShop.Domain.Models;
5 | using MyShop.Infrastructure;
6 | using MyShop.Infrastructure.Repositories;
7 | using MyShop.Web.Controllers;
8 | using MyShop.Web.Models;
9 | using System;
10 |
11 | namespace MyShop.Web.Tests
12 | {
13 | [TestClass]
14 | public class OrderControllerTests
15 | {
16 | [TestMethod]
17 | public void CanCreateOrderWithCorrectModel()
18 | {
19 | // ARRANGE
20 | var orderRepository = new Mock>();
21 | var productRepository = new Mock>();
22 | var customerRepository = new Mock>();
23 | var unitOfWork = new Mock();
24 |
25 | unitOfWork.Setup(uow => uow.CustomerRepository).Returns(() => customerRepository.Object);
26 | unitOfWork.Setup(uow => uow.OrderRepository).Returns(() => orderRepository.Object);
27 | unitOfWork.Setup(uow => uow.ProductRepository).Returns(() => productRepository.Object);
28 |
29 | var orderController = new OrderController(unitOfWork.Object);
30 |
31 | var createOrderModel = new CreateOrderModel
32 | {
33 | Customer = new CustomerModel
34 | {
35 | Name = "Filip Ekberg",
36 | ShippingAddress = "Test address",
37 | City = "Gothenburg",
38 | PostalCode = "43317",
39 | Country = "Sweden"
40 | },
41 | LineItems = new []
42 | {
43 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 10 },
44 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 2 },
45 | }
46 | };
47 |
48 | // ACT
49 |
50 | orderController.Create(createOrderModel);
51 |
52 | // ASSERT
53 |
54 | orderRepository.Verify(r => r.Add(It.IsAny()), Times.AtLeastOnce());
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/04/Start_Here/MyShop.Web.Tests/OrderControllerTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using Moq;
4 | using MyShop.Domain.Models;
5 | using MyShop.Infrastructure;
6 | using MyShop.Infrastructure.Repositories;
7 | using MyShop.Web.Controllers;
8 | using MyShop.Web.Models;
9 | using System;
10 |
11 | namespace MyShop.Web.Tests
12 | {
13 | [TestClass]
14 | public class OrderControllerTests
15 | {
16 | [TestMethod]
17 | public void CanCreateOrderWithCorrectModel()
18 | {
19 | // ARRANGE
20 | var orderRepository = new Mock>();
21 | var productRepository = new Mock>();
22 | var customerRepository = new Mock>();
23 | var unitOfWork = new Mock();
24 |
25 | unitOfWork.Setup(uow => uow.CustomerRepository).Returns(() => customerRepository.Object);
26 | unitOfWork.Setup(uow => uow.OrderRepository).Returns(() => orderRepository.Object);
27 | unitOfWork.Setup(uow => uow.ProductRepository).Returns(() => productRepository.Object);
28 |
29 | var orderController = new OrderController(unitOfWork.Object);
30 |
31 | var createOrderModel = new CreateOrderModel
32 | {
33 | Customer = new CustomerModel
34 | {
35 | Name = "Filip Ekberg",
36 | ShippingAddress = "Test address",
37 | City = "Gothenburg",
38 | PostalCode = "43317",
39 | Country = "Sweden"
40 | },
41 | LineItems = new []
42 | {
43 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 10 },
44 | new LineItemModel { ProductId = Guid.NewGuid(), Quantity = 2 },
45 | }
46 | };
47 |
48 | // ACT
49 |
50 | orderController.Create(createOrderModel);
51 |
52 | // ASSERT
53 |
54 | orderRepository.Verify(r => r.Add(It.IsAny()), Times.AtLeastOnce());
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30011.22
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyShop.Web", "MyShop.Web\MyShop.Web.csproj", "{304B9F8A-296B-4CBB-A684-3EBDC3A6D482}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyShop.Domain", "MyShop.Domain\MyShop.Domain.csproj", "{D1EFB329-5B5F-4F84-A6EA-468F68B73C9D}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyShop.Infrastructure", "MyShop.Infrastructure\MyShop.Infrastructure.csproj", "{2863D7D0-089D-4CEA-927B-D97272E8F9B7}"
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 | {304B9F8A-296B-4CBB-A684-3EBDC3A6D482}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {304B9F8A-296B-4CBB-A684-3EBDC3A6D482}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {304B9F8A-296B-4CBB-A684-3EBDC3A6D482}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {304B9F8A-296B-4CBB-A684-3EBDC3A6D482}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {D1EFB329-5B5F-4F84-A6EA-468F68B73C9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {D1EFB329-5B5F-4F84-A6EA-468F68B73C9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {D1EFB329-5B5F-4F84-A6EA-468F68B73C9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {D1EFB329-5B5F-4F84-A6EA-468F68B73C9D}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {2863D7D0-089D-4CEA-927B-D97272E8F9B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {2863D7D0-089D-4CEA-927B-D97272E8F9B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {2863D7D0-089D-4CEA-927B-D97272E8F9B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {2863D7D0-089D-4CEA-927B-D97272E8F9B7}.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 = {2A0CD69B-6A42-48D3-BABD-F056A991E6F2}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Startup.cs:
--------------------------------------------------------------------------------
1 | //using Microsoft.AspNetCore.Builder;
2 | //using Microsoft.AspNetCore.Hosting;
3 | //using Microsoft.AspNetCore.Http;
4 | //using Microsoft.AspNetCore.Mvc;
5 | //using Microsoft.Extensions.Configuration;
6 | //using Microsoft.Extensions.DependencyInjection;
7 | //using MyShop.Domain.Models;
8 | //using MyShop.Infrastructure;
9 |
10 | //namespace MyShop.Web
11 | //{
12 | // public class Startup
13 | // {
14 | // public Startup(IConfiguration configuration)
15 | // {
16 | // Configuration = configuration;
17 | // }
18 |
19 | // public IConfiguration Configuration { get; }
20 |
21 | // public void ConfigureServices(IServiceCollection services)
22 | // {
23 | // services.Configure(options =>
24 | // {
25 | // // This lambda determines whether user consent for non-essential cookies is needed for a given request.
26 | // options.CheckConsentNeeded = context => true;
27 | // options.MinimumSameSitePolicy = SameSiteMode.None;
28 | // });
29 |
30 | // services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
31 |
32 |
33 | // services.AddTransient();
34 |
35 | // }
36 |
37 | // // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
38 | // public void Configure(IApplicationBuilder app, IHostingEnvironment env)
39 | // {
40 | // if (env.IsDevelopment())
41 | // {
42 | // app.UseDeveloperExceptionPage();
43 | // }
44 | // else
45 | // {
46 | // app.UseExceptionHandler("/Order/Error");
47 | // app.UseHsts();
48 | // }
49 |
50 | // app.UseHttpsRedirection();
51 | // app.UseStaticFiles();
52 | // app.UseCookiePolicy();
53 |
54 | // app.UseMvc(routes =>
55 | // {
56 | // routes.MapRoute(
57 | // name: "default",
58 | // template: "{controller=Order}/{action=Index}/{id?}");
59 | // });
60 | // }
61 | // }
62 | //}
63 |
--------------------------------------------------------------------------------
/src/04/Completed/MyShop.Infrastructure/Repositories/CustomerRepository.cs:
--------------------------------------------------------------------------------
1 | using MyShop.Domain.Lazy;
2 | using MyShop.Domain.Models;
3 | using MyShop.Infrastructure.Lazy.Ghosts;
4 | using MyShop.Infrastructure.Lazy.Proxies;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 |
9 | namespace MyShop.Infrastructure.Repositories
10 | {
11 | public class CustomerRepository : GenericRepository
12 | {
13 | public CustomerRepository(ShoppingContext context) : base(context)
14 | {
15 | }
16 |
17 | public override Customer Get(Guid id)
18 | {
19 | var customerId = context.Customers
20 | .Where(c => c.CustomerId == id)
21 | .Select(c => c.CustomerId)
22 | .Single();
23 |
24 | return new GhostCustomer(() => base.Get(id))
25 | {
26 | CustomerId = customerId
27 | };
28 | }
29 |
30 | public override IEnumerable All()
31 | {
32 | // Lazy Loading: Value Holder
33 | //ProfilePictureValueHolder = new ValueHolder();
34 | //ProfilePictureValueHolder = new Lazy(() =>
35 | //{
36 | // return ProfilePictureService.GetFor(customer.Name);
37 | //});
38 |
39 | return base.All().Select(MapToProxy);
40 | }
41 |
42 | public override Customer Update(Customer entity)
43 | {
44 | var customer = context.Customers
45 | .Single(c => c.CustomerId == entity.CustomerId);
46 |
47 | customer.Name = entity.Name;
48 | customer.City = entity.City;
49 | customer.PostalCode = entity.PostalCode;
50 | customer.ShippingAddress = entity.ShippingAddress;
51 | customer.Country = entity.Country;
52 |
53 | return base.Update(customer);
54 | }
55 |
56 | private CustomerProxy MapToProxy(Customer customer)
57 | {
58 | return new CustomerProxy
59 | {
60 | CustomerId = customer.CustomerId,
61 | Name = customer.Name,
62 | ShippingAddress = customer.ShippingAddress,
63 | City = customer.City,
64 | PostalCode = customer.PostalCode,
65 | Country = customer.Country
66 | };
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/02/Start_Here/MyShop.Web/Controllers/OrderController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Linq;
4 | using Microsoft.AspNetCore.Mvc;
5 | using Microsoft.EntityFrameworkCore;
6 | using MyShop.Domain.Models;
7 | using MyShop.Infrastructure;
8 | using MyShop.Web.Models;
9 |
10 | namespace MyShop.Web.Controllers
11 | {
12 | public class OrderController : Controller
13 | {
14 | private ShoppingContext context;
15 |
16 | public OrderController()
17 | {
18 | context = new ShoppingContext();
19 | }
20 |
21 | public IActionResult Index()
22 | {
23 | var orders = context.Orders
24 | .Include(order => order.LineItems)
25 | .ThenInclude(lineItem => lineItem.Product)
26 | .Where(order => order.OrderDate > DateTime.UtcNow.AddDays(-1)).ToList();
27 |
28 | return View(orders);
29 | }
30 |
31 | public IActionResult Create()
32 | {
33 | var products = context.Products.ToList();
34 |
35 | return View(products);
36 | }
37 |
38 | [HttpPost]
39 | public IActionResult Create(CreateOrderModel model)
40 | {
41 | if (!model.LineItems.Any()) return BadRequest("Please submit line items");
42 |
43 | if (string.IsNullOrWhiteSpace(model.Customer.Name)) return BadRequest("Customer needs a name");
44 |
45 | var customer = new Customer
46 | {
47 | Name = model.Customer.Name,
48 | ShippingAddress = model.Customer.ShippingAddress,
49 | City = model.Customer.City,
50 | PostalCode = model.Customer.PostalCode,
51 | Country = model.Customer.Country
52 | };
53 |
54 | var order = new Order
55 | {
56 | LineItems = model.LineItems
57 | .Select(line => new LineItem { ProductId = line.ProductId, Quantity = line.Quantity })
58 | .ToList(),
59 |
60 | Customer = customer
61 | };
62 |
63 | context.Orders.Add(order);
64 |
65 | context.SaveChanges();
66 |
67 | return Ok("Order Created");
68 | }
69 |
70 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
71 | public IActionResult Error()
72 | {
73 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/02/Completed/MyShop.Web/Controllers/OrderController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Linq;
4 | using Microsoft.AspNetCore.Mvc;
5 | using MyShop.Domain.Models;
6 | using MyShop.Infrastructure.Repositories;
7 | using MyShop.Web.Models;
8 |
9 | namespace MyShop.Web.Controllers
10 | {
11 | public class OrderController : Controller
12 | {
13 | private readonly IRepository orderRepository;
14 | private readonly IRepository productRepository;
15 |
16 | public OrderController(IRepository orderRepository,
17 | IRepository productRepository)
18 | {
19 | this.orderRepository = orderRepository;
20 | this.productRepository = productRepository;
21 | }
22 |
23 | public IActionResult Index()
24 | {
25 | var orders = orderRepository.Find(order => order.OrderDate > DateTime.UtcNow.AddDays(-1));
26 |
27 | return View(orders);
28 | }
29 |
30 | public IActionResult Create()
31 | {
32 | var products = productRepository.All();
33 |
34 | return View(products);
35 | }
36 |
37 | [HttpPost]
38 | public IActionResult Create(CreateOrderModel model)
39 | {
40 | if (!model.LineItems.Any()) return BadRequest("Please submit line items");
41 |
42 | if (string.IsNullOrWhiteSpace(model.Customer.Name)) return BadRequest("Customer needs a name");
43 |
44 | var customer = new Customer
45 | {
46 | Name = model.Customer.Name,
47 | ShippingAddress = model.Customer.ShippingAddress,
48 | City = model.Customer.City,
49 | PostalCode = model.Customer.PostalCode,
50 | Country = model.Customer.Country
51 | };
52 |
53 | var order = new Order
54 | {
55 | LineItems = model.LineItems
56 | .Select(line => new LineItem { ProductId = line.ProductId, Quantity = line.Quantity })
57 | .ToList(),
58 |
59 | Customer = customer
60 | };
61 |
62 | orderRepository.Add(order);
63 |
64 | orderRepository.SaveChanges();
65 |
66 | return Ok("Order Created");
67 | }
68 |
69 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
70 | public IActionResult Error()
71 | {
72 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------