Skip to content

Commit e3f58a5

Browse files
committed
order controllers
1 parent acd73f2 commit e3f58a5

File tree

55 files changed

+1576
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1576
-224
lines changed

.vs/BookShopInventoryApp/v14/.suo

-8.5 KB
Binary file not shown.
3.06 MB
Binary file not shown.
1 MB
Binary file not shown.

BookShopInventoryApp.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@
191191
<Compile Include="Controllers\BookController.cs" />
192192
<Compile Include="Controllers\CustomerController.cs" />
193193
<Compile Include="Controllers\HomeController.cs" />
194+
<Compile Include="Controllers\OrderController.cs" />
195+
<Compile Include="Controllers\OrdersController.cs" />
194196
<Compile Include="Controllers\PublisherController.cs" />
195197
<Compile Include="Filters\InitializeSimpleMembershipAttribute.cs" />
196198
<Compile Include="Global.asax.cs">
197199
<DependentUpon>Global.asax</DependentUpon>
198200
</Compile>
199201
<Compile Include="Models\AccountModels.cs" />
200202
<Compile Include="Models\BookModel.cs" />
203+
<Compile Include="Models\BookShopInventoryAppContext.cs" />
201204
<Compile Include="Models\CustomerModel.cs" />
202205
<Compile Include="Models\Operation.cs">
203206
<DependentUpon>Operation.dbml</DependentUpon>
@@ -344,6 +347,13 @@
344347
<Content Include="Views\Customer\Details.cshtml" />
345348
<Content Include="Views\Customer\Delete.cshtml" />
346349
<Content Include="Views\Customer\Edit.cshtml" />
350+
<Content Include="Views\Orders\Index.cshtml" />
351+
<Content Include="Views\Orders\Details.cshtml" />
352+
<Content Include="Views\Orders\Create.cshtml" />
353+
<Content Include="Views\Orders\Edit.cshtml" />
354+
<Content Include="Views\Orders\Delete.cshtml" />
355+
<Content Include="Views\Order\order-list.cshtml" />
356+
<Content Include="Views\Order\Create.cshtml" />
347357
</ItemGroup>
348358
<ItemGroup>
349359
<Folder Include="App_Data\" />

Controllers/BookController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class BookController : Controller
1414
public BookController()
1515
{
1616
context = new OperationDataContext();
17+
1718
}
1819

1920
private void PreparePublisher(BookModel model)

