public void FindLendingReceiptByCaseNumber() { DateTime start = new DateTime(2017, 11, 30); DateTime s**t = new DateTime(2017, 12, 3); Device device = new Device("22", "Pelle"); List <Device> listdevice5 = new List <Device>(); listdevice5.Add(device); lr.CreateLoan(start, s**t, listdevice5); Lending loan = lr.GetLoan(); string casenumber = "Søren-1234"; string loanerinfo = "Søren"; LendingReceiptRepository.Instance.CreateLendingReceipt(loanerinfo, casenumber, loan, "Pelle"); string Casenumber = "Søren-1234"; LendingReceipt lendingreceipt = LendingReceiptRepository.Instance.FindReceiptByCasenumber(Casenumber); DateTime startdate = new DateTime(2017, 11, 30); Assert.AreEqual(startdate, lendingreceipt.Loan.StartDate); }
public DataRow mapDataRow(Model model, DataRow row) { LendingReceipt receipt = (LendingReceipt)model; row["id"] = receipt.id; row["created_date"] = receipt.createdDate; row["return_date"] = receipt.returnDate; row["customer_id"] = receipt.customer.id; row["is_active"] = receipt.isActive; return(row); }
public static void ShowLoanerReceipt() { LendingReceiptRepository.Instance.LoadData(); foreach (var LendingReceipt in LendingReceiptRepository.Instance.lendingReceiptList) { Console.WriteLine(LendingReceipt.ToString()); Console.WriteLine("Devices borrowed"); LendingReceipt.Loan.Devices.ForEach(Device => Console.WriteLine(Device.ToString())); Console.WriteLine(); } Console.ReadLine(); }
public SqlCommand createUpdateCommand(Model model, String tableName, SqlConnection connection) { LendingReceipt receipt = (LendingReceipt)model; String sql = $"UPDATE {tableName} SET created_date = @createdDate, return_date = @returnDate, customer_id = @customerId, is_active = @isActive WHERE id = @id"; SqlCommand updateCommand = new SqlCommand(string.Format(sql), connection); updateCommand.Parameters.AddWithValue("@id", receipt.id); updateCommand.Parameters.AddWithValue("@createdDate", receipt.createdDate); updateCommand.Parameters.AddWithValue("@returnDate", receipt.returnDate); updateCommand.Parameters.AddWithValue("@customerId", receipt.customer.id); updateCommand.Parameters.AddWithValue("@isActive", receipt.isActive); return(updateCommand); }
public ServiceResult <LendingReceipt> initialize(LendingReceipt receipt) { ServiceResult <LendingReceipt> result = new ServiceResult <LendingReceipt>(); foreach (LendingReceiptDetail detail in receipt.details) { detail.id.receipt = receipt; } receipt.createdDate = DateTime.Now; receipt.isActive = true; result.model = receipt; return(result); }
public SqlCommand createInsertCommand(Model model, String tableName, SqlConnection connection) { LendingReceipt receipt = (LendingReceipt)model; String sql = $"INSERT INTO {tableName} ([id], [created_date], [return_date], [customer_id], [is_active]) " + "VALUES (@id, @createdDate, @returnDate, @customerId, @isActive);"; SqlCommand insertCommand = new SqlCommand(string.Format(sql), connection); insertCommand.Parameters.AddWithValue("@id", receipt.id); insertCommand.Parameters.AddWithValue("@createdDate", receipt.createdDate); insertCommand.Parameters.AddWithValue("@returnDate", receipt.returnDate); insertCommand.Parameters.AddWithValue("@customerId", receipt.customer.id); insertCommand.Parameters.AddWithValue("@isActive", receipt.isActive); return(insertCommand); }
public void ReturnAvailableDevicesfortimeperiod() { LendingReceipt lendingReceipt = new LendingReceipt(); Device devicePelle = new Device("1", "Pelles-PC"); List <Device> PelleDevicelist = new List <Device>(); DeviceRepository.StaticInstance.DeviceList.Add(devicePelle); PelleDevicelist.Add(devicePelle); DateTime start = new DateTime(2017, 11, 30); DateTime s**t = new DateTime(2017, 12, 3); lendingReceipt.CreateLoan(start, s**t, PelleDevicelist); Lending loanSøren = lendingReceipt.GetLoan(); LendingReceiptRepository.Instance.CreateLendingReceipt("Søren Hansen Sø[email protected]", "Søren-1234", loanSøren, "Pelle"); Assert.IsFalse(LendingReceiptRepository.Instance.ReturnAvailableDevicesForGivenPeriod(start, s**t).Contains(devicePelle)); }
public Model mapModel(DataRow row) { LendingReceipt receipt = new LendingReceipt(); if (row == null) { return(receipt); } BaseDAO dao = Program.dao; receipt.id = row.Field <int>("id"); receipt.createdDate = row.Field <DateTime>("created_date"); receipt.returnDate = row.Field <DateTime>("return_date"); receipt.customer = dao.getList <Customer>(typeof(Customer)) .Where(customer => customer.id == row.Field <int>("customer_id")) .FirstOrDefault(); receipt.isActive = row.Field <bool>("is_active"); return(receipt); }
public ServiceResult <LendingReceipt> validate(LendingReceipt receipt) { ServiceResult <LendingReceipt> result = new ServiceResult <LendingReceipt>(); if (receipt.createdDate == null) { result.status = ServiceStatus.INVALID; result.messages.Add("createdDate", "Created date must not be empty."); } if (receipt.returnDate == null) { result.status = ServiceStatus.INVALID; result.messages.Add("returnedDate", "Returned date must not be empty."); } CustomerService customerService = new CustomerService(); ServiceResult <Customer> customerValidationResult = customerService.validate(receipt.customer); if (!customerValidationResult.isOk()) { result.status = ServiceStatus.INVALID; foreach (String key in customerValidationResult.messages.Keys) { result.messages.Add($"customer_{key}", customerValidationResult.messages[key]); } } if (receipt.details.Count == 0) { result.status = ServiceStatus.INVALID; result.messages.Add("details", "Lending details cannot be empty."); } result.model = receipt; return(result); }