public ActionResult StoreNewItem(StoreItemDisplayModel storeItem)
        {
            var sg = new StoreGateway();
            try
            {
                StoreItemDisplay display = new StoreItemDisplay();
                display.CanPickUpLocally = storeItem.CanPickUpLocally;
                display.ArticleNumber = storeItem.ArticleNumber;
                display.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                display.Currency = storeItem.Currency;
                display.Description = storeItem.Description;
                display.InternalId = storeItem.InternalId;
                display.Note = storeItem.HtmlNote;
                display.Price = storeItem.Price;
                display.PrivateManagerId = storeItem.PrivateManagerId;
                display.QuantityInStock = storeItem.QuantityInStock;
                display.StoreItemId = storeItem.StoreItemId;
                display.Merchant.Name = storeItem.StoreName;
                display.Weight = storeItem.Weight;
                display.MerchantId = storeItem.MerchantId;
                display.Name = storeItem.Name;
                display.Shipping = storeItem.Shipping;
                display.HasExtraLarge = storeItem.HasExtraLarge;
                display.HasExtraSmall = storeItem.HasExtraSmall;
                display.HasLarge = storeItem.HasLarge;
                display.HasMedium = storeItem.HasMedium;
                display.HasSmall = storeItem.HasSmall;
                display.HasXXLarge = storeItem.HasXXLarge;
                display.ItemTypeEnum = storeItem.ItemTypeEnum;
                display.ItemType = storeItem.ItemType;
                display.ColorTempSelected = storeItem.ColorsSelected;

                display = sg.CreateNewStoreItem(display);
                if (display.StoreItemId > 0)
                    return Redirect(Url.Content("~/store/item/edit/" + display.StoreItemId + "/" + display.PrivateManagerId.ToString().Replace("-", "") + "/" + display.MerchantId.ToString().Replace("-", "")));

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            //if the item didn't actually get created.
            var store = sg.GetStoreForManager(storeItem.MerchantId, storeItem.PrivateManagerId, false);
            storeItem.InternalId = store.InternalReference;
            storeItem.MerchantId = store.MerchantId;
            storeItem.PrivateManagerId = store.PrivateManagerId;
            return View(storeItem);
        }
Exemplo n.º 2
0
        public Classes.Store GetStore(Guid? merchantId, bool isRdn = false)
        {
            var store = new Classes.Store();
            try
            {
                if (!merchantId.HasValue && !isRdn)
                    throw new Exception("Invalid merchant id. (CreateNewShoppingCart in StoreGateway");

                var mc = new ManagementContext();
                Merchant merchant = null;
                if (merchantId.HasValue) // ToDo: When Store is updated, updated the references here to include more tables
                    merchant = mc.Merchants.Include("Items").FirstOrDefault(x => x.MerchantId.Equals(merchantId.Value));
                else
                    merchant = mc.Merchants.Include("Items").FirstOrDefault(x => x.IsRDNation.Equals(true));
                if (merchant == null)
                    return null;

                store.Name = merchant.ShopName;
                store.MerchantId = merchant.MerchantId;
                store.InternalId = merchant.InternalReference;
                foreach (var storeItem in merchant.Items)
                {
                    var item = new Classes.StoreItemDisplay();
                    item.ArticleNumber = storeItem.ArticleNumber;
                    item.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                    if (storeItem.Merchant.CurrencyRate == null)
                    {
                        item.Currency = "USD";
                        item.CurrencyCost = 1;
                    }
                    else
                    {
                        item.Currency = storeItem.Merchant.CurrencyRate.CurrencyAbbrName;
                        item.CurrencyCost = storeItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                    }
                    item.Description = storeItem.Description;
                    item.Name = storeItem.Name;
                    item.Price = storeItem.Price;
                    item.QuantityInStock = storeItem.QuantityInStock;
                    item.StoreItemId = storeItem.StoreItemId;
                    item.Weight = storeItem.Weight;
                    item.Note = storeItem.Note;
                    item.IsPublished = storeItem.IsPublished;
                    item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), storeItem.ItemTypeEnum.ToString());
                    if (item.ItemType == StoreItemTypeEnum.Shirt)
                    {
                        item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), storeItem.SizesEnum.ToString());
                        item.ItemSizeEnum = storeItem.SizesEnum;
                    }
                    store.StoreItems.Add(item);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;
        }
