Using automapper to reverse map from dto - automapper

Given the following code, is there anyway to get Automapper to do this instead of manually setting the properties? I'm trying to avoid having to do a one to one mapping at Mapper.CreateMap, since I;m constantly adding and removing fields from Contract, and at the moment have to remember to update this method with the changes.
private void MapModelToContract(ContractDto model, Contract contract)
{
contract.Id = model.Id;
contract.ContractDetail.BuyerCornhouseName = model.ContractDetailBuyerCornhouseName;
contract.ContractDetail.CnoCornLtdToBuyer = model.ContractDetailCnoCornLtdToBuyer;
contract.ContractDetail.CnoCornPartToCornLtd = model.ContractDetailCnoCornPartToCornLtd;
contract.ContractDetail.CnoSellerCornLtd = model.ContractDetailCnoSellerCornLtd;
contract.ContractDetail.CnoSellerCornPart = model.ContractDetailCnoSellerCornPart;
contract.ContractDetail.Commission = model.ContractDetailCommission;
contract.ContractDetail.ContractPrice = model.ContractDetailContractPrice;
contract.ContractDetail.SalesPriceToCornLtd = model.ContractDetailSalesPriceToCornLtd;
contract.ContractDetail.ContractedQuantity = model.ContractDetailContractedQuantity;
contract.ContractDetail.CostWarehouseToFob = model.ContractDetailCostWarehouseToFob;
contract.ContractDetail.Date = model.ContractDetailDate;
contract.ContractDetail.DeliveryDate = model.ContractDetailDeliveryDate;
contract.ContractDetail.FinalBuyerName = model.ContractDetailFinalBuyerName;
contract.ContractDetail.FinalSalesPrice = model.ContractDetailFinalSalesPrice;
contract.ContractDetail.Grade = model.ContractDetailGrade;
contract.ContractDetail.Notes = model.ContractDetailNotes;
contract.ContractDetail.PayableQuantity = model.ContractDetailPayableQuantity;
contract.ContractDetail.SalesShipmentPeriod = model.ContractDetailSalesShipmentPeriod;
contract.ContractDetail.SellerName = model.ContractDetailSellerName;
contract.ContractDetail.ToBePaidBy = model.ContractDetailToBePaidBy;
contract.ContractDetail.SalesBasis = model.ContractDetailSalesBasis;
contract.ContractDetail.SalesFreightValue = model.ContractDetailSalesFreightValue;
contract.CurrencyContract.Date = model.CurrencyContractDate;
contract.CurrencyContract.ExchangeRate = model.CurrencyContractExchangeRate;
contract.CurrencyContract.Number = model.CurrencyContractNumber;
contract.CurrencyContract.Value = model.CurrencyContractValue;
contract.CurrencyContract.IsAcc = model.CurrencyContractIsAcc;
contract.CurrencyContract.RepaidOn = model.CurrencyContractRepaidOn;
contract.CurrencyContract.RepaymentDate = model.CurrencyContractRepaymentDate;
contract.Discounts.Reason = model.DiscountsReason;
contract.Discounts.Value = model.DiscountsValue;
contract.DocumentControl.GuaranteeLetterReceived = model.DocumentControlGuaranteeLetterReceived;
contract.DocumentControl.PhotosReceived = model.DocumentControlPhotosReceived;
contract.GoodsStatus.ContainerNumber = model.GoodsStatusContainerNumber;
contract.GoodsStatus.EtaPort = model.GoodsStatusEtaPort;
contract.GoodsStatus.ExpectedDeliveryDate = model.GoodsStatusExpectedDeliveryDate;
contract.GoodsStatus.Port = model.GoodsStatusPort;
contract.GoodsStatus.ShippedStatus = model.GoodsStatusShippedStatus;
contract.GoodsStatus.VesselDeadline = model.GoodsStatusVesselDeadline;
contract.GoodsStatus.VesselName = model.GoodsStatusVesselName;
contract.GoodsStatus.HasSellerConfirmedRelease = model.GoodsStatusHasSellerConfirmedRelease;
contract.GoodsStatus.ReceivedShippingInstructions = model.GoodsStatusReceivedShippingInstructions;
contract.GoodsStatus.Notes = model.GoodsStatusNotes;
contract.NotaFiscalCornPart.Date = model.NotaFiscalCornPartDate;
contract.NotaFiscalCornPart.ExchangeRate = model.NotaFiscalCornPartExchangeRate;
contract.NotaFiscalCornPart.Number = model.NotaFiscalCornPartNumber;
contract.NotaFiscalSeller.Date = model.NotaFiscalSellerDate;
contract.NotaFiscalSeller.GoodsReleased = model.NotaFiscalSellerGoodsReleased;
contract.NotaFiscalSeller.Number = model.NotaFiscalSellerNumber;
contract.TransferToSeller.Date = model.TransferToSellerDate;
contract.TransferToSeller.TransferredFrom = model.ContractDetailBuyerCornhouseName;
contract.TransferToSeller.Value = model.TransferToSellerValue;
contract.CommissionLawyer.IsPaid = model.CommissionLawyerIsPaid;
}

