Beispiel #1
0
        public virtual ActionResult ShoeDetails(string sku)
        {
            var viewModel = new ShoeDetailsViewModel();

            using (var context = new TTTEntities())
            {
                viewModel.ModelImage = context.lnkcustomizemodelimages.Where(a => a.SKU == sku).Single();
                viewModel.CustomizeModel = context.refcustomizemodels.Where(a => a.ID == viewModel.ModelImage.CustomizeModelID).Single();
            }

            viewModel.ShareUrl = string.Format("http://www.tote-to-toe.com/Customize/ShoeDetails?sku={0}", sku);
                

            string imgName = string.Format("{0}_{1}_{2}_{3}_{4}.jpg",
                                            viewModel.CustomizeModel.Style,
                                            viewModel.CustomizeModel.Type,
                                            viewModel.ModelImage.HeelHeight,
                                            viewModel.ModelImage.Colour,
                                            viewModel.ModelImage.Priority);
            ConstructRecentViewCookie(string.Format("Customize/ShoeColour/{0}", imgName),
                                        string.Format("/Customize/ShoeDetails?sku={0}", sku));

            return View(viewModel);
        }
Beispiel #2
0
        private void AddToWishList(ShoeDetailsViewModel viewModel)
        {
            var wishlistID = 0;

            using (var context = new TTTEntities())
            {
                using (var trans = new TransactionScope())
                {
                    var customerEmail = Util.SessionAccess.Email;
                    var wishlist = context.trnwishlists.Where(a => a.Email == customerEmail).SingleOrDefault();
                    if (wishlist == null)
                    {
                        wishlistID = context.trnwishlists.Add(new trnwishlist()
                        {
                            Active = true,
                            CreateDT = DateTime.Now,
                            Email = customerEmail
                        }).ID;

                        AddWishlistItem(wishlistID, viewModel.ModelImage.SKU, viewModel.Size, context);
                    }
                    else
                    {
                        wishlistID = wishlist.ID;

                        var wishlistItem = context.lnkwishlists.Where(a => a.SKU == viewModel.ModelImage.SKU &&
                                                                            a.Size == viewModel.Size &&
                                                                            a.WishlistID == wishlistID).SingleOrDefault();

                        if (wishlistItem == null)
                            AddWishlistItem(wishlistID, viewModel.ModelImage.SKU, viewModel.Size, context);
                        else
                        {
                            wishlistItem.Active = true;
                            wishlistItem.UpdateDT = DateTime.Now;
                        }
                    }

                    context.SaveChanges();
                    trans.Complete();
                }
            }
        }
Beispiel #3
0
        public virtual ActionResult ShoeDetails(ShoeDetailsViewModel viewModel, FormCollection collection)
        {
            try
            {
                if (collection["submit"].ToString() == "+ ADD TO BAG")
                {
                    #region Add to Cart

                    var salesOrder = new trnsalesorder();

                    using (var context = new TTTEntities())
                    {
                        var query = from customizeModelImage in context.lnkcustomizemodelimages
                                    join customizeModel in context.refcustomizemodels on customizeModelImage.CustomizeModelID equals customizeModel.ID
                                    select new { CustomizeModel = customizeModel, CustomizeModelImage = customizeModelImage };

                        var customizeModelDetails = query.Where(a => a.CustomizeModelImage.SKU == viewModel.ModelImage.SKU).Single();

                        var customerEmail = Util.SessionAccess == null ? "" : Util.SessionAccess.Email;


                        if (!string.IsNullOrEmpty(customerEmail)) // login customer
                        {
                            var openStatusID = Util.GetStatusID(Status.Open.ToString());

                            salesOrder = context.trnsalesorders.Where(a => a.Email == customerEmail && a.StatusID == openStatusID).SingleOrDefault();

                            using (var trans = new TransactionScope())
                            {
                                if (salesOrder == null)
                                {
                                    salesOrder = context.trnsalesorders.Add(new trnsalesorder()
                                    {
                                        StatusID = openStatusID,
                                        Email = customerEmail,
                                        SubTotal = customizeModelDetails.CustomizeModel.Price,
                                        GrandTotal = customizeModelDetails.CustomizeModel.Price,
                                        CreateDT = DateTime.Now
                                    });
                                    context.SaveChanges();

                                    AddSalesOrderItem(salesOrder.ID, viewModel.ModelImage.SKU, viewModel.Size, viewModel.CustomizeModel.Price, context);
                                }
                                else
                                {
                                    var soItem = context.lnksalesorders.Where(a => a.SalesOrderID == salesOrder.ID &&
                                                                                    a.Size == viewModel.Size &&
                                                                                    a.SKU == viewModel.ModelImage.SKU).SingleOrDefault();
                                    if (soItem == null)
                                    {
                                        salesOrder.GrandTotal += customizeModelDetails.CustomizeModel.Price;
                                        salesOrder.UpdateDT = DateTime.Now;

                                        AddSalesOrderItem(salesOrder.ID, viewModel.ModelImage.SKU, viewModel.Size, viewModel.CustomizeModel.Price, context);
                                    }
                                    else
                                    {
                                        soItem.Active = true;
                                        soItem.UpdateDT = DateTime.Now;
                                    }
                                }

                                context.SaveChanges();
                                trans.Complete();
                            }
                        }
                        else // Anonymous user
                        {
                            ConstructShoppingBagCookie();

                            var soItem = context.lnksalesorders.Where(a => a.SalesOrderID == null &&
                                                                            a.Size == viewModel.Size && a.SKU == viewModel.ModelImage.SKU &&
                                                                            a.CookieID == cookieID).SingleOrDefault();
                            if (soItem == null)
                            {
                                AddSalesOrderItem(null, viewModel.ModelImage.SKU, viewModel.Size, viewModel.CustomizeModel.Price, context);
                            }
                            else
                            {
                                soItem.Active = true;
                                soItem.UpdateDT = DateTime.Now;
                            }

                            context.SaveChanges();
                        }
                    }

                    #endregion
                }
                else if (collection["submit"].ToString() == "+ ADD TO WISH LIST")
                {
                    #region Add to Wishlist

                    if (!Request.IsAuthenticated)
                    {
                        return RedirectToAction(MVC.SignIn.Index(Url.Action("ShoeDetails", new { sku = viewModel.ModelImage.SKU })));
                    }

                    AddToWishList(viewModel);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return RedirectToAction("ShoeDetails", new { sku = viewModel.ModelImage.SKU });
        }