Exemplo n.º 3
0
        public StoreItemDisplay CreateNewStoreItem(StoreItemDisplay storeItem)
        {
            try
            {
                var dc = new ManagementContext();

                var merchant = dc.Merchants.Where(x => x.InternalReference == storeItem.InternalId && x.MerchantId == storeItem.MerchantId && x.PrivateManagerId == storeItem.PrivateManagerId).FirstOrDefault();
                if (merchant != null)
                {
                    DataModels.Store.StoreItem si = new DataModels.Store.StoreItem();
                    si.ArticleNumber = storeItem.ArticleNumber;
                    si.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                    si.CanPickUpLocally = storeItem.CanPickUpLocally;
                    si.Description = storeItem.Description;
                    si.ExemptFromShipping = false;
                    si.Merchant = merchant;
                    si.Name = storeItem.Name;
                    si.Note = storeItem.Note;
                    si.Price = storeItem.Price;
                    si.QuantityInStock = storeItem.QuantityInStock;
                    si.VisibleOnRdn = false;
                    si.Weight = storeItem.Weight;
                    si.ShippingCosts = storeItem.Shipping;
                    si.IsPublished = false;
                    //si.ItemTypeEnum = storeItem.ItemTypeEnum;
                    si.ItemTypeEnum = (int)storeItem.ItemType;
                    si.Category = dc.StoreItemCategories.Where(x => x.StoreItemCategoryId == si.ItemTypeEnum).FirstOrDefault();
                    if (storeItem.HasExtraLarge)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.X_Large);
                    if (storeItem.HasExtraSmall)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.X_Small);
                    if (storeItem.HasLarge)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.Large);
                    if (storeItem.HasMedium)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.Medium);
                    if (storeItem.HasSmall)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.Small);
                    if (storeItem.HasXXLarge)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.XX_Large);

                    if (!String.IsNullOrEmpty(storeItem.ColorTempSelected))
                    {
                        foreach (string color in storeItem.ColorTempSelected.Split(';'))
                        {
                            if (color.Length > 3)
                            {
                                Color c = ColorTranslator.FromHtml(color);
                                int arb = c.ToArgb();
                                var colorDb = dc.Colors.Where(x => x.ColorIdCSharp == arb).FirstOrDefault();
                                if (colorDb != null)
                                {
                                    DataModels.Store.StoreItemColor cItem = new DataModels.Store.StoreItemColor();
                                    cItem.Color = colorDb;
                                    cItem.StoreItem = si;
                                    si.Colors.Add(cItem);
                                }
                            }
                        }
                    }

                    dc.StoreItems.Add(si);
                    dc.SaveChanges();

                    storeItem.StoreItemId = si.StoreItemId;
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return storeItem;
        }
Exemplo n.º 4
0
        public Classes.StoreItemDisplay GetStoreItemManager(Guid merchantId, Guid privateManagerId, int itemId)
        {
            var item = new Classes.StoreItemDisplay();
            try
            {
                var mc = new ManagementContext();
                var storeItem = mc.StoreItems.Include("Colors").Include("Colors.Color").Include("Photos").Where(x => x.StoreItemId == itemId).Where(x => x.Merchant.MerchantId == merchantId).Where(x => x.Merchant.PrivateManagerId == privateManagerId).FirstOrDefault();
                if (storeItem == null)
                    return item;

                item.CanPickUpLocally = storeItem.CanPickUpLocally;
                item.Name = storeItem.Merchant.ShopName;
                item.MerchantId = storeItem.Merchant.MerchantId;
                item.InternalId = storeItem.Merchant.InternalReference;
                item.PrivateManagerId = storeItem.Merchant.PrivateManagerId;
                item.ArticleNumber = storeItem.ArticleNumber;
                item.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                if (storeItem.Merchant.CurrencyRate == null)
                {
                    item.Currency = "USD";
                    item.CurrencyCost = 1;
                }
                else
                {
                    item.Currency = storeItem.Merchant.CurrencyRate.CurrencyAbbrName;
                    item.CurrencyCost = storeItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                }
                item.Description = storeItem.Description;
                item.Name = storeItem.Name;
                item.Price = storeItem.Price;
                item.QuantityInStock = storeItem.QuantityInStock;
                item.StoreItemId = storeItem.StoreItemId;
                item.Weight = storeItem.Weight;
                item.Note = storeItem.Note;
                item.Shipping = storeItem.ShippingCosts;
                item.ShippingAdditional = storeItem.ShippingCostsAdditional;
                item.IsPublished = storeItem.IsPublished;
                item.ItemTypeEnum = storeItem.ItemTypeEnum;
                item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), storeItem.ItemTypeEnum.ToString());
                if (item.ItemType == StoreItemTypeEnum.Shirt)
                {
                    item.ItemSizeEnum = storeItem.SizesEnum;
                    item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), storeItem.SizesEnum.ToString());
                }
                DisplayStoreItemColors(storeItem, item);

                foreach (var photo in storeItem.Photos)
                {
                    PhotoItem p = new PhotoItem(photo.ItemPhotoId, photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, photo.AlternativeText);
                    item.Photos.Add(p);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return item;
        }
