Created
June 24, 2015 18:12
-
-
Save fpopic/9396ae53b4dbd536f6bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Model; | |
| using System.ComponentModel; | |
| namespace BLL | |
| { | |
| public class BillBLL | |
| { | |
| private BillDAL dal = new BillDAL(); | |
| public BindingList<Bill> FetchAll() | |
| { | |
| BindingList<Bill> list = new BindingList<Bill>(); | |
| var dalCollection = dal.FetchAll(); | |
| foreach (var dalObject in dalCollection) | |
| { | |
| Bill bill = new Bill(); | |
| bill.LoadFromDB(dalObject); | |
| list.Add(bill); | |
| } | |
| return list; | |
| } | |
| public Bill Fetch(int id) | |
| { | |
| Bill bill = null; | |
| var dalObject = dal.Fetch(id); | |
| if (dalObject != null) | |
| { | |
| bill = new Bill(); | |
| bill.LoadFromDB(dalObject); | |
| } | |
| return bill; | |
| } | |
| public BindingList<Bill> FetchWithContractId(int id) | |
| { | |
| BindingList<Bill> bills = new BindingList<Bill>(); | |
| foreach (var dalObject in dal.FetchAll()) | |
| { | |
| var bill = new Bill(); | |
| bill.LoadFromDB(dalObject); | |
| if (bill.ContractId == id) | |
| { | |
| bills.Add(bill); | |
| } | |
| } | |
| return bills; | |
| } | |
| public void Insert(Bill a) | |
| { | |
| if (string.IsNullOrEmpty(a.Error)) | |
| { | |
| dal.Insert(a.Id, a.ContractId, a.DateIssued, a.PaymentDeadline, a.Discount, a.Paid); | |
| } | |
| else | |
| { | |
| throw new Exception("Validacija neuspješna: " + a.Error); | |
| } | |
| } | |
| public void Delete(Bill a) | |
| { | |
| dal.Delete(a.Id); | |
| } | |
| public void Update(Bill a) | |
| { | |
| if (string.IsNullOrEmpty(a.Error)) | |
| { | |
| dal.Update(a.Id, a.ContractId, a.DateIssued, a.PaymentDeadline, a.Discount, a.Paid); | |
| } | |
| else | |
| { | |
| throw new Exception("Validacija neuspješna: " + a.Error); | |
| } | |
| } | |
| public void RefreshBill(object datasource, int position, object current) | |
| { | |
| BindingList<Bill> list = (BindingList<Bill>)datasource; | |
| Bill a = list[position]; | |
| list[position] = Fetch(a.Id); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace Model | |
| { | |
| public class BillDAL | |
| { | |
| public List<Bill> FetchAll() | |
| { | |
| using (RPPP14Entities ctx = new RPPP14Entities()) | |
| { | |
| return ctx.Bills.ToList(); | |
| } | |
| } | |
| public Bill Fetch(int billId) | |
| { | |
| using (RPPP14Entities ctx = new RPPP14Entities()) | |
| { | |
| return ctx.Bills.Where(a => a.Id == billId).SingleOrDefault(); | |
| } | |
| } | |
| public void Insert(int id, int contractId, DateTime dateIssued, DateTime? paymentDeadline, decimal? discount, bool paid) | |
| { | |
| using (RPPP14Entities ctx = new RPPP14Entities()) | |
| { | |
| Bill a = new Bill(); | |
| a.Id = id; | |
| a.ContractId = contractId; | |
| a.DateIssued = dateIssued; | |
| a.PaymentDeadline = paymentDeadline; | |
| a.Discount = discount; | |
| a.Paid = paid; | |
| ctx.Bills.Add(a); | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| public void Update(int id, int contractId, DateTime dateIssued, DateTime? paymentDeadline, decimal? discount, bool paid) | |
| { | |
| using (RPPP14Entities ctx = new RPPP14Entities()) | |
| { | |
| Bill a = ctx.Bills.Where(c => c.Id == id).Single(); | |
| a.ContractId = contractId; | |
| a.DateIssued = dateIssued; | |
| a.PaymentDeadline = paymentDeadline; | |
| a.Discount = discount; | |
| a.Paid = paid; | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| public void Delete(int id) | |
| { | |
| using (RPPP14Entities ctx = new RPPP14Entities()) | |
| { | |
| Bill a = ctx.Bills.Where(c => c.Id == id).Single(); | |
| ctx.Bills.Remove(a); | |
| ctx.SaveChanges(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment