예제 #1
0
        public ActionResult AddToCartOfProductFreeTrial(string Id, string CateID)
        {
            OurProductFactory _factory         = new OurProductFactory();
            YourCartFactory   _yourcartFactory = new YourCartFactory();

            try
            {
                // get detail product by product id
                PackageDetailViewModels model = new PackageDetailViewModels();

                // Set info for breadcrumb if item is product
                ViewBag.Title        = "";
                ViewBag.CategoryID   = "";
                ViewBag.CategoryName = "";

                var ListPackages = _factory.GetListData(CurrentUser.UserId, null, 0, null, null, Id);
                if (ListPackages != null && ListPackages.Any())
                {
                    model.PackageDetail          = ListPackages.FirstOrDefault();
                    model.PackageDetail.CusId    = CurrentUser.UserId;
                    model.PackageDetail.Quantity = 1;
                    if (model.PackageDetail.IsUnlimitedAmountOfUnit)
                    {
                        model.PackageDetail.AmountOfUnit = -1;
                    }

                    if (model.PackageDetail.IsUnlimitedNumberOfAccount)
                    {
                        model.PackageDetail.NumberOfAccount = -1;
                    }

                    if (model.PackageDetail.IsUnlimitedIncludeStore)
                    {
                        model.PackageDetail.NumOfStore   = -1;
                        model.PackageDetail.IncludeStore = -1;
                    }
                    else
                    {
                        model.PackageDetail.NumOfStore = model.PackageDetail.IncludeStore;
                    }

                    if (model.PackageDetail.ImageURL == null || model.PackageDetail.ImageURL.Equals(""))
                    {
                        model.PackageDetail.ImageURL = _ImgDummyPackage;
                    }

                    if (model.PackageDetail.ListPrice != null && model.PackageDetail.ListPrice.Any())
                    {
                        model.PackageDetail.Period     = 30;
                        model.PackageDetail.PeriodType = (int)Commons.EPeriodType.Day;
                    }

                    // If item is package
                    if (model.PackageDetail.ProductType == (byte)Commons.EProductType.Package)
                    {
                        ViewBag.Title = "Package - " + model.PackageDetail.Name;

                        //=======Get List Product Child
                        if (model.PackageDetail.ListProductChild != null && model.PackageDetail.ListProductChild.Any())
                        {
                            //update bug of Long by Trongntn 22-11-2017
                            model.PackageDetail.ListProductChild = model.PackageDetail.ListProductChild.Where(x => x.ProductType == (byte)Commons.EProductType.Product).ToList();

                            model.PackageDetail.ListProductChild.ForEach(xx =>
                            {
                                // Get list cate product of package
                                if (xx.ProductType == (byte)Commons.EProductType.Product)
                                {
                                    model.ListApplyAdditionProduct.Add(new ProductApplyAdditionPackage
                                    {
                                        ProductName   = xx.Name,
                                        ProductId     = xx.ID,
                                        ProductCateId = xx.ListCategory.Select(s => s.CategoryID).FirstOrDefault().ToString()
                                    });
                                }
                            });
                        }

                        // If item is package from list recommend in Product list
                        if (!string.IsNullOrEmpty(CateID))
                        {
                            var listCate = ((List <CategoryDetailModels>)Session["ListItemCategory"]);
                            if (listCate != null)
                            {
                                var CateDetail = listCate.Where(x => x.ID.Equals(CateID)).FirstOrDefault();
                                // Set info for breadcrumb if item is product
                                ViewBag.CategoryID   = CateDetail == null ? "" : CateDetail.ID;
                                ViewBag.CategoryName = CateDetail == null ? "" : CateDetail.Name;
                            }
                        }
                    }
                    // If item is product
                    else if (model.PackageDetail.ProductType == (byte)Commons.EProductType.Product)
                    {
                        ViewBag.Title = "Product - " + model.PackageDetail.Name;

                        if (model.PackageDetail.ListCategory != null && model.PackageDetail.ListCategory.Any())
                        {
                            var infoCategory = model.PackageDetail.ListCategory.FirstOrDefault();
                            model.ListApplyAdditionProduct.Add(new ProductApplyAdditionPackage
                            {
                                ProductName   = model.PackageDetail.Name,
                                ProductId     = model.PackageDetail.ID,
                                ProductCateId = infoCategory.CategoryID
                            });

                            // Set info for breadcrumb if item is product
                            ViewBag.CategoryID   = infoCategory.CategoryID;
                            ViewBag.CategoryName = infoCategory.CategoryName;
                        }
                    }


                    //==========Get List Addition Type
                    //List<SelectListItem> ListAdditionType = new List<SelectListItem>();
                    //ListAdditionType = GetListAdditionType();
                    //ViewBag.ListAdditionType = ListAdditionType;

                    model.PackageDetail.CurrencySymbol = CurrencySymbol;
                    model.PackageDetail.Price          = 0;
                    model.PackageDetail.DiscountValue  = 0;

                    if (model.PackageDetail.ListComposite != null && model.PackageDetail.ListComposite.Any())
                    {
                        //Product
                        model.PackageDetail.ListProductOnPackage = model.PackageDetail.ListComposite
                                                                   .Where(ww => ww.ProductType == (byte)Commons.EProductType.Product)
                                                                   .OrderBy(ww => ww.Sequence).ThenBy(ww => ww.ProductName).ToList();
                        model.PackageDetail.ListProductOnPackage.ForEach(x =>
                        {
                            if (x.Quantity == -1)
                            {
                                x.ProductName = x.ProductName + " (For unlimited devices)";
                            }
                            else
                            {
                                x.ProductName = x.ProductName + " (For " + x.Quantity + " device" + (x.Quantity > 1 ? "s" : "") + ")";
                            }
                        });

                        //Addition
                        model.PackageDetail.ListComposite = model.PackageDetail.ListComposite
                                                            .Where(ww => ww.ProductType != (byte)Commons.EProductType.Product)
                                                            .OrderBy(ww => ww.Sequence).ThenBy(ww => ww.ProductName).ToList();
                    }
                }

                // add to cart
                AddItemToOrderModels modelAddItems = new AddItemToOrderModels();
                modelAddItems.CusID   = CurrentUser.UserId;
                modelAddItems.OrderID = ORDERID;
                List <Item> ListItems = new List <Item>();
                //===============
                Item package = new Item();
                package.ID           = "";
                package.ProductID    = model.PackageDetail.ID;
                package.ProductName  = model.PackageDetail.Name;
                package.ProductType  = model.PackageDetail.ProductType;
                package.AdditionType = model.PackageDetail.AdditionType;
                package.ImageURL     = model.PackageDetail.ImageURL;
                package.Period       = model.PackageDetail.Period;
                package.PeriodType   = model.PackageDetail.PeriodType;
                package.Quantity     = model.PackageDetail.Quantity;
                package.Price        = model.PackageDetail.Price;

                package.NumOfStore   = model.PackageDetail.NumOfStore;
                package.NumOfAccount = model.PackageDetail.NumberOfAccount;
                package.AmountOfUnit = model.PackageDetail.AmountOfUnit;

                package.PromotionID      = model.PackageDetail.PromotionID;
                package.PromotionName    = model.PackageDetail.PromotionName;
                package.PromotionAmount  = model.PackageDetail.PromotionAmount;
                package.IsApplyPromotion = model.PackageDetail.IsApplyPromotion;

                package.DiscountID     = model.PackageDetail.DiscountID;
                package.DiscountName   = model.PackageDetail.DiscountName;
                package.DiscountAmount = model.PackageDetail.DiscountAmount;
                package.DiscountValue  = model.PackageDetail.DiscountValue;
                package.DiscountType   = model.PackageDetail.DiscountType;

                package.Description = model.PackageDetail.Description;
                package.ItemGroup   = model.PackageDetail.ItemGroup;
                package.IsDelete    = model.PackageDetail.IsDelete;

                package.ListItem = new List <Item>();
                foreach (var item in model.ListAdditionBuy.Where(w => w.IsDelete != true).ToList())
                {
                    package.ListItem.Add(new Item
                    {
                        ID             = "",
                        ProductID      = item.ID,
                        ParentAddition = item.ApplyProductId,
                        ProductName    = item.Name,
                        ProductType    = (byte)Commons.EProductType.Addition,
                        AdditionType   = item.AdditionType,
                        Quantity       = item.Quantity,
                        Period         = item.Period,
                        PeriodType     = item.PeriodType,
                        Price          = item.Price,
                        IsDelete       = item.IsDelete,
                        AmountOfUnit   = item.AmountOfUnit,
                        ItemGroup      = (byte)Commons.EItemGroup.Addition
                    });
                }
                package.ListStoreApply    = new List <ApplyStore>();
                package.ListAdditionApply = new List <AdditionApply>();

                package.ListFunction = new List <ItemFunction>();
                // Get all composite (products + additions)
                if (model.PackageDetail.ListComposite == null)
                {
                    model.PackageDetail.ListComposite = new List <ProductCompositeModels>();
                }
                if (model.PackageDetail.ListProductOnPackage != null && model.PackageDetail.ListProductOnPackage.Any())
                {
                    model.PackageDetail.ListComposite.AddRange(model.PackageDetail.ListProductOnPackage);
                }

                package.ListComposite = model.PackageDetail.ListComposite;
                //=========
                ListItems.Add(package);
                modelAddItems.ListItems = ListItems;
                modelAddItems.IsFree    = true;
                //====================
                string            msg         = "";
                bool              success     = false;
                OrderDetailModels OrderDetail = _yourcartFactory.AddItems(modelAddItems, ref success, ref msg);
                if (success)
                {
                    ORDERID = OrderDetail.ID;
                    if (OrderDetail.ListItems != null && OrderDetail.ListItems.Count > 0)
                    {
                        OrderDetail.TotalQuantity = (int)OrderDetail.ListItems.Sum(x => x.Quantity);
                    }
                    return(Json(OrderDetail, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    if (!string.IsNullOrEmpty(msg))
                    {
                        if (msg.Equals("Payment is pending!") || msg.Equals("The receipt has been paid in full!"))
                        {
                            var Cookie = Request.Cookies["csc-order-v2"];
                            if (Cookie != null)
                            {
                                var Order     = Cookie.Value;
                                var strOrder  = Server.UrlDecode(Order);
                                var ListOrder = JsonConvert.DeserializeObject <List <CookieOrder> >(strOrder);
                                if (ListOrder != null && ListOrder.Any())
                                {
                                    var temp = ListOrder.FirstOrDefault(x => x.OrderId.Equals(ORDERID));
                                    if (temp != null)
                                    {
                                        ListOrder.Remove(temp);
                                        Cookie.Value = null;
                                        Response.Cookies.Add(Cookie);
                                        var strListOrder = JsonConvert.SerializeObject(ListOrder);
                                        Cookie.Value = strListOrder;
                                        Response.Cookies.Add(Cookie);
                                    }
                                }
                            }
                            ORDERID = "";
                            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, msg));
                        }
                    }
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, msg));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("AddToCartOfProduct: ", ex);
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message));
            }
        }
예제 #2
0
        public ActionResult Index(AccountLoginRequest model, string returnUrl = null)
        {
            try
            {
                if (Session["UserClientSite"] != null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                if (ModelState.IsValid)
                {
                    UserFactory factoy = new UserFactory();

                    ResponseAccountLogin User = factoy.LoginClient(model.Email, model.Password);
                    bool isValid = (User != null && !string.IsNullOrEmpty(User.ID));
                    if (isValid)
                    {
                        UserSession userSession = new UserSession();
                        userSession.Email           = User.Email;
                        userSession.UserName        = User.Name;
                        userSession.UserId          = User.ID;
                        userSession.IsAuthenticated = true;
                        userSession.ImageUrl        = User.ImageURL;
                        userSession.IsReseller      = User.IsReseller;
                        userSession.CurrencySymbol  = User.CurrencySymbol;
                        // Update 04/09/2018
                        userSession.ListProduct = User.ListProduct;
                        //currency
                        //userSession.CurrencySymbol = GetCurrency();
                        //Commons.CurrencySymbol = userSession.CurrencySymbol;
                        if (!string.IsNullOrEmpty(User.OrderID))
                        {
                            var Cookie = Request.Cookies["csc-order-v2"];
                            if (Cookie != null)
                            {
                                var Order     = Cookie.Value;
                                var strOrder  = Server.UrlDecode(Order);
                                var ListOrder = JsonConvert.DeserializeObject <List <CookieOrder> >(strOrder);
                                if (ListOrder != null && ListOrder.Any())
                                {
                                    /* Check merge order anynomus */
                                    var itemMerge = ListOrder.FirstOrDefault(x => !string.IsNullOrEmpty(x.OrderId) && string.IsNullOrEmpty(x.CusId));
                                    if (itemMerge != null && !string.IsNullOrEmpty(User.OrderID))
                                    {
                                        YourCartFactory _factoryYC = null;
                                        _factoryYC = new YourCartFactory();
                                        var msg    = string.Empty;
                                        var result = _factoryYC.OrderMerge(itemMerge.OrderId, User.OrderID, ref msg);
                                        ListOrder.Remove(itemMerge);
                                        Cookie.Value = null;
                                        Response.Cookies.Add(Cookie);
                                        var strListOrderMerge = JsonConvert.SerializeObject(ListOrder);
                                        Cookie.Value = strListOrderMerge;
                                        Response.Cookies.Add(Cookie);
                                    }

                                    var temp = ListOrder.FirstOrDefault(x => x.OrderId.Equals(User.OrderID));
                                    if (temp != null)
                                    {
                                        var _OrderId = temp.OrderId;
                                        if (Session["ORDERID"] != null && string.IsNullOrEmpty(Session["ORDERID"].ToString()))
                                        {
                                            Session["ORDERID"] = _OrderId;
                                        }
                                        YourCartFactory _factory      = new YourCartFactory();
                                        var             modelYourCart = _factory.GetOrderDetail(_OrderId);
                                        if (modelYourCart.ListItems != null && modelYourCart.ListItems.Count > 0)
                                        {
                                            modelYourCart.TotalQuantity = (int)modelYourCart.ListItems.Sum(x => x.Quantity);
                                            Session["IsFree"]           = modelYourCart.IsFree;
                                        }

                                        temp.Qty = modelYourCart.TotalQuantity;
                                    }
                                    else
                                    {
                                        //check cusid
                                        var orderTmp = ListOrder.Where(ww => ww.CusId == User.ID).FirstOrDefault();
                                        if (orderTmp != null)
                                        {
                                            orderTmp.OrderId = User.OrderID;
                                            orderTmp.Qty     = User.NumOfItems;
                                        }
                                        else
                                        {
                                            var _OrderId = User.OrderID;
                                            if (Session["ORDERID"] != null && string.IsNullOrEmpty(Session["ORDERID"].ToString()))
                                            {
                                                Session["ORDERID"] = _OrderId;
                                            }
                                            YourCartFactory _factory      = new YourCartFactory();
                                            var             modelYourCart = _factory.GetOrderDetail(_OrderId);
                                            if (modelYourCart.ListItems != null && modelYourCart.ListItems.Count > 0)
                                            {
                                                modelYourCart.TotalQuantity = (int)modelYourCart.ListItems.Sum(x => x.Quantity);
                                                Session["IsFree"]           = modelYourCart.IsFree;
                                            }

                                            var newtemp = new CookieOrder
                                            {
                                                CusId   = User.ID,
                                                OrderId = User.OrderID,
                                                Qty     = modelYourCart.TotalQuantity
                                            };
                                            ListOrder.Add(newtemp);
                                        }
                                    }

                                    //ListOrder.ForEach(x => {
                                    //    x.Qty = x.OrderId == User.OrderID ? temp.Qty : x.Qty;
                                    //});
                                }
                                else
                                {
                                    YourCartFactory _factory      = new YourCartFactory();
                                    var             modelYourCart = _factory.GetOrderDetail(User.OrderID);
                                    if (modelYourCart.ListItems != null && modelYourCart.ListItems.Count > 0)
                                    {
                                        modelYourCart.TotalQuantity = (int)modelYourCart.ListItems.Sum(x => x.Quantity);
                                        Session["IsFree"]           = modelYourCart.IsFree;
                                    }
                                    ListOrder = new List <CookieOrder>()
                                    {
                                        new CookieOrder
                                        {
                                            CusId   = User.ID,
                                            OrderId = User.OrderID,
                                            Qty     = modelYourCart.TotalQuantity
                                        }
                                    };
                                }
                                //Cookie.Expires = DateTime.Now.AddDays(-1d);
                                // Reset value cookie
                                Cookie.Value = null;
                                Response.Cookies.Add(Cookie);
                                var strListOrder = JsonConvert.SerializeObject(ListOrder);
                                Cookie.Value = strListOrder;
                                Response.Cookies.Add(Cookie);
                            }
                            else
                            {
                                YourCartFactory _factory      = new YourCartFactory();
                                var             modelYourCart = _factory.GetOrderDetail(User.OrderID);
                                if (modelYourCart.ListItems != null && modelYourCart.ListItems.Count > 0)
                                {
                                    modelYourCart.TotalQuantity = (int)modelYourCart.ListItems.Sum(x => x.Quantity);
                                    Session["IsFree"]           = modelYourCart.IsFree;
                                }
                                var ListOrder = new List <CookieOrder>()
                                {
                                    new CookieOrder
                                    {
                                        CusId   = User.ID,
                                        OrderId = User.OrderID,
                                        Qty     = modelYourCart.TotalQuantity
                                    }
                                };
                                var strListOrder = JsonConvert.SerializeObject(ListOrder);
                                Cookie       = new HttpCookie("csc-order-v2");
                                Cookie.Value = strListOrder;
                                Response.Cookies.Add(Cookie);
                            }
                        }
                        else
                        {
                            var Cookie = Request.Cookies["csc-order-v2"];
                            if (Cookie != null)
                            {
                                var Order     = Cookie.Value;
                                var strOrder  = Server.UrlDecode(Order);
                                var ListOrder = JsonConvert.DeserializeObject <List <CookieOrder> >(strOrder);
                                if (ListOrder != null && ListOrder.Any())
                                {
                                    var temp = ListOrder.FirstOrDefault(x => x.CusId.Equals(User.ID));
                                    if (temp != null)
                                    {
                                        ListOrder.Remove(temp);
                                        Cookie.Value = null;
                                        Response.Cookies.Add(Cookie);
                                        var strListOrder = JsonConvert.SerializeObject(ListOrder);
                                        Cookie.Value = strListOrder;
                                        Response.Cookies.Add(Cookie);
                                    }
                                }
                                //Cookie.Expires = DateTime.Now.AddDays(-1d);
                                // Reset value cookie
                            }
                        }

                        Session.Add("UserClientSite", userSession);
                        Session.Remove("ListItemCategory");
                        //Update 04/09/2018
                        if (User.ListProduct != null && User.ListProduct.Any() && User.IsReseller)
                        {
                            return(RedirectToAction("Cart", "YourCart"));
                        }
                        //else
                        //{
                        return(RedirectToAction("Index", "MyStoreAndBusiness"));
                        //}
                        //if (!string.IsNullOrEmpty(mController))
                        //    return RedirectToAction("Index", mController);
                        //if (returnUrl == null)
                        //    return RedirectToAction("Index", "Home");
                        //else
                        //    return Redirect(returnUrl);
                    }
                    else
                    {
                        if (User != null && User.IsVerify == false)
                        {
                            return(RedirectToAction("Verification", "SignUp", new { email = model.Email }));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Email/Password is incorrect!");
                            return(View(model));
                        }
                    }
                }
                else
                {
                    return(View(model));// Return Error page
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Index : ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }