Пример #1
0
        public JsonResult Index()
        {
            var ebay         = new eBayDatabaseMarketPlace();
            var marketplaces = this.context.Customer.CustomerMarketPlaces
                               .Where(m => m.Marketplace.InternalId == ebay.InternalId)
                               .Select(m => new SimpleMarketPlaceModel {
                displayName = m.DisplayName, MpId = m.Marketplace.Id, MpName = m.Marketplace.Name
            });

            return(Json(marketplaces, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public static IEnumerable <MP_CustomerMarketPlace> GetEbayCustomerMarketPlaces(this Customer customer)
        {
            var ebay = new eBayDatabaseMarketPlace();

            return(customer.CustomerMarketPlaces.Where(m => m.Marketplace.InternalId == ebay.InternalId));
        }
Пример #3
0
        public JsonResult FetchToken(string username)
        {
            try {
                var customer = this.context.Customer;
                if (customer == null)
                {
                    Log.Warn("Customer is not authorized in system");
                    return(Json(new { error = "Customer is not authorized in system" }, JsonRequestBehavior.AllowGet));
                }

                var ebay = new eBayDatabaseMarketPlace();

                var sid      = TempData["SID"] as string;
                var isUpdate = TempData["isUpdate"] is bool && (bool)TempData["isUpdate"];

                if (string.IsNullOrEmpty(sid))
                {
                    Log.Warn("Sid is empty");
                    return(Json(new { error = "Username is empty" }, JsonRequestBehavior.AllowGet));
                }
                if (string.IsNullOrEmpty(username))
                {
                    Log.Warn("Username is empty");
                    return(Json(new { error = "Username is empty" }, JsonRequestBehavior.AllowGet));
                }
                bool             isValid          = false;
                eBaySecurityInfo eBaySecurityInfo = null;
                try {
                    Log.InfoFormat("Saving sid {0} for username {1}", sid, username);
                    var token = this.eBayServiceHelper.FetchToken(sid);
                    Log.InfoFormat("Token {0} was generated.", token);

                    eBaySecurityInfo = new eBaySecurityInfo {
                        Token = token
                    };

                    isValid = this.eBayServiceHelper.ValidateAccount(eBaySecurityInfo);
                } catch (Exception ex) {
                    Log.Warn("Failed fetching token", ex);
                }

                if (!isValid)
                {
                    Log.WarnFormat("eBay account has not been activated yet");
                    return(Json(new { error = "Your account has not been activated yet. Accounts are not accessible until an actual debit or credit has first been posted to the account, even though you may have already filled out our account creation form." }, JsonRequestBehavior.AllowGet));
                }

                this.mpChecker.Check(ebay.InternalId, customer, username);

                var mp = this.helper.SaveOrUpdateCustomerMarketplace(username, ebay, eBaySecurityInfo, customer);

                this.session.Flush();

                if (!isUpdate)
                {
                    this.serviceClient.Instance.UpdateMarketplace(this.context.Customer.Id, mp.Id, true, this.context.UserId);
                }

                this.customers.SaveOrUpdate(customer);

                return(Json(new { msg = string.Format("Congratulations. Your shop was {0} successfully.", isUpdate ? "updated" : "added") }, JsonRequestBehavior.AllowGet));
            } catch (MarketPlaceAddedByThisCustomerException) {
                return(Json(new { error = DbStrings.StoreAddedByYou }, JsonRequestBehavior.AllowGet));
            } catch (MarketPlaceIsAlreadyAddedException) {
                return(Json(new { error = DbStrings.StoreAlreadyExistsInDb }, JsonRequestBehavior.AllowGet));
            } catch (Exception e) {
                Log.Error(e);
                return(Json(new { error = e.Message }, JsonRequestBehavior.AllowGet));
            }
        }