The below mapper works for you.
If the Source (ContractDto) and Destination (Contract) have same property names.
Mapper.CreateMap<ContractDto, Contract>(); // Maps if ContractDto & Contract have same property names
If the Source (ContractDto) and Destination (Contract) have diff property names. Then
Mapper.CreateMap<ContractDto, Contract>()
.ForMember(destination => destination.BuyerCornhouseName, options => options.MapFrom(source => source.ContractDetailBuyerCornhouseName))
.ForMember(destination => destination.CnoCornLtdToBuyer, options => options.MapFrom(source => source.ContractDetailCnoCornLtdToBuyer));
// Explicitly you have specify for other properties also

Related

How to prompt for user info for a key in a map type variable in Terraform

I have the following variable in terraform:
rds_config_list = [
{
rds_name = "shiftleft"
rds_identifier = "shiftleft-postgres"
rds_password = <USETINPUT>
rds_snapshot_identifier = "shiftleft"
rds_postgres_instance_class = "db.m6g.large"
rds_postgres_engine_version = "13.3"
rds_postgres_family = "postgres13"
rds_postgres_allocated_storage = 100
rds_postgres_max_allocated_storage = 1000
rds_backup_retention_period = 7
rds_postgres_multi_az = false
rds_postgres_deletion_protection = false
},
{
rds_name = "shiftleft2"
rds_identifier = "shiftleft2-postgres"
rds_password = <USETINPUT>
rds_snapshot_identifier = "shiftleft2"
rds_postgres_instance_class = "db.m6g.large"
rds_postgres_engine_version = "13.3"
rds_postgres_family = "postgres13"
rds_postgres_allocated_storage = 100
rds_postgres_max_allocated_storage = 1000
rds_backup_retention_period = 7
rds_postgres_multi_az = false
rds_postgres_deletion_protection = false
}
]
i want to prompt for user input for the passwords for each of them and not have the same password for all databases, this is inside a .tfvars file. is there any way to do it?

Automate copy paste Excel ranges dynamically from different sheets

