Beispiel #1
0
        public ActionResult UpdateAddresses(int?[] country, string[] states_canadian, string[] states_other, string[] states_us,
                                            string billing_first_name, string billing_last_name, string billing_company, string billing_address, string billing_city, long?billing_citySelected,
                                            string billing_postcode, string billing_phone, string shipping_first_name, string shipping_last_name, string shipping_company,
                                            string shipping_address, string shipping_city, long?shipping_citySelected, string shipping_postcode, string shipping_phone)
        {
            var ownerid = sessionid.Value;
            var profile = repository.GetUserById(ownerid, subdomainid.Value);

            if (profile == null)
            {
                return(SendJsonErrorResponse("Cannot find profile"));
            }

            var addressHandler = new AddressHandler(profile.organisation1, repository);

            addressHandler.SetShippingAndBillingAddresses(billing_first_name,
                                                          billing_last_name,
                                                          billing_company,
                                                          billing_address,
                                                          billing_city,
                                                          billing_citySelected,
                                                          billing_postcode,
                                                          billing_phone,
                                                          country.ElementAtOrDefault(0),
                                                          states_canadian.ElementAtOrDefault(0),
                                                          states_other.ElementAtOrDefault(0),
                                                          states_us.ElementAtOrDefault(0),
                                                          shipping_first_name,
                                                          shipping_last_name,
                                                          shipping_company,
                                                          shipping_address,
                                                          shipping_city,
                                                          shipping_citySelected,
                                                          shipping_postcode,
                                                          shipping_phone,
                                                          country.ElementAtOrDefault(1),
                                                          states_canadian.ElementAtOrDefault(1),
                                                          states_other.ElementAtOrDefault(1),
                                                          states_us.ElementAtOrDefault(1),
                                                          false);

            repository.Save();
            CacheHelper.Instance.invalidate_dependency(DependencyType.products_subdomain, subdomainid.Value.ToString());
            CacheHelper.Instance.invalidate_dependency(DependencyType.organisation, subdomainid.Value.ToString());
#if LUCENE
            // update index
            var indexer = new LuceneWorker(db, profile.organisation1.MASTERsubdomain.ToIdName());
            indexer.AddToIndex(LuceneIndexType.CONTACTS, profile);
#endif
            return(Json(OPERATION_SUCCESSFUL.ToJsonOKData()));
        }
Beispiel #2
0
        public ActionResult update_addresses(string billing_first_name, string billing_last_name, string billing_company, string billing_address, string billing_city, long?billing_citySelected,
                                             string billing_postcode, string billing_phone,
                                             string shipping_first_name, string shipping_last_name, string shipping_company, string shipping_address, string shipping_city, long?shipping_citySelected, string shipping_postcode, string shipping_phone,
                                             int[] country, string[] states_canadian, string[] states_other, string[] states_us,
                                             bool ship_same_billing)
        {
            var handler = new AddressHandler(cart.user.organisation1, repository);

            handler.SetShippingAndBillingAddresses(billing_first_name,
                                                   billing_last_name,
                                                   billing_company,
                                                   billing_address,
                                                   billing_city,
                                                   billing_citySelected,
                                                   billing_postcode,
                                                   billing_phone,
                                                   country[0],
                                                   states_canadian[0],
                                                   states_other[0],
                                                   states_us[0],
                                                   shipping_first_name,
                                                   shipping_last_name,
                                                   shipping_company,
                                                   shipping_address,
                                                   shipping_city,
                                                   shipping_citySelected,
                                                   shipping_postcode,
                                                   shipping_phone,
                                                   country[1],
                                                   states_canadian[1],
                                                   states_other[1],
                                                   states_us[1],
                                                   ship_same_billing);

            repository.Save();

            return(RedirectToAction("final_step"));
        }
