private void AddShippingAddressToOwnerPersonIfItIsNew(ProductChild pc) { Owner productChildOwner = pc.Owner; productChildOwner.IsNullThrowException(); Person ownerPerson = productChildOwner.Person; ownerPerson.IsNullThrowException(); AddressBiz addressBiz = OwnerBiz.AddressBiz; //get the address from the productChild AddressComplex shipFromAddressComplexInProductChild = pc.ShipFromAddressComplex; shipFromAddressComplexInProductChild.ErrorCheck(); //if there is no address... there should be an error. if (!shipFromAddressComplexInProductChild.Error.IsNullOrWhiteSpace()) { throw new Exception("You need to add the address of where the product is sitting"); } //address is complete. //We need to make the unique name from this so that we can check it exists in the db AddressMain addressToSave = addressBiz.Factory() as AddressMain; addressToSave.LoadFor(shipFromAddressComplexInProductChild); addressToSave.Name = addressToSave.MakeUniqueName(); //locate this address in Person //get all the addresses for the ownerPerson List <AddressMain> allAddressForOwnerPerson = addressBiz.FindAll().Where(x => x.PersonId == ownerPerson.Id).ToList(); if (allAddressForOwnerPerson.IsNull()) { //no addresses found. Its empty... //so add the new address addNewAddress(pc, ownerPerson, addressBiz, addressToSave); } { //addresses have been found //we do not update old addresses, we just add new ones, if they change. AddressMain addressFound = allAddressForOwnerPerson.FirstOrDefault(x => x.Name.ToLower() == addressToSave.Name.ToLower()); if (addressFound.IsNull()) { //the address was not found. //AddressComplex contains a new address //Add it to the person's addresses addNewAddress(pc, ownerPerson, addressBiz, addressToSave); } //else //{ // updateAddress(pc, addressBiz, addressToSave); //} } //otherwise do nothing }
//public AddressVerificationRequest GetAddressVerificationRequestConfirmation(AddressVerificationRequest avr) //{ // var avr2 = GetAddressVerificationRequest(avr.AddressId); // avr2.MailServiceEnum = avr.MailServiceEnum; // avr2.IsSure1 = avr.IsSure1; // avr2.DateIsSure1 = DateTime.UtcNow; // avr2.PaymentAmount = getVerificaionCost(avr2); // return avr2; //} //double getVerificaionCost(AddressVerificationRequest avr) //{ // string error = ""; // double verificationCost = 0; // switch (avr.MailServiceEnum) // { // case MailServiceENUM.Post: // switch (CountryBiz.IsAddressInPakistan(avr.CountryId)) // { // case true: // //is in Pakistan // verificationCost = VerificationConfig.Cost_Postal_Local; // break; // case false: // //is foreign // verificationCost = VerificationConfig.Cost_Postal_International; // break; // default: // error = string.Format("No such option"); // throw new Exception(error); // } // break; // case MailServiceENUM.Courier: // switch (CountryBiz.IsAddressInPakistan(avr.CountryId)) // { // case true: // //is in Pakistan // verificationCost = VerificationConfig.Cost_Courier_Local; // break; // case false: // verificationCost = VerificationConfig.Cost_Courier_International; // //is foreign // break; // default: // error = string.Format("No such option"); // throw new Exception(error); // } // break; // default: // error = string.Format("No such option: {0}", avr.MailServiceEnum); // throw new Exception(error); // } // return verificationCost; //} public void IssueAddressVerificationRequest(AddressVerificationRequest avr, GlobalObject globalObject) { avr.AddressId.IsNullOrWhiteSpaceThrowArgumentException("id"); if (avr.MailServiceEnum == MailServiceENUM.Unknown) { throw new Exception("Mail Service is unknown"); } if (avr.IsSure1 == false) { throw new Exception("Not Sure 1"); } if (avr.IsSure2 == false) { throw new Exception("Not Sure 2"); } if (avr.PaymentAmount == 0) { throw new Exception("No payment amount."); } AddressMain address = Find(avr.AddressId); address.IsNullThrowException("Address Not found"); AddressVerificationTrx addyVerfTrx = fixAddressVerificationTrx(avr, address); //this is where we give the verification number long verificationNumber = GenerateRandomVerificationNumber; addyVerfTrx.Verification.VerificationNumber = verificationNumber; if (address.AddressVerificationTrxs.IsNull()) { address.AddressVerificationTrxs = new List <AddressVerificationTrx>(); } address.AddressVerificationTrxs.Add(addyVerfTrx); address.Verification.VerificaionStatusEnum = VerificaionStatusENUM.Requested; AddressVerificationTrxBiz.Create(addyVerfTrx); ControllerCreateEditParameter param = new ControllerCreateEditParameter(); param.Entity = address as ICommonWithId; param.GlobalObject = globalObject; UpdateAndSave(param); //UpdateAndSave(address); }
public override void Fix(ControllerCreateEditParameter parm) { base.Fix(parm); AddressMain addy = parm.Entity as AddressMain; AttachCountry(addy); addy.Name = parm.Entity.MakeUniqueName(); addy.VerificationStatusEnum = addy.Verification.VerificaionStatusEnum; }
public void AddPickupAddress(BuySellDoc buySellDoc) { //add the PickUp From Address to the Complex buySellDoc.AddressShipFromId.IsNullOrWhiteSpaceThrowException("AddressShipFromId"); AddressMain addressShipFrom = AddressBiz.Find(buySellDoc.AddressShipFromId); addressShipFrom.IsNullThrowException("addressShipFrom"); buySellDoc.AddressShipFromString = addressShipFrom.AddressWithoutContacts(); buySellDoc.AddressShipFromComplex = addressShipFrom.ToAddressComplex(); }
private void AttachCountry(AddressMain addy) { //addy.CountryId.IsNullOrWhiteSpaceThrowException("Country ID is null. Programming Error"); //if (addy.Country.IsNull()) //{ // Country country = CountryBiz.Find(addy.CountryId); // country.IsNullThrowException("Country not found."); // addy.Country = country; //} }
public override ICommonWithId Factory() { ICommonWithId icommon = base.Factory(); AddressMain address = icommon as AddressMain; address.AddressType.IsBillAddress = true; address.AddressType.IsInformAddress = true; address.AddressType.IsShipAddress = true; return(icommon); }
public AddressVerificationRequest GetAddressVerificationRequest(string addressId) { UserId.IsNullOrWhiteSpaceThrowArgumentException("Please log in"); addressId.IsNullOrWhiteSpaceThrowArgumentException("No Address Id"); AddressMain address = Find(addressId); address.IsNullThrowException("Address Not found"); return(load_AddressVerificationRequestModel(addressId, address)); }
public void UpdateAndSaveDefaultAddress(string userId, string addressId, GlobalObject globalObject) { userId.IsNullOrWhiteSpaceThrowArgumentException("userId"); addressId.IsNullOrWhiteSpaceThrowArgumentException("AddressId is null"); AddressMain address = Find(addressId); address.IsNullThrowException("Address"); //the default address must always be all three if (!address.AddressType.IsBillAddress || !address.AddressType.IsShipAddress || !address.AddressType.IsInformAddress) { if (!address.AddressType.IsBillAddress) { ErrorsGlobal.AddMessage("Updated to Billing address."); } if (!address.AddressType.IsShipAddress) { ErrorsGlobal.AddMessage("Updated to Shipping address."); } if (!address.AddressType.IsInformAddress) { ErrorsGlobal.AddMessage("Updated to Inform To address."); } address.AddressType.IsBillAddress = true; address.AddressType.IsShipAddress = true; address.AddressType.IsInformAddress = true; Update(address); } Person person = UserBiz.GetPersonFor(userId); person.IsNullThrowException("Person not found"); person.DefaultBillAddressId = addressId; ControllerCreateEditParameter param = new ControllerCreateEditParameter(); param.Entity = person as ICommonWithId; param.GlobalObject = globalObject; PersonBiz.UpdateAndSave(param); //PersonBiz.UpdateAndSave(person); }
public SelectList SelectListForAddressId(string addressId) { try { addressId.IsNullThrowException(); AddressMain addy = Find(addressId); addy.IsNullThrowException(); addy.PersonId.IsNullOrWhiteSpaceThrowException(); return(SelectListForPersonId(addy.PersonId)); } catch (System.Exception) { return(new SelectList(Enumerable.Empty <SelectListItem>())); } }
private string addNewAddress(BuySellDoc bsd, Person person, AddressMain addressToSave) { bsd.IsNullThrowException(); if (addressToSave.BuySellDocs.IsNull()) { addressToSave.BuySellDocs = new List <BuySellDoc>(); } addressToSave.BuySellDocs.Add(bsd); addressToSave.PersonId = person.Id; person.Addresses.Add(addressToSave); return(addressToSave.Id); }
private void createAndAssignNew_ShipToAddress(BuySellDoc buySellDoc) { AddressMain addressToSave = AddressBiz.Factory() as AddressMain; addressToSave.LoadFor(buySellDoc.AddressShipToComplex); addressToSave.Name = addressToSave.MakeUniqueName(); if (addressToSave.BuySellDocs.IsNull()) { addressToSave.BuySellDocs = new List <BuySellDoc>(); } addressToSave.BuySellDocs.Add(buySellDoc); addressToSave.PersonId = buySellDoc.Customer.PersonId; buySellDoc.Customer.Person.Addresses.Add(addressToSave); buySellDoc.AddressShipToId = addressToSave.Id; AddressBiz.Create(addressToSave); }
private AddressVerificationRequest load_AddressVerificationRequestModel(string addressId, AddressMain address) { addressId.IsNullOrWhiteSpaceThrowArgumentException("addressId"); AddressVerificationRequest avr = new AddressVerificationRequest(); avr.AddressMailForm = address.ToPostalHTML(); avr.AddressId = addressId; //tod //avr.CountryId = address.CountryId; //avr.CourierInternationalPayment = VerificationConfig.Sale_Courier_International.ToString(); //avr.CourierLocalPayment = VerificationConfig.Sale_Courier_Local.ToString(); //avr.PostalInternationalPayment = VerificationConfig.Sale_Postal_International.ToString(); //avr.PostalLocalPayment = VerificationConfig.Sale_Postal_Local.ToString(); avr.CourierBtnCaption = ""; MailLocalOrForiegnENUM mailLocalOrForiegnEnum = IsAddressInPakistan(addressId) ? MailLocalOrForiegnENUM.InPakistan : MailLocalOrForiegnENUM.OutOfPakistan; string postBtnCaption; getVerificaionCharges(MailServiceENUM.Post, mailLocalOrForiegnEnum, out postBtnCaption); avr.PostalBtnCaption = postBtnCaption; string courierBtnCaption; getVerificaionCharges(MailServiceENUM.Courier, mailLocalOrForiegnEnum, out courierBtnCaption); avr.CourierBtnCaption = courierBtnCaption; avr.MailLocalOrForeignEnum = IsAddressInPakistan(addressId) ? MailLocalOrForiegnENUM.InPakistan : MailLocalOrForiegnENUM.OutOfPakistan; return(avr); }
private void updateAddress(ProductChild pc, AddressBiz addressBiz, AddressMain addressToSave) { pc.ShipFromAddressId = addressToSave.Id; addressBiz.Update(addressToSave); }
void createAddressVerificationTrx(AddressMain address, AddressVerificationTrx addyVerfTrx) { }
AddressVerificationTrx fixAddressVerificationTrx(AddressVerificationRequest avr, AddressMain address) { address.Verification.SetTo(EnumLibrary.EnumNS.VerificaionStatusENUM.Requested); //create a Verification Request AddressVerificationTrx addyVerfTrx = AddressVerificationTrxBiz.Factory() as AddressVerificationTrx; //addyVerfTrx.Address = address; addyVerfTrx.AddressId = avr.AddressId; addyVerfTrx.MailServiceEnum = avr.MailServiceEnum; //todo //addyVerfTrx.MailLocalOrForiegnEnum = GetMailLocalOrForiegnEnum(address.CountryId); //Accept payment here? addyVerfTrx.DateVerifcationPaymentAccepted = DateTime.UtcNow; addyVerfTrx.Verification.SetTo(VerificaionStatusENUM.Requested); addyVerfTrx.Name = string.Format("{0}-{1}", UserName, address.Name); return(addyVerfTrx); }
public string AddToSale(string userId, string productChildId, string poNumber, DateTime poDate) { userId.IsNullOrWhiteSpaceThrowException("No user"); double totalThisItem = 0; //who is the owner:The product Child owner is the owner //get the productChild productChildId.IsNullOrWhiteSpaceThrowException("No Product"); ProductChild productChild = ProductChildBiz.Find(productChildId); productChild.IsNullThrowException("productChild"); //get the product child's owner Owner ownerProductChild = productChild.Owner; ownerProductChild.IsNullThrowException("productChildOwner"); //get the owner //Get the select list for owner Person ownerPerson = ownerProductChild.Person; ownerPerson.IsNullThrowException("ownerPerson"); System.Web.Mvc.SelectList ownerSelectList = OwnerBiz.SelectListOnlyWith(ownerProductChild); ////the user is the customer user; //get the customer Customer customerUser = CustomerBiz.GetPlayerFor(userId); //Get the select list for Customer //remove the owner from the list... owner cannot sell to self. System.Web.Mvc.SelectList customerSelectList = CustomerBiz.SelectListWithout(ownerPerson); System.Web.Mvc.SelectList selectListOwner = OwnerBiz.SelectListOnlyWith(ownerProductChild); System.Web.Mvc.SelectList selectListCustomer = CustomerBiz.SelectListWithout(ownerPerson); //this is the address in the customer AddressMain addressBillTo = customerUser.DefaultBillAddress; AddressMain addressShipTo = customerUser.DefaultShipAddress; AddressComplex addressShipFromComplex = productChild.ShipFromAddressComplex; string addressBillToId = ""; string addressShipToId = ""; if (!addressBillTo.IsNull()) { addressBillToId = addressBillTo.Id; } if (!addressShipTo.IsNull()) { addressShipToId = addressShipTo.Id; } //Get the select list for AddressInform System.Web.Mvc.SelectList selectListBillTo = AddressBiz.SelectListBillAddressCurrentUser(); //Get the select list for AddressShipTo System.Web.Mvc.SelectList selectListShipTo = AddressBiz.SelectListShipAddressCurrentuser(); //check to see if there is any open sale which belongs to the same buyer and seller BuySellDoc sale = BuySellDocBiz.GetOpenSaleWithSameCustomerAndSeller(customerUser.Id, ownerProductChild.Id, productChild); //create the itemList. List <BuySellItem> buySellItems = new List <BuySellItem>(); string shopId = ""; if (sale.IsNull()) { //otherwise add a new sale sale = CreateSale( productChild, ownerProductChild, 1, productChild.Sell.SellPrice, customerUser, selectListOwner, selectListCustomer, addressBillToId, addressShipToId, selectListBillTo, selectListShipTo, BuySellDocStateENUM.RequestUnconfirmed, BuySellDocStateModifierENUM.Unknown, DateTime.Now, DateTime.Now, shopId); totalThisItem++; } else { //dont really need this, but it is good for consistancy. sale.BuySellDocumentTypeEnum = BuySellDocumentTypeENUM.Purchase; sale.BuySellDocStateEnum = BuySellDocStateENUM.RequestUnconfirmed; //now check to see if it is the same item... or is it a new item //get list of items for the sale List <BuySellItem> itemList = sale.BuySellItems.Where(x => x.MetaData.IsDeleted == false).ToList(); if (itemList.IsNullOrEmpty()) { BuySellItem buySellItem = new BuySellItem(sale.Id, productChild.Id, 1, productChild.Sell.SellPrice, productChild.FullName()); sale.Add(buySellItem); } else { //there are items in the list BuySellItem itemFound = itemList.FirstOrDefault(x => x.ProductChildId == productChild.Id); if (itemFound.IsNull()) { BuySellItem buySellItem = new BuySellItem(sale.Id, productChild.Id, 1, productChild.Sell.SellPrice, productChild.FullName()); sale.Add(buySellItem); } else { totalThisItem = itemFound.Quantity.Order; itemFound.Quantity.Order += 1; itemFound.Quantity.Order_Original = itemFound.Quantity.Order; //itemFound.Quantity.Ship += 1; } } totalThisItem++; sale.AddressShipFromComplex = addressShipFromComplex; BuySellDocBiz.GetDefaultVehicalType(sale); sale.AddressShipFromId = productChild.ShipFromAddressId; sale.RequestUnconfirmed.SetToTodaysDate(UserName, UserId); ControllerCreateEditParameter parm = new ControllerCreateEditParameter(); parm.Entity = sale as ICommonWithId; parm.GlobalObject = GetGlobalObject(); BuySellDocBiz.Update(parm); } BuySellDocBiz.SaveChanges(); string message = string.Format("Success. You ordered {0:N2} for {1:N2} (X{2:N2})", productChild.FullName(), productChild.Sell.SellPrice, totalThisItem); return(message); }
private static void addNewAddress(ProductChild pc, Person ownerPerson, AddressBiz addressBiz, AddressMain addressToSave) { pc.ShipFromAddressId = addressToSave.Id; if (addressToSave.ProductChilds.IsNull()) { addressToSave.ProductChilds = new List <ProductChild>(); } addressToSave.ProductChilds.Add(pc); ownerPerson.Addresses.Add(addressToSave); addressToSave.PersonId = ownerPerson.Id; addressBiz.Create(addressToSave); }
/// <summary> /// This returns the new address Id, or null. /// </summary> /// <param name="buySellDoc"></param> /// <param name="addressComplex"></param> /// <returns></returns> private bool isNewAddress(BuySellDoc buySellDoc, AddressComplex addressComplex, out string addressFoundId) { addressFoundId = ""; if (addressComplex.IsNull()) { return(false); } buySellDoc.IsNullThrowException(); Customer customer = buySellDoc.Customer; customer.IsNullThrowException(); Person person = customer.Person; person.IsNullThrowException(); addressComplex.ErrorCheck(); //if there is no address... there should be an error. if (!addressComplex.Error.IsNullOrWhiteSpace()) { throw new Exception(addressComplex.Error); } //address is complete. //We need to make the unique name from this so that we can check it exists in the db AddressMain addressToSave = AddressBiz.Factory() as AddressMain; addressToSave.LoadFor(addressComplex); addressToSave.Name = addressToSave.MakeUniqueName(); //locate this address in Person //get all the addresses for the ownerPerson List <AddressMain> allAddressForOwnerPerson = AddressBiz.FindAll().Where(x => x.PersonId == person.Id).ToList(); if (allAddressForOwnerPerson.IsNull()) { //no addresses found. Its empty... //so add the new address return(true); } else { //addresses have been found //we do not update old addresses, we just add new ones, if they change. AddressMain addressFound = allAddressForOwnerPerson.FirstOrDefault(x => x.Name.ToLower() == addressToSave.Name.ToLower()); if (addressFound.IsNull()) { //the address was not found. //AddressComplex contains a new address //Add it to the person's addresses return(true); } else { addressFoundId = addressFound.Id; } } return(false); }
private void addNewAddress(ICommonWithId entity, Person person, AddressBiz addressBiz, AddressMain addressToSave) { ProductChild pc = entity as ProductChild; pc.IsNullThrowException(); pc.ShipFromAddressId = addressToSave.Id; if (addressToSave.ProductChilds.IsNull()) { addressToSave.ProductChilds = new List <ProductChild>(); } addressToSave.ProductChilds.Add(pc); person.Addresses.Add(addressToSave); addressToSave.PersonId = person.Id; addressBiz.Create(addressToSave); }