Controllers/OrderController.cs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using BookShopInventoryApp.Models;
7+
8+
namespace BookInventoryApp.Controllers
9+
{
10+
public class OrderController : Controller
11+
{
12+
private OperationDataContext context;
13+
14+
public OrderController()
15+
{
16+
context = new OperationDataContext();
17+
18+
}
19+
20+
private void PrepareOrderDetails(OrderModel model)
21+
{
22+
model.Books = context.BOOKs.AsQueryable<BOOK>().Select(x =>
23+
new SelectListItem()
24+
{
25+
Text = x.Title,
26+
Value = x.Id.ToString()
27+
});
28+
model.Customers = context.Customers.AsQueryable<Customer>().Select(x =>
29+
new SelectListItem()
30+
{
31+
Text = x.FirstName + x.LastName,
32+
Value = x.ReferenceId.ToString()
33+
});
34+
}
35+
36+
public ActionResult Index()
37+
{
38+
IList<OrderModel> OrderList = new List<OrderModel>();
39+
var query = from order in context.Orders
40+
join BOOK in context.BOOKs
41+
on order.BookId equals BOOK.Id
42+
select new OrderModel
43+
{
44+
OrderNo = order.OrderNo,
45+
Quantity = order.Quantity,
46+
OrderDate = order.OrderDate,
47+
BookName = order.BookName,
48+
CustomerName = order.CustomerName
49+
};
50+
OrderList = query.ToList();
51+
return View(OrderList);
52+
}
53+
54+
55+
56+
public ActionResult Create()
57+
{
58+
OrderModel model = new OrderModel();
59+
PrepareOrderDetails(model);
60+
return View(model);
61+
}
62+
63+
[HttpPost]
64+
public ActionResult Create(OrderModel model)
65+
{
66+
try
67+
{
68+
Order order = new Order()
69+
{
70+
Quantity = model.Quantity,
71+
OrderDate = model.OrderDate,
72+
BookId = model.BookId,
73+
CustomerReferenceId = model.CustomerReferenceId
74+
};
75+
context.Orders.InsertOnSubmit(order);
76+
context.SubmitChanges();
77+
return RedirectToAction("Index");
78+
}
79+
catch
80+
{
81+
return View(model);
82+
}
83+
}
84+
/*
85+
public ActionResult Details(int id)
86+
{
87+
BookModel model = context.BOOKs.Where(x => x.Id == id).Select(x =>
88+
new BookModel()
89+
{
90+
Id = x.Id,
91+
Title = x.Title,
92+
Author = x.Author,
93+
Price = x.Price,
94+
Year = x.Year,
95+
ISBN = x.ISBN,
96+
StockLevel = x.StockLevel,
97+
PublisherName = x.Publisher.Name
98+
}).SingleOrDefault();
99+
100+
return View(model);
101+
}
102+
public ActionResult Edit(int id)
103+
{
104+
BookModel model = context.BOOKs.Where(x => x.Id == id).Select(x =>
105+
new BookModel()
106+
{
107+
Id = x.Id,
108+
Title = x.Title,
109+
Author = x.Author,
110+
Price = x.Price,
111+
Year = x.Year,
112+
ISBN = x.ISBN,
113+
StockLevel = x.StockLevel,
114+
PublisherName = x.Publisher.Name,
115+
PublisherId = x.PublisherId
116+
}).SingleOrDefault();
117+
118+
PreparePublisher(model);
119+
return View(model);
120+
}
121+
122+
[HttpPost]
123+
public ActionResult Edit(BookModel model)
124+
{
125+
try
126+
{
127+
128+
BOOK book = context.BOOKs.Where(x => x.Id == model.Id).Single<BOOK>();
129+
book.Title = model.Title;
130+
book.Author = model.Author;
131+
book.Price = model.Price;
132+
book.Year = model.Year;
133+
book.ISBN = model.ISBN;
134+
book.StockLevel = model.StockLevel;
135+
book.PublisherId = model.PublisherId;
136+
context.SubmitChanges();
137+
return RedirectToAction("Index");
138+
}
139+
catch
140+
{
141+
return View(model);
142+
}
143+
}
144+
145+
public ActionResult Delete(int id)
146+
{
147+
148+
BookModel model = context.BOOKs.Where(x => x.Id == id).Select(x =>
149+
new BookModel()
150+
{
151+
Id = x.Id,
152+
Title = x.Title,
153+
Author = x.Author,
154+
Price = x.Price,
155+
Year = x.Year,
156+
ISBN = x.ISBN,
157+
StockLevel = x.StockLevel,
158+
PublisherName = x.Publisher.Name
159+
}).SingleOrDefault();
160+
return View(model);
161+
}
162+
[HttpPost]
163+
public ActionResult Delete(BookModel model)
164+
{
165+
try
166+
{
167+
BOOK book = context.BOOKs.Where(x => x.Id == model.Id).Single<BOOK>();
168+
context.BOOKs.DeleteOnSubmit(book);
169+
context.SubmitChanges();
170+
return RedirectToAction("Index");
171+
}
172+
catch
173+
{
174+
return View(model);
175+
}
176+
}*/
177+
}
178+
}

