public InvoiceModel UpdateLabor(int invoiceId, int laborId, int employeeId, int locationId) { var invoice = InvoiceRepository.GetInvoice(invoiceId); if (invoice == null) { throw new ArgumentException(string.Format("{0} is an invalid invoice number", invoiceId)); } var labor = invoice.LaborList.Where(l => l.Id == laborId).FirstOrDefault(); if (labor == null) { throw new ArgumentException("laborId"); } var employee = GetEmployeeLogFromCache(locationId).Where(e => e.Employee.Id == employeeId).Select(s => s.Employee).FirstOrDefault(); if (employee == null) { throw new ArgumentException("employeeId"); } if (labor.Employee.Id == defaultEmployeeId) { labor.Employee = employee; } else { var newLabor = new Data.Graph.Labor(); newLabor.LaborDate = DateTime.Now; newLabor.LaborType = new Data.Graph.LaborType(AvailableLaborTypes.Where(t => t.LaborTypeId == labor.LaborType.Id).First()); newLabor.EstimatedRate = labor.EstimatedRate; newLabor.Employee = employee; invoice.AddLabor(newLabor); } invoice.CalculateLaborRates(labor.LaborType.Id); InvoiceRepository.SaveInvoice(invoice); Logger.InfoFormat("Added employee id {0} to labor id {1} on invoice {2}", employeeId, laborId, invoiceId); return(Mapper.Map <Data.Graph.Invoice, Models.InvoiceModel>(invoice)); }
public InvoiceModel AddLabor(int invoiceId, int laborTypeId, decimal rate) { var invoice = InvoiceRepository.GetInvoice(invoiceId); if (invoice == null) { throw new ArgumentException(string.Format("{0} is an invalid invoice number", invoiceId)); } var labor = new Data.Graph.Labor(); labor.LaborDate = DateTime.Now; labor.LaborType = new Data.Graph.LaborType(AvailableLaborTypes.Where(t => t.LaborTypeId == laborTypeId).First()); labor.EstimatedRate = rate; labor.Employee = defaultEmployee; invoice.AddLabor(labor); invoice.CalculateLaborRates(labor.LaborType.Id); InvoiceRepository.SaveInvoice(invoice); Logger.InfoFormat("Added labor type id {0} to invoice {1} with a base rate of {2}", laborTypeId, invoiceId, rate); return(Mapper.Map <Data.Graph.Invoice, Models.InvoiceModel>(invoice)); }
public InvoiceModel AddLabor(int invoiceId, int laborTypeId, decimal rate) { var invoice = InvoiceRepository.GetInvoice(invoiceId); if (invoice == null) throw new ArgumentException(string.Format("{0} is an invalid invoice number", invoiceId)); var labor = new Data.Graph.Labor(); labor.LaborDate = DateTime.Now; labor.LaborType = new Data.Graph.LaborType(AvailableLaborTypes.Where(t => t.LaborTypeId == laborTypeId).First()); labor.EstimatedRate = rate; labor.Employee = defaultEmployee; invoice.AddLabor(labor); invoice.CalculateLaborRates(labor.LaborType.Id); InvoiceRepository.SaveInvoice(invoice); Logger.InfoFormat("Added labor type id {0} to invoice {1} with a base rate of {2}", laborTypeId, invoiceId, rate); return Mapper.Map<Data.Graph.Invoice, Models.InvoiceModel>(invoice); }
public InvoiceModel UpdateLabor(int invoiceId, int laborId, int employeeId, int locationId) { var invoice = InvoiceRepository.GetInvoice(invoiceId); if (invoice == null) throw new ArgumentException(string.Format("{0} is an invalid invoice number", invoiceId)); var labor = invoice.LaborList.Where(l => l.Id == laborId).FirstOrDefault(); if (labor == null) throw new ArgumentException("laborId"); var employee = GetEmployeeLogFromCache(locationId).Where(e => e.Employee.Id == employeeId).Select(s => s.Employee).FirstOrDefault(); if (employee == null) throw new ArgumentException("employeeId"); if (labor.Employee.Id == defaultEmployeeId) { labor.Employee = employee; } else { var newLabor = new Data.Graph.Labor(); newLabor.LaborDate = DateTime.Now; newLabor.LaborType = new Data.Graph.LaborType(AvailableLaborTypes.Where(t => t.LaborTypeId == labor.LaborType.Id).First()); newLabor.EstimatedRate = labor.EstimatedRate; newLabor.Employee = employee; invoice.AddLabor(newLabor); } invoice.CalculateLaborRates(labor.LaborType.Id); InvoiceRepository.SaveInvoice(invoice); Logger.InfoFormat("Added employee id {0} to labor id {1} on invoice {2}", employeeId, laborId, invoiceId); return Mapper.Map<Data.Graph.Invoice, Models.InvoiceModel>(invoice); }