I have tables in different sheets of excel and requirement is to copy second last row of table to last row. Can someone pls help me how can we dynamically find table size so that code wont be required to change evrytime when table size changes? There are many tables and we want to automate this task using vba code and macro button.
I have written a code but that is range specific and everytime I need to update the range and process become cumbersome.
Sub history_copy()
Set obj = ActiveWorkbook.Sheets("sheet A")
obj.Range("E12:N12").Value = obj.Range("E11:N11").Value
obj.Range("E34:N34").Value = obj.Range("E33:N33").Value
obj.Range("E46:N46").Value = obj.Range("E45:N45").Value
obj.Range("E57:N57").Value = obj.Range("E56:N56").Value
Set obj1 = ActiveWorkbook.Sheets("sheet b ")
obj1.Range("G21:O21").Value = obj1.Range("G20:O20").Value
Set obj2 = ActiveWorkbook.Sheets("sheet c")
obj2.Range("D4:M4").Value = obj2.Range("D3:M3").Value
obj2.Range("D14:M14").Value = obj2.Range("D13:M13").Value
obj2.Range("D23:M23").Value = obj2.Range("D22:M22").Value
obj2.Range("D33:M33").Value = obj2.Range("D32:M32").Value
obj2.Range("D43:M43").Value = obj2.Range("D42:M42").Value
obj2.Range("D52:M52").Value = obj2.Range("D51:M51").Value
obj2.Range("D61:M61").Value = obj2.Range("D60:M60").Value
obj2.Range("D70:M70").Value = obj2.Range("D69:M69").Value
obj2.Range("D79:M79").Value = obj2.Range("D78:M78").Value
obj2.Range("D88:M88").Value = obj2.Range("D87:M87").Value
obj2.Range("D97:M97").Value = obj2.Range("D96:M96").Value
obj2.Range("D106:M106").Value = obj2.Range("D105:M105").Value
obj2.Range("D114:M114").Value = obj2.Range("D113:M113").Value
Set obj3 = ActiveWorkbook.Sheets("sheet d")
obj3.Range("D4:L4").Value = obj3.Range("D3:L3").Value
Set obj5 = ActiveWorkbook.Sheets("sheet f")
obj5.Range("D4:L4").Value = obj5.Range("D3:L3").Value
Set obj6 = ActiveWorkbook.Sheets("sheet e")
obj6.Range("C4:C12").Value = obj6.Range("B4:B12").Value
obj6.Range("H4:H8").Value = obj6.Range("G4:G8").Value
obj6.Range("N4:N11").Value = obj6.Range("M4:M11").Value
obj6.Range("S4:S10").Value = obj6.Range("R4:R10").Value
obj6.Range("X4:X18").Value = obj6.Range("W4:W18").Value
obj6.Range("AD4:AD9").Value = obj6.Range("AC4:AC9").Value
obj6.Range("AI4:AI13").Value = obj6.Range("AH4:AH13").Value
obj6.Range("AO4:AO6").Value = obj6.Range("AN4:AN6").Value
obj6.Range("AT4:AT11").Value = obj6.Range("AS4:AS11").Value
obj6.Range("AY4:AY20").Value = obj6.Range("AX4:AX20").Value
obj6.Range("BD4:BD10").Value = obj6.Range("BC4:BC10").Value
obj6.Range("BI4:BI21").Value = obj6.Range("BH4:BH21").Value
Set obj7 = ActiveWorkbook.Sheets("sheet i")
obj7.Range("C4:C12").Value = obj7.Range("B4:B12").Value
obj7.Range("H4:H8").Value = obj7.Range("G4:G8").Value
obj7.Range("N4:N11").Value = obj7.Range("M4:M11").Value
obj7.Range("S4:S10").Value = obj7.Range("R4:R10").Value
obj7.Range("X4:X18").Value = obj7.Range("W4:W18").Value
obj7.Range("AD4:AD9").Value = obj7.Range("AC4:AC9").Value
obj7.Range("AI4:AI13").Value = obj7.Range("AH4:AH13").Value
obj7.Range("AO4:AO6").Value = obj7.Range("AN4:AN6").Value
obj7.Range("AT4:AT11").Value = obj7.Range("AS4:AS11").Value
obj7.Range("AY4:AY20").Value = obj7.Range("AX4:AX20").Value
obj7.Range("BD4:BD10").Value = obj7.Range("BC4:BC10").Value
obj7.Range("BI4:BI21").Value = obj7.Range("BH4:BH21").Value
End Sub

how to update all legal entity in stripe through api

How to update all legal entity in stripe through API?
Thanks in advance. When run this, it throws errors like invalid arguments
\Stripe\Stripe::setApiKey("");
$account = \Stripe\Account::retrieve("");
$account->first_name = "555-867-5309";
$account->save();
$acc_details = \Stripe\Account::retrieve('');
$acc_details->legal_entity['first_name'] = 'First Name';
$acc_details->legal_entity['last_name'] = 'Last Name';
$acc_details->legal_entity['dob']['day'] = '04';
$acc_details->legal_entity['dob']['month'] = '05';
$acc_details->legal_entity['dob']['year'] = '1980';
$acc_details->legal_entity['type'] = 'individual';//Either “individual” or “company”
$acc_details->legal_entity['address']['city'] = 'Abbotsford';
$acc_details->legal_entity['address']['country'] = 'CA';
$acc_details->legal_entity['address']['line1'] = '33415 Maclure Rd';
$acc_details->legal_entity['address']['line2'] = '33415 Maclure Rd';
$acc_details->legal_entity['address']['postal_code'] = 'V2S 7W2';
$acc_details->legal_entity['address']['state'] = 'BC';
$acc_details->legal_entity['personal_id_number'] = '056464654';

How to inset a customer location through graph