Controllers/OrdersController.cs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.Entity;
5+
using System.Linq;
6+
using System.Web;
7+
using System.Web.Mvc;
8+
using BookShopInventoryApp.Models;
9+
10+
namespace BookShopInventoryApp.Controllers
11+
{
12+
public class OrdersController : Controller
13+
{
14+
private BookShopInventoryAppContext db = new BookShopInventoryAppContext();
15+
16+
//
17+
// GET: /Order/
18+
19+
public ActionResult Index()
20+
{
21+
return View(db.OrderModels.ToList());
22+
}
23+
24+
//
25+
// GET: /Order/Details/5
26+
27+
public ActionResult Details(int id = 0)
28+
{
29+
OrderModel ordermodel = db.OrderModels.Find(id);
30+
if (ordermodel == null)
31+
{
32+
return HttpNotFound();
33+
}
34+
return View(ordermodel);
35+
}
36+
37+
//
38+
// GET: /Order/Create
39+
40+
public ActionResult Create()
41+
{
42+
return View();
43+
}
44+
45+
//
46+
// POST: /Order/Create
47+
48+
[HttpPost]
49+
[ValidateAntiForgeryToken]
50+
public ActionResult Create(OrderModel ordermodel)
51+
{
52+
if (ModelState.IsValid)
53+
{
54+
db.OrderModels.Add(ordermodel);
55+
db.SaveChanges();
56+
return RedirectToAction("Index");
57+
}
58+
59+
return View(ordermodel);
60+
}
61+
62+
//
63+
// GET: /Order/Edit/5
64+
65+
public ActionResult Edit(int id = 0)
66+
{
67+
OrderModel ordermodel = db.OrderModels.Find(id);
68+
if (ordermodel == null)
69+
{
70+
return HttpNotFound();
71+
}
72+
return View(ordermodel);
73+
}
74+
75+
//
76+
// POST: /Order/Edit/5
77+
78+
[HttpPost]
79+
[ValidateAntiForgeryToken]
80+
public ActionResult Edit(OrderModel ordermodel)
81+
{
82+
if (ModelState.IsValid)
83+
{
84+
db.Entry(ordermodel).State = EntityState.Modified;
85+
db.SaveChanges();
86+
return RedirectToAction("Index");
87+
}
88+
return View(ordermodel);
89+
}
90+
91+
//
92+
// GET: /Order/Delete/5
93+
94+
public ActionResult Delete(int id = 0)
95+
{
96+
OrderModel ordermodel = db.OrderModels.Find(id);
97+
if (ordermodel == null)
98+
{
99+
return HttpNotFound();
100+
}
101+
return View(ordermodel);
102+
}
103+
104+
//
105+
// POST: /Order/Delete/5
106+
107+
[HttpPost, ActionName("Delete")]
108+
[ValidateAntiForgeryToken]
109+
public ActionResult DeleteConfirmed(int id)
110+
{
111+
OrderModel ordermodel = db.OrderModels.Find(id);
112+
db.OrderModels.Remove(ordermodel);
113+
db.SaveChanges();
114+
return RedirectToAction("Index");
115+
}
116+
117+
protected override void Dispose(bool disposing)
118+
{
119+
db.Dispose();
120+
base.Dispose(disposing);
121+
}
122+
}
123+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Data.Entity;
2+
3+
namespace BookShopInventoryApp.Models
4+
{
5+
public class BookShopInventoryAppContext : DbContext
6+
{
7+
// You can add custom code to this file. Changes will not be overwritten.
8+
//
9+
// If you want Entity Framework to drop and regenerate your database
10+
// automatically whenever you change your model schema, add the following
11+
// code to the Application_Start method in your Global.asax file.
12+
// Note: this will destroy and re-create your database with every model change.
13+
//
14+
// System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<BookShopInventoryApp.Models.BookShopInventoryAppContext>());
15+
16+
public BookShopInventoryAppContext() : base("name=BookShopInventoryAppContext")
17+
{
18+
}
19+
20+
public DbSet<OrderModel> OrderModels { get; set; }
21+
}
22+
}

0 commit comments

Comments
 (0)