public override GNInvoiceDetail PopulateSelectLists(GNInvoiceDetail invoiceDetail = null) { invoiceDetail = base.PopulateSelectLists(invoiceDetail); if (invoiceDetail == null) { invoiceDetail = new GNInvoiceDetail(); GNAccount acct = entityService.db.GNAccounts.Where(a => a.Organization.Id == UserContact.GNOrganizationId).FirstOrDefault(); if (acct != null) { invoiceDetail.DiscountAmount = acct.DefaultDiscountAmount; invoiceDetail.DiscountType = acct.DefaultDiscountType; } } if (!string.IsNullOrEmpty(Request["invoiceId"])) { invoiceDetail.Invoice = entityService.db.GNInvoices.Find(Guid.Parse((Request["invoiceId"]))); if (invoiceDetail.Invoice != null) { invoiceDetail.GNInvoiceId = invoiceDetail.Invoice.Id; } } return(invoiceDetail); }
public override string GetParentIdForEntityOnDelete(string id) { GNAccount acct = null; if (!string.IsNullOrEmpty(id)) { acct = entityService.db.GNPaymentMethods.Find(Guid.Parse(id)).Account; } if (acct != null) { id = acct.Id.ToString(); } return(id); }
private async Task <GNAccount> InsertNewOrgAccount(GNOrganization org, GNContact mainOrgContact, double maxBalanceAllowed = 0.0, bool validBillingAgreementRequired = true) { GNAccount acct = null; try { acct = new GNAccount { Id = Guid.NewGuid(), Organization = org, GNAccountTypeId = this.db.GNAccountTypes.Where(t => t.Name == "INDUSTRY").Select(t => t.Id).FirstOrDefault(), AccountOwner = mainOrgContact, BillingContact = mainOrgContact, MailingContact = mainOrgContact, CreateDateTime = DateTime.Now, CreatedBy = mainOrgContact.Id, DefaultDiscountAmount = 0.0, DefaultDiscountType = GNAccount.DiscountType.FLAT.GetCode(), BillingMode = GNAccount.BillingModeType.INVOICE.GetCode(), TotalAmountOwed = 0, TotalAmountPaid = 0, MaxBalanceAllowed = maxBalanceAllowed, ValidBillingAgreementRequired = validBillingAgreementRequired }; acct = this.db.GNAccounts.Add(acct); int result = await this.db.SaveChangesAsync(); } catch (Exception ex) { var ex2 = new Exception("Unable to add Account for Organization.", ex); LogUtil.Error(logger, ex2.Message, ex2); throw ex2; } return(acct); }
private void SendOrgAccountRegCompleteNotification(AspNetUser user) { try { if (!string.IsNullOrEmpty(user.DefaultOrganizationId)) { Guid orgGuid = Guid.Parse(user.DefaultOrganizationId); GNAccount orgAccount = this.db.GNAccounts.Where(a => a.Organization.Id == orgGuid).FirstOrDefault(); if (orgAccount != null) { GNContact mainOrgContact = orgAccount.Organization.OrgMainContact; if (mainOrgContact.AspNetUserId == user.Id) { //send notification bool notifySuccess = new GenomeNext.App.NotificationCloudMessageService().NotifyGNContact( "ORG_ACCOUNT_REGISTRATION_COMPLETE", mainOrgContact.Email, "Account:" + mainOrgContact.Id.ToString(), new Dictionary <string, string> { { "OrganizationName", orgAccount.Organization.Name }, { "FirstName", mainOrgContact.FirstName }, { "LastName", mainOrgContact.LastName } }); } } } } catch (Exception e) { LogUtil.Error(logger, "Unable to send org account registration complete notification after Email Confirmation: " + e.Message, e); } }
public async Task <ActionResult> AccountSubmit(RegisterAccountViewModel model) { if (ModelState.IsValid) { GNInviteCode inviteCodeRedemption = null; try { //redeem invite code inviteCodeRedemption = inviteCodeService.RedeemInviteCode(model.InviteCode); if (inviteCodeRedemption != null) { //Auth or Create User AspNetUser aspNetUser = await AuthCreateUser(model.Email, model.Password, model.IsExistingUser, verifyEmail : true, signUpForNews : model.SignUpForNewsAndProducts, organizationId : null); if (ModelState.IsValid && aspNetUser != null) { //Insert New Org GNOrganization org = await InsertNewOrganization(model); if (org != null) { //Insert Main Org Contact GNContact mainOrgContact = await InsertMainOrgContact(model, aspNetUser, org); if (mainOrgContact != null) { double maxBalanceAllowed = 0.0; bool validBillingAgreementRequired = false; //set free credit allowance based on invite code redemption if (inviteCodeRedemption.FreeCreditAllowance > 0.0) { maxBalanceAllowed = inviteCodeRedemption.FreeCreditAllowance; } GNAccount orgAccount = await InsertNewOrgAccount(org, mainOrgContact, maxBalanceAllowed, validBillingAgreementRequired); if (inviteCodeRedemption.InviteCode.Equals("GENandGEN2015")) { org.GNSettingsTemplate = db.GNSettingsTemplates.Where(a => a.Name == "GN_GENOMICS2015").FirstOrDefault(); db.SaveChanges(); } if (orgAccount != null) { if (model.IsExistingUser) { //send notification bool notifySuccess = new GenomeNext.App.NotificationCloudMessageService().NotifyGNContact( "ORG_ACCOUNT_REGISTRATION_COMPLETE", mainOrgContact.Email, "Account:" + mainOrgContact.Id.ToString(), new Dictionary <string, string> { { "OrganizationName", orgAccount.Organization.Name }, { "FirstName", mainOrgContact.FirstName }, { "LastName", mainOrgContact.LastName } }); } return(RedirectToAction("AccountComplete", new { id = org.Id })); } } } } } else { ModelState.AddModelError("InviteCode", "Unable to redeem Invite Code."); } } catch (Exception ex) { LogUtil.Error(logger, "Unable to perform Account Registration", ex); ModelState.AddModelError("", "Unable to perform Account Registration"); } if (inviteCodeRedemption != null) { inviteCodeService.UnRedeemInviteCode(model.InviteCode); } } return(View(model)); }