Exemplo n.º 5
0
        public StoreItemDisplay UpdateStoreItem(StoreItemDisplay storeItem)
        {
            try
            {
                var dc = new ManagementContext();
                var si = dc.StoreItems.Include("Colors").Include("Colors.Color").Where(x => x.StoreItemId == storeItem.StoreItemId && x.Merchant.InternalReference == storeItem.InternalId && x.Merchant.MerchantId == storeItem.MerchantId && x.Merchant.PrivateManagerId == storeItem.PrivateManagerId).FirstOrDefault();

                if (si != null)
                {
                    si.CanPickUpLocally = storeItem.CanPickUpLocally;
                    si.Merchant = si.Merchant;
                    si.ArticleNumber = storeItem.ArticleNumber;
                    si.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                    si.Description = storeItem.Description;
                    si.ExemptFromShipping = false;
                    si.Name = storeItem.Name;
                    si.Note = storeItem.Note;
                    si.Price = storeItem.Price;
                    si.QuantityInStock = storeItem.QuantityInStock;
                    si.VisibleOnRdn = false;
                    si.Weight = storeItem.Weight;
                    si.ShippingCosts = storeItem.Shipping;
                    si.ShippingCostsAdditional = storeItem.ShippingAdditional;
                    si.Category = dc.StoreItemCategories.Where(x => x.StoreItemCategoryId == storeItem.ItemTypeEnum).FirstOrDefault();
                    //they are just now publishing the item.
                    if (!si.IsPublished && storeItem.IsPublished)
                    {
                        AddRDNationFeeToMerchant(si);
                        si.LastPublished = DateTime.UtcNow;
                    }
                    si.IsPublished = storeItem.IsPublished;
                    si.ItemTypeEnum = storeItem.ItemTypeEnum;
                    si.SizesEnum = 0;
                    if (storeItem.HasExtraLarge)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.X_Large);
                    if (storeItem.HasExtraSmall)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.X_Small);
                    if (storeItem.HasLarge)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.Large);
                    if (storeItem.HasMedium)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.Medium);
                    if (storeItem.HasSmall)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.Small);
                    if (storeItem.HasXXLarge)
                        si.SizesEnum += Convert.ToInt32(StoreItemShirtSizesEnum.XX_Large);

                    //removes any colors not being used anymore.
                    List<int> colors = new List<int>();
                    if (!String.IsNullOrEmpty(storeItem.ColorTempSelected))
                    {
                        foreach (string color in storeItem.ColorTempSelected.Split(';'))
                        {
                            if (color.Length > 3)
                            {
                                Color c = ColorTranslator.FromHtml(color);
                                int arb = c.ToArgb();
                                colors.Add(arb);
                            }
                        }
                    }
                    var colorsNoLongerIn = si.Colors.Where(x => !colors.Contains(x.Color.ColorIdCSharp)).ToList();
                    foreach (var removeColor in colorsNoLongerIn)
                    {
                        si.Colors.Remove(removeColor);
                    }
                    //adds colors that are not currently added to the storeitem.
                    if (!String.IsNullOrEmpty(storeItem.ColorTempSelected))
                    {
                        foreach (string color in storeItem.ColorTempSelected.Split(';'))
                        {
                            if (color.Length > 3)
                            {
                                Color c = ColorTranslator.FromHtml(color);
                                int arb = c.ToArgb();
                                if (si.Colors.Where(x => x.Color.ColorIdCSharp == arb).FirstOrDefault() == null)
                                {
                                    var colorDb = dc.Colors.Where(x => x.ColorIdCSharp == arb).FirstOrDefault();
                                    if (colorDb != null)
                                    {
                                        DataModels.Store.StoreItemColor cItem = new DataModels.Store.StoreItemColor();
                                        cItem.Color = colorDb;
                                        cItem.StoreItem = si;
                                        si.Colors.Add(cItem);
                                    }
                                }
                            }
                        }
                    }



                    int ch = dc.SaveChanges();

                    storeItem.StoreItemId = si.StoreItemId;
                }
            }
            catch (System.Exception e)
            {
                var ex = e;
                ErrorDatabaseManager.AddException(ex, ex.GetType());
            }
            return storeItem;
        }