Hello I am banging my head against the wall trying find the correct way to insert a customer location using a graph. I am currently using the PX.Objects.CR.CustomerLocationMaint graph. But when I insert or set current location it is always null.
Here is my code
private PX.Objects.CR.Location UpdateCustomerLocation(PX.Objects.AR.Customer cust, ListingRead currentListing, ListingContactRelnListing contact)
{
PX.Objects.AR.CustomerLocationMaint g = new PX.Objects.AR.CustomerLocationMaint();
g.Clear(PXClearOption.ClearAll);
g.BusinessAccount.Current = cust;
PX.Objects.CR.Location loc = new PX.Objects.CR.Location();
loc.BAccountID = cust.BAccountID;
loc.LocationCD = "RL" + contact.contact.id;
loc.Descr = currentListing.property.system_search_key;
loc.DefContactID = cust.DefContactID;
loc.IsActive = true;
loc.LocType = "CU";
g.Location.Current = loc;
loc = g.Location.Insert(loc);
PX.Objects.CR.Address addr = new PX.Objects.CR.Address();
addr.BAccountID = cust.BAccountID;
addr.AddressType = "BS";
addr.CountryID = "NZ";
addr.AddressLine1 = currentListing.property.adr_street_number + " " + currentListing.property.adr_street_name;
addr.AddressLine2 = currentListing.property.adr_suburb_or_town;
addr.AddressLine3 = currentListing.property.adr_state_or_region;
addr = g.Address.Insert(addr);
loc.DefAddressID = addr.AddressID;
g.Location.Update(loc);
g.Actions.PressSave();
return loc;
}

(Python/Pygame) Best way to load a LOT of images at the same time?

I have a function to load sounds, but not one for loading images. This is how my image loading is layed out currently:
if os.path.exists("themes/voltorb"):
vgui = pygame.image.load("themes/voltorb/gui.png")
voptions = pygame.image.load("themes/voltorb/options.png")
vachievements = pygame.image.load("themes/voltorb/achievements.png")
voverlay = pygame.image.load("themes/voltorb/overlay.png")
vconfirm = pygame.image.load("themes/voltorb/confirm.png")
vboom = pygame.mixer.Sound("themes/voltorb/boom.mp3")
vcoin = pygame.mixer.Sound("themes/voltorb/coin.mp3")
vtheme = {"gui":vgui,"options":voptions,"achievements":vachievements,"overlay":voverlay,"confirm":vconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"v":vtheme})
if os.path.exists("themes/fluttershy"):
fcoin = pygame.mixer.Sound("themes/fluttershy/coin.mp3")
fgui = pygame.image.load("themes/fluttershy/gui.png")
foptions = pygame.image.load("themes/fluttershy/options.png")
fachievements = pygame.image.load("themes/fluttershy/achievements.png")
foverlay = pygame.image.load("themes/fluttershy/overlay.png")
ftheme = {"gui":fgui,"options":foptions,"achievements":fachievements,"overlay":foverlay,"confirm":fconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"f":ftheme})
if os.path.exists("themes/mario"):
mgui = pygame.image.load("themes/mario/gui.png")
moptions = pygame.image.load("themes/mario/options.png")
machievements = pygame.image.load("themes/mario/achievements.png")
moverlay = pygame.image.load("themes/mario/overlay.png")
mtheme = {"gui":mgui,"options":moptions,"achievements":machievements,"overlay":moverlay,"confirm":mconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"m":mtheme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret1"):
s1gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/gui.png")
s1options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/options.png")
s1achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/achievements.png")
s1overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/overlay.png")
s1theme = {"gui":s1gui,"options":s1options,"achievements":s1achievements,"overlay":s1overlay,"confirm":s1confirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"s1":s1theme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret2"):
s2gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/gui.png")
s2options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/options.png")
s2achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/achievements.png")
s2overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/overlay.png")
s2theme = {"gui":s2gui,"options":s2options,"achievements":s2achievements,"overlay":s2overlay,"confirm":s2confirm,"coin":s2coin,"boom":s2boom,"music":s2music}
themedb.update({"s2":s2theme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret3"):
s3gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/gui.png")
s3options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/options.png")
s3achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/achievements.png")
s3overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/overlay.png")
s3theme = {"gui":s3gui,"options":s3options,"achievements":s3achievements,"overlay":s3overlay,"confirm":s3confirm,"coin":s3coin,"boom":s3boom,"music":s3music}
themedb.update({"s3":s3theme})
I'm not sure if there's any easy way to do this, but I have the most difficult way typed already. If anyone has an idea of how to shorten this, then thanks!
Take all your images and put them in a dict, where the key is the variable you were using, and the value is the path:
vimages = {'vgui': "themes/voltorb/gui.png", 'voptions': "themes/voltorb/options.png", 'vachievements': "themes/voltorb/achievements.png"} # and so on...
Then, iterate through vimages, checking for the existence of each individual file, then calling pygame.image.load() on it, and store the result in your already-existing dict (vtheme, in this case).
This way, you don't need to keep writing out pygame.image.load() over and over again.

Resources