Пример #1
0
        //thong tin chung
        public ActionResult CommonInfo()
        {
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            if (commonInfo == null)
            {
                commonInfo = new CommonBO();
            }
            return(View(commonInfo));
        }
Пример #2
0
        public ActionResult Index(string metatitle, int id, int attribute_pa_chon_chat_lieu_op_lung = 0, string cart_item_key = "")
        {
            if (metatitle.Length <= 0 || metatitle.Split('-').Count() <= 1)
            {
                return(RedirectToAction("NotFound", "Error"));
            }


            var product = ProductDAO.GetProductByID(id);

            if (product == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            product.avatar.OrderBy(x => x.displayorder);
            product.slide.OrderBy(x => x.displayorder);

            if (product.collectionid > 0)
            {
                ViewBag.CollectionName = BrandModel.GetCollectionByID(Convert.ToInt32(product.collectionid)).name;
            }
            else
            {
                ViewBag.BrandName = BrandModel.GetBrandByID(Convert.ToInt32(product.brandid)).name;
            }

            ViewBag.CurrentMaterialID = attribute_pa_chon_chat_lieu_op_lung;
            CartSession cart = new CartSession();

            if (!String.IsNullOrEmpty(cart_item_key))
            {
                List <CartSession> lstCartItem = Session["fancycart"] as List <CartSession>;
                if (lstCartItem != null)
                {
                    cart = lstCartItem.Where(x => x.ItemKey == cart_item_key).FirstOrDefault();
                }
            }
            if (cart == null)
            {
                cart = new CartSession();
            }
            if (!String.IsNullOrEmpty(cart.Order))
            {
                cart.OrderObject            = JsonConvert.DeserializeObject <dynamic>(cart.Order);
                cart.OrderObject_Additional = cart.OrderObject.product[0];
            }

            ViewBag.CurrentCartItem = cart;
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            ViewBag.CommonInfo = commonInfo;
            return(View(product));
        }
Пример #3
0
        public ActionResult ChekoutSuccess(string orderid = "")
        {
            if (string.IsNullOrEmpty(orderid))
            {
                return(RedirectToAction("Index"));
            }
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            ViewBag.CommonInfo = commonInfo;
            OrderBO order = OrderDAO.GetOrderByID(orderid);


            return(View(order));
        }
Пример #4
0
        public ActionResult UpdateCommonInfo(CommonBO updateBO, FormCollection form)
        {
            string accName   = form["accountname"];
            string bankName  = form["bankname"];
            string accNumber = form["accountnumber"];

            updateBO.bankinfo = new List <BankInfo>();
            updateBO.bankinfo.Add(new BankInfo()
            {
                accountname   = accName,
                accountnumber = accNumber,
                bankname      = bankName
            });
            if (ModelState.IsValid)
            {
                var updateModel = LocationDAO.GetCommonInfoByID(updateBO.id);
                if (updateModel == null || String.IsNullOrEmpty(updateModel.id))
                {
                    SetAlert($"Không tồn tại Common này!", "error");
                    return(View("CommonInfo", updateBO));
                }
                updateModel.email          = updateBO.email;
                updateModel.facebookchat   = updateBO.facebookchat;
                updateModel.facebookpage   = updateBO.facebookpage;
                updateModel.factoryaddress = updateBO.factoryaddress;
                updateModel.hotline        = updateBO.hotline;
                updateModel.phone          = updateBO.phone;
                updateModel.mapurl         = updateBO.mapurl;
                updateModel.officeaddress  = updateBO.officeaddress;
                updateModel.zalochat       = updateBO.zalochat;


                updateModel.bankinfo = new List <BankInfo>();
                updateModel.bankinfo.Add(new BankInfo()
                {
                    accountname   = accName,
                    accountnumber = accNumber,
                    bankname      = bankName
                });
                string errorMessage = "";
                var    result       = LocationDAO.UpdateCommonInfo(updateModel, ref errorMessage);
                SetAlert($"Cập nhật thông tin chung thành công", "success");
                return(RedirectToAction("CommonInfo"));
            }
            return(View("CommonInfo", updateBO));
        }
Пример #5
0
        public ActionResult Collection(string metatitle, int id, string orderby = "")
        {
            if (metatitle.Length <= 0 && metatitle.Split('-').Count() < 2)
            {
                return(RedirectToAction("NotFound", "Error"));
            }

            var collectionInfo = CollectionDAO.GetCollectionByID(id);

            if (collectionInfo == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }

            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            ViewBag.OrderBy    = orderby;
            ViewBag.CommonInfo = commonInfo;
            return(View(collectionInfo));
        }
Пример #6
0
        public ActionResult Index()
        {
            var commonInfo    = LocationDAO.GetCommonInfoByID("commoninfo");
            var lstBrand      = BrandModel.GetAllBrand();
            var lstPhoneModel = new List <PhoneModelBO>();

            foreach (var item in lstBrand)
            {
                var result = BrandModel.GetPhoneModelByBrandID(item.id);
                if (result != null)
                {
                    lstPhoneModel.AddRange(result);
                }
            }
            ViewBag.ListBrand  = lstBrand;
            ViewBag.ListModel  = lstPhoneModel;
            ViewBag.CommonInfo = commonInfo;

            return(View());
        }
Пример #7
0
        public ActionResult Checkout()
        {
            List <CartSession> lstCartItem = Session["fancycart"] as List <CartSession>;

            if (lstCartItem == null)
            {
                lstCartItem = new List <CartSession>();
            }
            if (lstCartItem.Count <= 0)
            {
                return(RedirectToAction("Index"));
            }

            //load danh sách Province
            var listProvince = LocationDAO.GetListProvinces();

            ViewBag.ListProvince = listProvince;
            ViewBag.ListCartItem = lstCartItem;
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            ViewBag.CommonInfo = commonInfo;

            return(View());
        }
Пример #8
0
        public ActionResult Contact()
        {
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            return(View(commonInfo));
        }
Пример #9
0
        public ActionResult Footer()
        {
            var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");

            return(PartialView(commonInfo));
        }
Пример #10
0
        public ActionResult Checkout(FormCollection form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var lstIP = CommonHelper.GetIPAddresses();

                    OrderBO order = new OrderBO();
                    order.id         = DateTime.Now.Ticks.ToString();
                    order.createdate = DateTime.Now;
                    order.fullname   = form["fullname"].ToString();

                    int districtID = Convert.ToInt32(form["district"].ToString());
                    int provinceID = Convert.ToInt32(form["province"].ToString());
                    int wardID     = Convert.ToInt32(form["ward"].ToString());
                    var provinceBO = LocationDAO.GetProvinceByID(provinceID);
                    var districtBO = LocationDAO.GetDistrictByID(districtID);
                    var wardBO     = LocationDAO.GetWardByID(wardID);



                    order.district = districtBO.name;
                    order.province = provinceBO.name;
                    order.ward     = wardBO.name;

                    order.email       = form["email"].ToString();
                    order.phone       = form["phone"].ToString();
                    order.fulladdress = form["orderfulladdress"].ToString();

                    order.note = form["ordernote"].ToString();
                    var listItemKey = form["listitemkey"].Split('|');
                    if (listItemKey == null || listItemKey.Count() <= 0 ||
                        String.IsNullOrEmpty(order.fullname) ||
                        String.IsNullOrEmpty(order.phone) || String.IsNullOrEmpty(order.fulladdress) ||
                        String.IsNullOrEmpty(order.district) || String.IsNullOrEmpty(order.province) ||
                        String.IsNullOrEmpty(order.ward))
                    {//phai dien day du thong tin
                        return(RedirectToAction("Checkout"));
                    }
                    //get list item
                    List <CartSession> lstCartItem = new List <CartSession>();
                    lstCartItem = Session["fancycart"] as List <CartSession>;
                    if (lstCartItem == null)
                    {
                        return(RedirectToAction("Checkout"));
                    }
                    List <CartItemBO> lstCartItemBO = new List <CartItemBO>();
                    foreach (var item in lstCartItem)
                    {
                        CartItemBO cartItem = JsonConvert.DeserializeObject <CartItemBO>(JsonConvert.SerializeObject(item));
                        lstCartItemBO.Add(cartItem);
                    }
                    order.listitem = lstCartItemBO;

                    //check payment method
                    var payment = form["payment_method"];
                    if (payment.ToLower().Trim() == "bacs")
                    {
                        order.paymenttype = 2;
                    }
                    else
                    {
                        order.paymenttype = 1;
                    }

                    //tính discount
                    if (order.paymenttype == 2)
                    {
                        order.totaldiscount = order.listitem.Sum(x => x.FinalPrice) * 5 / 100;
                    }
                    order.iporder    = lstIP != null && lstIP.Count() > 0 ? lstIP.First() : "";
                    order.status     = 1;
                    order.statusname = "Chưa xử lý";

                    //insert to mongodb

                    string error  = "";
                    var    result = OrderDAO.CreateOrder(order, ref error);
                    if (result)
                    {
                        //remove item in cart
                        lstCartItem.Clear();
                        #region create account
                        //add user vào thông tin tài khoản luôn
                        //check đã tồn tại username
                        string username = !String.IsNullOrEmpty(order.email) ? order.email : order.phone;
                        var    userBO   = UserDAO.GetUserByUserNameNotAdmin(username);
                        if (userBO != null && userBO.id > 0)
                        {
                            return(RedirectToAction("ChekoutSuccess", new { orderid = order.id }));
                        }

                        UserBO user = new UserBO();
                        user.username    = username;
                        user.password    = "******";//123456
                        user.phone       = order.phone;
                        user.isactive    = 1;
                        user.role        = "customer";
                        user.fullname    = order.fullname;
                        user.address     = order.fulladdress + ", " + order.ward + ", " + order.district + ", " + order.province;
                        user.email       = order.email;
                        user.createddate = DateTime.Now;
                        user.note        = "User được tạo tự động khi submit đơn hàng thành công";
                        string errorMessage = String.Empty;
                        result = UserDAO.CreateUser(user, ref errorMessage);
                        #endregion
                    }

                    return(RedirectToAction("ChekoutSuccess", new { orderid = order.id }));
                }
                else
                {
                    List <CartSession> lstCartItem = Session["fancycart"] as List <CartSession>;
                    if (lstCartItem == null)
                    {
                        lstCartItem = new List <CartSession>();
                    }
                    if (lstCartItem.Count <= 0)
                    {
                        return(RedirectToAction("Index"));
                    }

                    //load danh sách Province
                    var listProvince = LocationDAO.GetListProvinces();
                    ViewBag.ListProvince = listProvince;
                    ViewBag.ListCartItem = lstCartItem;
                    var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");
                    ViewBag.CommonInfo = commonInfo;

                    return(View("Checkout"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "* Quý khách vui lòng nhập đầy đủ thông tin để gửi đơn hàng ạ!");
                List <CartSession> lstCartItem = Session["fancycart"] as List <CartSession>;
                if (lstCartItem == null)
                {
                    lstCartItem = new List <CartSession>();
                }
                if (lstCartItem.Count <= 0)
                {
                    return(RedirectToAction("Index"));
                }

                //load danh sách Province
                var listProvince = LocationDAO.GetListProvinces();
                ViewBag.ListProvince = listProvince;
                ViewBag.ListCartItem = lstCartItem;
                var commonInfo = LocationDAO.GetCommonInfoByID("commoninfo");
                ViewBag.CommonInfo = commonInfo;

                return(View("Checkout"));
            }
        }