public InvoiceLaborDTO InvoiceLaborDTOMapper(InvoiceLabor invoiceLabor) { InvoiceLaborDTO invoiceLaborDTO = new InvoiceLaborDTO(); invoiceLaborDTO.LaborType = new TypeCodeDTO(); invoiceLaborDTO.LaborType.TypeCode = invoiceLabor.LaborType; invoiceLaborDTO.ID = invoiceLabor.ID; invoiceLabor.InvoiceID = invoiceLabor.InvoiceID; invoiceLaborDTO.Amount = Math.Round(invoiceLabor.Amount.GetValueOrDefault(), 2); invoiceLaborDTO.Hours = invoiceLabor.Hours; invoiceLaborDTO.Rate = invoiceLabor.Rate; invoiceLaborDTO.RecordStatus = "Active"; return(invoiceLaborDTO); }
public long Delete(InvoiceLabor labor) { _bheDBContext.InvoiceLabors.Attach(labor); return(_bheDBContext.InvoiceLabors.Remove(labor).ID); }
public long Add(InvoiceLabor labor) { return(_bheDBContext.InvoiceLabors.Add(labor).ID); }
public long Update(InvoiceDTO invoiceDTO) { long updatedID = -1; //Update Invoice var existingInvoice = _bheUOW.InvoiceRepository.Query().SingleOrDefault(x => x.ID == invoiceDTO.ID); if (existingInvoice != null) { existingInvoice.BalanceDue = Math.Round(invoiceDTO.BalanceDue.GetValueOrDefault(), 2); existingInvoice.Comments = invoiceDTO.Comments; existingInvoice.CustomerID = invoiceDTO.Customer.ID; existingInvoice.CustomerID = invoiceDTO.CustomerID; existingInvoice.CustomerPO = invoiceDTO.CustomerPO; existingInvoice.Freight = Math.Round(invoiceDTO.Freight.GetValueOrDefault(), 2); existingInvoice.InvoiceDate = invoiceDTO.InvoiceDate == DateTime.MinValue ? DateTime.Now : invoiceDTO.InvoiceDate; existingInvoice.InvoiceNumber = invoiceDTO.InvoiceNumber; existingInvoice.InvoiceStatus = invoiceDTO.InvoiceStatus.TypeCode; existingInvoice.InvoiceStatusID = invoiceDTO.InvoiceStatus.TypeCodeID; existingInvoice.InvoiceType = invoiceDTO.InvoiceType; existingInvoice.LaborSubTotal = Math.Round(invoiceDTO.LaborSubTotal, 2); existingInvoice.PartsSubTotal = Math.Round(invoiceDTO.PartsSubTotal, 2); existingInvoice.Tax = Math.Round(invoiceDTO.Tax, 2); existingInvoice.TravelCharge = Math.Round(invoiceDTO.TravelCharge.GetValueOrDefault(), 2); existingInvoice.TravelExpense = Math.Round(invoiceDTO.TravelExpense.GetValueOrDefault(), 2); existingInvoice.LastUpdatedBy = "Admin"; existingInvoice.LastUpdatedDate = DateTime.Now; if (existingInvoice.InvoiceType == "SERVICE-INVOICE") { existingInvoice.InvoiceService.Make = invoiceDTO.Make; existingInvoice.InvoiceService.Model = invoiceDTO.Model; existingInvoice.InvoiceService.SerialNumber = invoiceDTO.SerialNumber; existingInvoice.InvoiceService.UnitNumber = invoiceDTO.UnitNumber; existingInvoice.InvoiceService.ServicedAt = invoiceDTO.ServicedAt; existingInvoice.InvoiceService.ServiceStartDate = invoiceDTO.ServiceStartDate; existingInvoice.InvoiceService.ServiceEndDate = invoiceDTO.ServiceEndDate; } if (existingInvoice.InvoiceType == "PART-INVOICE") { existingInvoice.OrderNumber = invoiceDTO.OrderNumber; existingInvoice.PaymentStatus = invoiceDTO.PaymentStatus.TypeCode; existingInvoice.SaleRep = invoiceDTO.SalesRep; existingInvoice.ShippingMethod = invoiceDTO.ShippingMethod.TypeCode; } existingInvoice.IsStorePickUp = invoiceDTO.IsStorePickUp; updatedID = existingInvoice.ID; } //Insert/Update/Delete Parts Items if (invoiceDTO.InvoiceItems != null && invoiceDTO.InvoiceItems.Count > 0) { for (int i = 0; i < invoiceDTO.InvoiceItems.Count; i++) { //Delete Invoice Item if (invoiceDTO.InvoiceItems[i].RecordStatus.ToUpper() == "DELETED") { InvoiceItem invoiceItem = new InvoiceItem() { Description = invoiceDTO.InvoiceItems[i].Description, ID = invoiceDTO.InvoiceItems[i].ID, Price = invoiceDTO.InvoiceItems[i].Price, Quantity = invoiceDTO.InvoiceItems[i].Quantity, Total = invoiceDTO.InvoiceItems[i].Total }; var invoiceItemID = _bheUOW.InvoiceItemsRepository.Delete(invoiceItem); } //Insert Item if (invoiceDTO.InvoiceItems[i].ID == 0) { invoiceDTO.InvoiceItems[i].InvoiceID = invoiceDTO.ID; InvoiceItemMapper mapper = new InvoiceItemMapper(); _bheUOW.InvoiceItemsRepository.Add(mapper.InvoiceItemEntityMapper(invoiceDTO.InvoiceItems[i])); } } } //Insert/Update/Delete Labor Items if (invoiceDTO.InvoiceLabors != null && invoiceDTO.InvoiceLabors.Count > 0) { for (int i = 0; i < invoiceDTO.InvoiceLabors.Count; i++) { //Delete Invoice Item if (invoiceDTO.InvoiceLabors[i].RecordStatus.ToUpper() == "DELETED") { InvoiceLabor invoiceLabor = new InvoiceLabor() { ID = invoiceDTO.InvoiceLabors[i].ID, InvoiceID = invoiceDTO.InvoiceLabors[i].InvoiceID, Amount = invoiceDTO.InvoiceLabors[i].Amount, Hours = invoiceDTO.InvoiceLabors[i].Hours, LaborType = invoiceDTO.InvoiceLabors[i].LaborType.TypeCode, Rate = invoiceDTO.InvoiceLabors[i].Rate, }; var invoiceLaborID = _bheUOW.InvoiceLaborRepository.Delete(invoiceLabor); } //Insert Item if (invoiceDTO.InvoiceLabors[i].ID == 0) { invoiceDTO.InvoiceLabors[i].InvoiceID = invoiceDTO.ID; InvoiceLaborMapper mapper = new InvoiceLaborMapper(); _bheUOW.InvoiceLaborRepository.Add(mapper.InvoiceLaborEntityMapper(invoiceDTO.InvoiceLabors[i])); } } } _bheUOW.SaveChanges(); //Insert/Update/Delete Labor Items return(updatedID); }
private InvoiceLaborDTO InvoiceLaborDTOMapper(InvoiceLabor invoiceLabor) { laborMapper = new InvoiceLaborMapper(); return(laborMapper.InvoiceLaborDTOMapper(invoiceLabor)); }