Beispiel #3
0
        private void SaveEbayOrders(OrderTypeCollection collection)
        {
            using (var repository = new TradelrRepository())
            {
                foreach (OrderType entry in collection)
                {
                    Transaction transaction;
                    // check if order already exists
                    var existingEbayOrder = repository.GetSubDomain(sd.id).ebay_orders.SingleOrDefault(x => x.orderid == entry.OrderID);

                    if (existingEbayOrder != null)
                    {
                        var order = existingEbayOrder.orders.Single();
                        transaction = new Transaction(order, repository, seller.id);

                        // update order status
                        existingEbayOrder.status = entry.OrderStatus.ToString();
                    }
                    else
                    {
                        // check if user already exists
                        var buyer = repository.GetUserByEbayID(entry.BuyerUserID);

                        if (buyer == null)
                        {
                            // get receiver and add to contact db
                            var userService = new UserService(token);

                            // get by itemid as invalid request seems to be returned when get by userid
                            var ebaybuyer = userService.GetUser(entry.BuyerUserID);

                            // we assume that same buyer for all transactions so we get the first email address
                            var buyeremail = entry.TransactionArray.ItemAt(0).Buyer.Email;

                            buyer = SaveEbayBuyer(ebaybuyer, buyeremail);
                        }

                        // add a shipping and billing address
                        if (entry.ShippingAddress != null)
                        {
                            var buyername = Utility.SplitFullName(entry.ShippingAddress.Name);
                            var handler   = new AddressHandler(buyer.organisation1, repository);
                            handler.SetShippingAndBillingAddresses(buyername[0],
                                                                   buyername[1],
                                                                   entry.ShippingAddress.CompanyName ?? "",
                                                                   entry.ShippingAddress.Street1 + "\r\n" + entry.ShippingAddress.Street2,
                                                                   entry.ShippingAddress.CityName,
                                                                   null,
                                                                   entry.ShippingAddress.PostalCode,
                                                                   entry.ShippingAddress.Phone,
                                                                   entry.ShippingAddress.Country.ToString().ToCountry().id,
                                                                   entry.ShippingAddress.StateOrProvince,
                                                                   entry.ShippingAddress.StateOrProvince,
                                                                   entry.ShippingAddress.StateOrProvince,
                                                                   buyername[0],
                                                                   buyername[1],
                                                                   entry.ShippingAddress.CompanyName ?? "",
                                                                   entry.ShippingAddress.Street1 + "\r\n" + entry.ShippingAddress.Street2,
                                                                   entry.ShippingAddress.CityName,
                                                                   null,
                                                                   entry.ShippingAddress.PostalCode,
                                                                   entry.ShippingAddress.Phone,
                                                                   entry.ShippingAddress.Country.ToString().ToCountry().id,
                                                                   entry.ShippingAddress.StateOrProvince,
                                                                   entry.ShippingAddress.StateOrProvince,
                                                                   entry.ShippingAddress.StateOrProvince,
                                                                   true);
                        }

                        // add normal order
                        transaction = new Transaction(sd, buyer, TransactionType.INVOICE, repository, seller.id);

                        transaction.CreateTransaction(repository.GetNewOrderNumber(sd.id, TransactionType.INVOICE),
                                                      entry.CreatedTime, "",
                                                      entry.AmountPaid.currencyID.ToString().ToCurrency().id);

                        // mark as sent
                        var tradelr_orderstatus = GetOrderStatus(entry.OrderStatus);
                        transaction.UpdateOrderStatus(tradelr_orderstatus);

                        // add ebay specific order information
                        var newEbayOrder = new ebay_order();
                        newEbayOrder.orderid     = entry.OrderID;
                        newEbayOrder.status      = entry.OrderStatus.ToString();
                        newEbayOrder.created     = entry.CreatedTime;
                        newEbayOrder.subdomainid = sd.id;
                        transaction.AddEbayOrderInformation(newEbayOrder);

                        foreach (eBay.Service.Core.Soap.TransactionType trans in entry.TransactionArray)
                        {
                            var ebay_itemid = trans.Item.ItemID;

                            // get product details
                            var itemservice = new ItemService(token);
                            var item        = itemservice.GetItem(ebay_itemid);

                            // add new product if necessary
                            var existingproduct = repository.GetProducts(sd.id).SingleOrDefault(x => x.ebayID.HasValue && x.ebay_product.ebayid == ebay_itemid);
                            if (existingproduct == null)
                            {
                                // add new product  (triggered when synchronisation is carried out the first time)
                                var newproduct = new Listing();
                                newproduct.Populate(item);
                                var importer = new ProductImport();
                                var pinfo    = importer.ImportEbay(newproduct, sd.id);

                                repository.AddProduct(pinfo, sd.id);
                                existingproduct = pinfo.p;
                            }
                            else
                            {
                                // if existing product is completed then we need to relist
                                if (entry.OrderStatus == OrderStatusCodeType.Completed ||
                                    entry.OrderStatus == OrderStatusCodeType.Shipped)
                                {
                                    // see if product listing is still active
                                    if (item.SellingStatus.ListingStatus == ListingStatusCodeType.Completed ||
                                        item.SellingStatus.ListingStatus == ListingStatusCodeType.Ended)
                                    {
                                        // set status to inactive
                                        existingproduct.ebay_product.isActive = false;

                                        // check if we should autorelist
                                        if (existingproduct.ebay_product.autorelist)
                                        {
                                            // check that product has enough stock
                                            if (existingproduct.HasStock(existingproduct.ebay_product.quantity))
                                            {
                                                var exporter =
                                                    new EbayExporter(
                                                        existingproduct.ebay_product.siteid.ToEnum <SiteCodeType>(),
                                                        sd.ToHostName(),
                                                        token,
                                                        sd);

                                                exporter.BuildItem(existingproduct.ebay_product);
                                            }
                                        }
                                    }
                                }
                            }

                            // add tradelr order item
                            var orderItem = new orderItem
                            {
                                description = item.Title,
                                variantid   = existingproduct.product_variants[0].id,
                                unitPrice   = (decimal)trans.TransactionPrice.Value,
                                quantity    = trans.QuantityPurchased
                            };

                            if (trans.Taxes != null)
                            {
                                orderItem.tax =
                                    (decimal)(trans.Taxes.TotalTaxAmount.Value / trans.TransactionPrice.Value);
                            }

                            transaction.AddOrderItem(orderItem, null);

                            // update inventory
                            transaction.UpdateInventoryItem(orderItem, trans.QuantityPurchased);

                            // add ebay order item
                            var ebayorderitem = new ebay_orderitem();
                            ebayorderitem.lineid = trans.OrderLineItemID;
                            newEbayOrder.ebay_orderitems.Add(ebayorderitem);
                        }

                        // update shipping
                        transaction.UpdateShippingCost(entry.ShippingServiceSelected.ShippingServiceCost.Value.ToString());
                        transaction.UpdateShippingMethod(entry.ShippingServiceSelected.ShippingService);

                        // update tax : ebay tax is the shipping tax which applies to the entire order total
                        // may or may not include shipping cost
                        if (entry.ShippingDetails.SalesTax != null)
                        {
                            transaction.UpdateOrderTax((decimal)entry.ShippingDetails.SalesTax.SalesTaxPercent,
                                                       entry.ShippingDetails.SalesTax.ShippingIncludedInTax);
                        }


                        transaction.UpdateTotal();
                        transaction.SaveNewTransaction(); ////////////////////// SAVE INVOICE
                    }

                    // the following applies to both new and existing order
                    var existingPayment = transaction.GetPayments().SingleOrDefault(x => x.reference == entry.OrderID);
                    if (existingPayment != null)
                    {
                        var newstatus = GetPaymentStatus(entry.CheckoutStatus.Status);
                        if (existingPayment.status != newstatus.ToString())
                        {
                            transaction.UpdatePaymentStatus(existingPayment, newstatus);
                        }
                    }
                    else
                    {
                        // if payment has been made then add payment
                        if (entry.CheckoutStatus.Status == CompleteStatusCodeType.Complete)
                        {
                            var p = new DBML.payment();
                            p.status     = GetPaymentStatus(entry.CheckoutStatus.Status).ToString();
                            p.method     = entry.CheckoutStatus.PaymentMethod.ToString();
                            p.created    = entry.CheckoutStatus.LastModifiedTime;
                            p.notes      = entry.BuyerCheckoutMessage;
                            p.paidAmount = (decimal)entry.AmountPaid.Value;
                            p.reference  = entry.OrderID;

                            transaction.AddPayment(p, false);
                        }
                    }

                    // if there is a shipped date, mark as ship if not already done so
                    if (transaction.GetOrderStatus() != OrderStatus.SHIPPED &&
                        entry.ShippedTimeSpecified)
                    {
                        transaction.UpdateOrderStatus(OrderStatus.SHIPPED);

                        if (entry.ShippingDetails.ShipmentTrackingDetails.Count != 0)
                        {
                            foreach (ShipmentTrackingDetailsType trackentry in entry.ShippingDetails.ShipmentTrackingDetails)
                            {
                                var comment = string.Format(OrderComment.ORDER_SHIP_STANDARD,
                                                            trackentry.ShippingCarrierUsed,
                                                            trackentry.ShipmentTrackingNumber);
                                transaction.AddComment(comment);
                            }
                        }
                        else
                        {
                            transaction.AddComment(OrderComment.ORDER_SHIP, created: entry.ShippedTime);
                        }
                    }
                    repository.Save();  // save per order
                }
            }
        }
        public ActionResult Update(long?id, string email, string address, string city, long?citySelected, string coPhone,
                                   string companyName, IEnumerable <int?> country, string fax, string firstName, int?permissions,
                                   string gender, string lastName, string notes, string phone, string postcode, string title, string password,
                                   IEnumerable <string> states_canadian, IEnumerable <string> states_other, IEnumerable <string> states_us,
                                   string billing_first_name, string billing_last_name, string billing_company, string billing_address, string billing_city, long?billing_citySelected,
                                   string billing_postcode, string billing_phone,
                                   string shipping_first_name, string shipping_last_name, string shipping_company, string shipping_address, string shipping_city, long?shipping_citySelected, string shipping_postcode, string shipping_phone)
        {
            if (!id.HasValue)
            {
                return(SendJsonErrorResponse("Missing ID"));
            }

            try
            {
                var contact = repository.GetContact(subdomainid.Value, id.Value);

                if (contact == null)
                {
                    return(SendJsonErrorResponse("Missing ID"));
                }

                var original = contact.ToModel(sessionid, subdomainid.Value);

                // no need to take into account whether an organisation is there because it will always be created
                contact.organisation1.address = address.Trim();
                if (citySelected.HasValue)
                {
                    var mcity = repository.GetCity(citySelected.Value);
                    contact.organisation1.MASTERcity = mcity;
                }
                else if (!string.IsNullOrEmpty(city))
                {
                    contact.organisation1.MASTERcity = repository.AddCity(city);
                }
                if (coPhone != null)
                {
                    contact.organisation1.phone = coPhone;
                }
                if (companyName != null)
                {
                    contact.organisation1.name = companyName;
                }
                if (country != null)
                {
                    contact.organisation1.country = country.ElementAtOrDefault(0);
                    contact.organisation1.state   = AddressHandler.GetState(country.ElementAtOrDefault(0), states_us.ElementAtOrDefault(0), states_canadian.ElementAtOrDefault(0), states_other.ElementAtOrDefault(0));
                }
                if (fax != null)
                {
                    contact.organisation1.fax = fax;
                }

                if (email != null)
                {
                    contact.email = email;
                }
                if (firstName != null)
                {
                    contact.firstName = firstName;
                }
                if (gender != null)
                {
                    contact.gender = gender;
                }
                if (lastName != null)
                {
                    contact.lastName = lastName;
                }
                if (phone != null)
                {
                    contact.phoneNumber = phone;
                }
                if (postcode != null)
                {
                    contact.organisation1.postcode = postcode;
                }

                // handle addresses
                var addressHandler = new AddressHandler(contact.organisation1, repository);
                addressHandler.SetShippingAndBillingAddresses(billing_first_name,
                                                              billing_last_name,
                                                              billing_company,
                                                              billing_address,
                                                              billing_city,
                                                              billing_citySelected,
                                                              billing_postcode,
                                                              billing_phone,
                                                              country.ElementAtOrDefault(1),
                                                              states_canadian.ElementAtOrDefault(1),
                                                              states_other.ElementAtOrDefault(1),
                                                              states_us.ElementAtOrDefault(1),
                                                              shipping_first_name,
                                                              shipping_last_name,
                                                              shipping_company,
                                                              shipping_address,
                                                              shipping_city,
                                                              shipping_citySelected,
                                                              shipping_postcode,
                                                              shipping_phone,
                                                              country.ElementAtOrDefault(2),
                                                              states_canadian.ElementAtOrDefault(2),
                                                              states_other.ElementAtOrDefault(2),
                                                              states_us.ElementAtOrDefault(2),
                                                              false);

                if (title != null)
                {
                    contact.title = title;
                }

                if (!string.IsNullOrEmpty(password))
                {
                    // password specified
                    contact.passwordHash = Crypto.Utility.ComputePasswordHash(email + password);
                }
                else
                {
                    // password removed
                    contact.passwordHash = null;
                }

                // list of fields that are allowed to be modified
                if (notes != null)
                {
                    contact.notes = notes;
                }

                // handle permissions
                if (permissions.HasValue)
                {
                    contact.permissions = permissions;
                }

                repository.AddActivity(sessionid.Value,
                                       new ActivityMessage(id.Value, sessionid,
                                                           ActivityMessageType.CONTACT_UPDATED,
                                                           new HtmlLink(contact.ToEmailName(true), id.Value).ToContactString()), subdomainid.Value);

                repository.Save();
#if LUCENE
                // update search index
                var indexer = new LuceneWorker(db, MASTERdomain.ToIdName());
                indexer.AddToIndex(LuceneIndexType.CONTACTS, contact);
#endif
                // get changed and store in database
                var changed  = contact.ToModel(sessionid, subdomainid.Value);
                var comparer = new CompareObject();
                var diff     = comparer.Compare(original, changed);
                if (diff.Count != 0)
                {
                    repository.AddChangeHistory(sessionid.Value, contact.id, ChangeHistoryType.CONTACT, diff);
                }
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }
            return(Json(id.ToJsonOKData()));
        }