Exemplo n.º 6
0
        public StoreShoppingCart GetShoppingCart(Guid cartId)
        {
            var output = new StoreShoppingCart();
            try
            {
                var mc = new ManagementContext();
                DateTime now = DateTime.Now;
                var cart = mc.ShoppingCarts.Include("Items").Include("Items.StoreItem").Include("Items.StoreItem.Colors").Include("Items.StoreItem.Colors.Color").Include("Items.StoreItem.Merchant").FirstOrDefault(x => x.ShoppingCartId.Equals(cartId));
                if (cart == null) return output;

                output.ShoppingCartId = cart.ShoppingCartId;
                output.Ip = cart.Ip;

                foreach (var shoppingCartItem in cart.Items)
                {
                    output.ItemsCount += 1;
                    var item = new StoreItemDisplay();
                    item.Merchant.MerchantId = shoppingCartItem.StoreItem.Merchant.MerchantId;
                    item.Merchant.Name = shoppingCartItem.StoreItem.Merchant.ShopName;
                    item.Merchant.TaxRate = shoppingCartItem.StoreItem.Merchant.TaxRate;
                    if (shoppingCartItem.StoreItem.Merchant.CurrencyRate == null)
                    {
                        item.Merchant.Currency = "USD";
                        item.Merchant.CurrencyCost = 1;
                    }
                    else
                    {
                        item.Merchant.Currency = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyAbbrName;
                        item.Merchant.CurrencyCost = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                    }
                    item.Name = shoppingCartItem.StoreItem.Name;
                    item.BasePrice = shoppingCartItem.StoreItem.Price;
                    item.Price = (shoppingCartItem.StoreItem.Price * shoppingCartItem.Quantity);
                    var color = DisplayStoreItemColor(shoppingCartItem.StoreItem.Colors.Where(x => x.Color.ColorIdCSharp == shoppingCartItem.Color).FirstOrDefault());
                    if (color != null)
                    {
                        item.Colors.Add(color);
                        item.ColorAGB = color.CSharpColor;
                        item.ColorHex = color.HexColor;
                    }
                    item.QuantityOrdered = shoppingCartItem.Quantity;
                    item.Weight = (shoppingCartItem.StoreItem.Weight * shoppingCartItem.Quantity);
                    item.ShoppingCartItemId = shoppingCartItem.ShoppingCartItemId;
                    item.ArticleNumber = shoppingCartItem.StoreItem.ArticleNumber;
                    if (shoppingCartItem.StoreItem.Merchant.CurrencyRate == null)
                    {
                        item.Currency = "USD";
                        item.CurrencyCost = 1;
                    }
                    else
                    {
                        item.Currency = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyAbbrName;
                        item.CurrencyCost = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                    }
                    item.Description = shoppingCartItem.StoreItem.Description;
                    item.WillPickUpLocally = shoppingCartItem.WillPickUpLocally;
                    if (!shoppingCartItem.WillPickUpLocally)
                    {
                        item.Shipping = shoppingCartItem.StoreItem.ShippingCosts;
                        //if there are more than one of the same items being shipped, then we add on the additional fees.
                        if (shoppingCartItem.Quantity > 1)
                            item.Shipping += shoppingCartItem.StoreItem.ShippingCostsAdditional * (shoppingCartItem.Quantity - 1);
                    }
                    else
                        item.Shipping = 0;
                    item.CanRunOutOfStock = shoppingCartItem.StoreItem.CanRunOutOfStock;
                    item.StoreItemId = shoppingCartItem.StoreItem.StoreItemId;
                    item.Note = shoppingCartItem.StoreItem.Note;
                    item.BaseTaxOnItem = Math.Round((item.BasePrice * Convert.ToDecimal(shoppingCartItem.StoreItem.Merchant.TaxRate)), 2);
                    item.TotalTaxOnItem = (item.BaseTaxOnItem * shoppingCartItem.Quantity);
                    item.PriceInclTax = Math.Round((item.Price + item.TotalTaxOnItem), 2);
                    item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), shoppingCartItem.StoreItem.ItemTypeEnum.ToString());
                    if (item.ItemType == StoreItemTypeEnum.Shirt)
                    {
                        item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), shoppingCartItem.Size.ToString());
                        item.ItemSizeEnum = shoppingCartItem.Size;
                    }
                    foreach (var photo in shoppingCartItem.StoreItem.Photos)
                    {
                        PhotoItem p = new PhotoItem(photo.ItemPhotoId, photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, photo.AlternativeText);
                        item.Photos.Add(p);
                    }
                    var store = output.Stores.Where(x => x.MerchantId == item.Merchant.MerchantId).FirstOrDefault();
                    if (store != null)
                    {
                        store.TotalPrice += item.Price;
                        store.TotalShipping += item.Shipping;
                        store.TotalAfterShipping += item.Price + item.Shipping;
                        store.StoreItems.Add(item);
                    }
                    else
                    {
                        Store.Classes.Store s = new Classes.Store();
                        s.MerchantId = item.Merchant.MerchantId;
                        s.Currency = item.Merchant.Currency;
                        s.StripePublishableKey = item.Merchant.StripePublishableKey;
                        s.Name = item.Merchant.Name;
                        s.TotalPrice = item.Price;
                        s.TotalShipping = item.Shipping;
                        s.TotalAfterShipping = item.Price + item.Shipping;
                        s.StoreItems.Add(item);
                        output.Stores.Add(s);
                    }
                }
                cart.Expires = DateTime.Now.AddDays(1);
                mc.SaveChanges();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return output;
        }