-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBillController.cs
55 lines (51 loc) · 1.89 KB
/
BillController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using HomeManagementApplicationMain.Models;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using System.Data;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace HomeManagementApplicationMain.Controllers
{
[Route("HomeManagementApplicationMain/[controller]")]
public class BillController : Controller
{
private HMDBContext context;
public IConfiguration Configuration { get; set; }
public BillController(HMDBContext dbContext)
{
context = dbContext;
}
public IActionResult Bill()
{
BillMaster billDetails = new BillMaster();
var billDdl = context.BillMaster.Select(y => new { y.BillId, y.BillName });
List<SelectListItem> BillList = new List<SelectListItem>();
foreach (var item in billDdl)
{
BillList.Add(new SelectListItem { Text = item.BillName, Value = item.BillId.ToString() });
}
billDetails.BillList = BillList;
return View(billDetails);
}
[HttpPost]
public IActionResult Bill(BillDetails billDetails)
{
if (ModelState.IsValid)
{
BillDetails details = new BillDetails();
details.Amount = billDetails.Amount;
details.Date = billDetails.Date;
details.Store = billDetails.Store;
context.Add<BillDetails>(billDetails);
context.SaveChanges();
}
return View();
}
}
}