public static RentalGroups convertRentalGroup(RentalGroup_Representation rentalGroup) { RentalGroups convertedRentalGroup = new RentalGroups() { groupID = rentalGroup.id, comment = rentalGroup.comment, deposit = rentalGroup.deposit, isOpen = rentalGroup.isOpen }; Customers customer = convertCustomer(rentalGroup.rentals.FirstOrDefault().customer); Customers contact = null; if (rentalGroup.rentals.FirstOrDefault().contact != null) { contact = convertCustomer(rentalGroup.rentals.FirstOrDefault().contact); } foreach (var rental in rentalGroup.rentals) { var convertedRental = convertRental(rental); convertedRental.Customers = customer; if (contact != null) { convertedRental.Customers1 = contact; } convertedRentalGroup.Rentals.Add(convertedRental); } return(convertedRentalGroup); }
public static RentalGroup_Representation convertRentalGroup(RentalGroups rentalGroup) { RentalGroup_Representation convertedRentalGroup = new RentalGroup_Representation() { comment = rentalGroup.comment, deposit = rentalGroup.deposit ?? 0, id = rentalGroup.groupID, isOpen = rentalGroup.isOpen }; foreach (Rentals rental in rentalGroup.Rentals) { RentalRepresentation rentalToAdd = convertRental(rental); rentalToAdd.group = convertedRentalGroup; convertedRentalGroup.rentals.Add(rentalToAdd); } return(convertedRentalGroup); }
public long AddRentalGroup(RentalGroup_Representation rentalGroup) { using (ISQLConnection dataSource = DataSource) { RentalGroups rentalGroupToAdd = RepresentationConverter.convertRentalGroup(rentalGroup); //foreach (RentalRepresentation rental in rentalGroup.rentals) //{ //rentalGroupToAdd.Rentals.Add(RepresentationConverter.convertRental(rental)); //dataSource.UpdateTool(RepresentationConverter.convertTool(rental.tool)); //dataSource.UpdateCustomer(RepresentationConverter.convertCustomer(rental.customer)); //} rentalGroup.id = dataSource.AddRentalGroup(rentalGroupToAdd); //foreach (RentalRepresentation rental in rentalGroup.rentals) //{ // rental.group = rentalGroup; // AddRental(rental); //} return(rentalGroup.id); } }