public bool UpdateMerchantSettings(OverviewMerchant store)
        {
            try
            {
                var dc = new ManagementContext();
                var merc = dc.Merchants.Where(x => x.InternalReference == store.InternalReference && x.MerchantId == store.MerchantId && x.PrivateManagerId == store.PrivateManagerId).FirstOrDefault();

                if (merc != null)
                {
                    merc.OrderPayedNotificationEmail = store.OrderPayedNotificationEmail;
                    merc.PaypalEmail = store.PaypalEmail;
                    //need to make sure we have a paypal email.
                    if (String.IsNullOrEmpty(merc.PaypalEmail))
                        merc.AcceptPaymentsViaPaypal = false;
                    else
                        merc.AcceptPaymentsViaPaypal = store.AcceptPaymentsViaPaypal;
                    if (merc.AcceptPaymentsViaStripe || (store.AcceptPaymentsViaPaypal && !String.IsNullOrEmpty(store.PaypalEmail)))
                        merc.IsPublished = store.IsPublished;
                    else
                        merc.IsPublished = false;

                    dc.SaveChanges();
                    return true;
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }
        /// <summary>
        /// Gets a list with merchants for overview
        /// </summary>
        /// <returns></returns>
        public List<OverviewMerchant> GetMerchants()
        {
            var output = new List<OverviewMerchant>();
            try
            {
                var mc = new ManagementContext();
                var merchants = mc.Merchants.Include("Items").Where(x => x.IsRDNation.Equals(false)).Select(x => new { x.MerchantId, x.InternalReference, x.PrivateManagerId, x.InternalReferenceType, x.OwnerName, x.ShopName, x.AmountOnAccount, x.PayedFeesToRDN, x.Created, itemsInShop = x.Items.Count });

                foreach (var dbmerchant in merchants)
                {
                    var merchant = new OverviewMerchant();
                    merchant.AmountOnAccount = dbmerchant.AmountOnAccount;
                    merchant.PrivateManagerId = dbmerchant.PrivateManagerId;
                    merchant.Created = dbmerchant.Created;
                    merchant.InternalReference = dbmerchant.InternalReference;
                    merchant.InternalReferenceType = (MerchantInternalReference)dbmerchant.InternalReferenceType;
                    merchant.MerchantId = dbmerchant.MerchantId;
                    merchant.OwnerName = dbmerchant.OwnerName;
                    merchant.PayedFeesToRDN = dbmerchant.PayedFeesToRDN;
                    merchant.ShopName = dbmerchant.ShopName;
                    merchant.NumberOfItemsForSale = dbmerchant.itemsInShop;
                    output.Add(merchant);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return output;
        }
 public DisplayInvoice()
 {
     Refunds = new List<InvoiceRefund>();
     Merchant = new OverviewMerchant();
     InvoiceItems = new List<InvoiceItem>();
     InvoiceShipping = new InvoiceContactInfo();
     InvoiceBilling = new InvoiceContactInfo();
     SellersAddress = new InvoiceContactInfo();
 }
 public ActionResult MerchantSettings(OverviewMerchant merchant)
 {
     try
     {
         MerchantGateway mg = new MerchantGateway();
         mg.UpdateMerchantSettings(merchant);
         NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
         string u = nameValueCollection["return"];
         if (!String.IsNullOrEmpty(u))
         {
             return Redirect(u + "?u=" + SiteMessagesEnum.sus);
         }
         return Redirect(Url.Content("~/merchant/settings?u=" + SiteMessagesEnum.sus));
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
 }
 private static OverviewMerchant GetDisplayMerchant(Merchant merchant)
 {
     try
     {
         var merch = new OverviewMerchant();
         merch.ShopName = merchant.ShopName;
         merch.MerchantId = merchant.MerchantId;
         merch.InternalReference = merchant.InternalReference;
         merch.PrivateManagerId = merchant.PrivateManagerId;
         merch.AmountOnAccount = merchant.AmountOnAccount;
         
         if (merchant.CurrencyRate == null)
         {
             merch.Currency = "USD";
             merch.CurrencyCost = 1;
         }
         else
         {
             merch.Currency = merchant.CurrencyRate.CurrencyAbbrName;
             merch.CurrencyCost = merchant.CurrencyRate.CurrencyExchangePerUSD;
         }
         merch.OrderPayedNotificationEmail = merchant.OrderPayedNotificationEmail;
         merch.PayedFeesToRDN = merchant.PayedFeesToRDN;
         merch.IsPublished = merchant.IsPublished;
         merch.AcceptPaymentsViaPaypal = merchant.AcceptPaymentsViaPaypal;
         merch.PaypalEmail = merchant.PaypalEmail;
         merch.AcceptPaymentsViaStripe = merchant.AcceptPaymentsViaStripe;
         merch.StripeConnectKey = merchant.StripeConnectKey;
         merch.StripeConnectToken = merchant.StripeConnectToken;
         merch.WelcomeMessage = merchant.WelcomeMessage;
         return merch;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return null;
 }
 private static OverviewMerchant DisplayMerchant(Merchant dbmerchant)
 {
     try
     {
         var merchant = new OverviewMerchant();
         merchant.AmountOnAccount = dbmerchant.AmountOnAccount;
         merchant.PrivateManagerId = dbmerchant.PrivateManagerId;
         merchant.Created = dbmerchant.Created;
         merchant.InternalReference = dbmerchant.InternalReference;
         merchant.InternalReferenceType = (MerchantInternalReference)dbmerchant.InternalReferenceType;
         merchant.MerchantId = dbmerchant.MerchantId;
         merchant.OwnerName = dbmerchant.OwnerName;
         merchant.PayedFeesToRDN = dbmerchant.PayedFeesToRDN;
         merchant.ShopName = dbmerchant.ShopName;
         merchant.AcceptPaymentsViaPaypal = dbmerchant.AcceptPaymentsViaPaypal;
         merchant.AcceptPaymentsViaStripe = dbmerchant.AcceptPaymentsViaStripe;
         merchant.PaypalEmail = dbmerchant.PaypalEmail;
         merchant.OrderPayedNotificationEmail = dbmerchant.OrderPayedNotificationEmail;
         merchant.StripeConnectKey = dbmerchant.StripeConnectKey;
         merchant.StripeConnectToken = dbmerchant.StripeConnectToken;
         merchant.StripePublishableKey = dbmerchant.StripePublishableKey;
         merchant.StripeRefreshToken = dbmerchant.StripeRefreshToken;
         merchant.StripeTokenType = dbmerchant.StripeTokenType;
         merchant.StripeUserId = dbmerchant.StripeUserId;
         return merchant;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return null;
 }
        public OverviewMerchant CreateMerchantAccount(Guid internalId, MerchantInternalReference internalReference)
        {
            OverviewMerchant merchant = new OverviewMerchant();
            try
            {
                var dc = new ManagementContext();
                string notificationEmail = String.Empty;
                string ownerName = String.Empty;

                if (internalReference == MerchantInternalReference.Member)
                {
                    var mem = dc.Members.Where(x => x.MemberId == internalId).FirstOrDefault();
                    if (mem != null && mem.ContactCard != null && mem.ContactCard.Emails.FirstOrDefault() != null)
                        notificationEmail = mem.ContactCard.Emails.FirstOrDefault().EmailAddress;
                    ownerName = mem.DerbyName;
                }

                Merchant merc = MerchantGateway.CreateMerchantAccount(internalId, internalReference, notificationEmail, ownerName);
                merchant.InternalReference = internalId;
                merchant.MerchantId = merc.MerchantId;
                merchant.PrivateManagerId = merc.PrivateManagerId;
                merchant.ShopName = merc.ShopName;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return merchant;
        }