Exemple #1
0
        public IActionResult SaveItem(string Id = null, int CatId = 0, int IdCoQuan = 1)
        {
            ProductsOrderModel data           = new ProductsOrderModel();
            string             ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            int IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString());

            data.SearchData = new SearchProductsOrder()
            {
                CurrentPage = 0, ItemsPerPage = 10, Keyword = ""
            };

            if (IdDC == 0)
            {
                data.Item = new ProductsOrder()
                {
                    CreatedDate = DateTime.Now, Status = 0
                };
            }
            else
            {
                data.Item = ProductsOrderService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName);
                SearchProductsOrderDetail dts = new SearchProductsOrderDetail()
                {
                    ProductOrderId = IdDC
                };
                data.ListDetail = ProductsOrderDetailService.GetListPagination(dts, "");
            }
            return(View(data));
        }
Exemple #2
0
        public ActionResult DeleteItem(string Id)
        {
            string        ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            ProductsOrder model          = new ProductsOrder()
            {
                Id = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString())
            };

            try
            {
                if (model.Id > 0)
                {
                    model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]);
                    ProductsOrderService.DeleteItem(model);
                    TempData["MessageSuccess"] = "Xóa thành công";
                    return(Json(new MsgSuccess()));
                }
                else
                {
                    TempData["MessageError"] = "Xóa Không thành công";
                    return(Json(new MsgError()));
                }
            }
            catch
            {
                TempData["MessageSuccess"] = "Xóa không thành công";
                return(Json(new MsgError()));
            }
        }
Exemple #3
0
        public IActionResult Index([FromQuery] SearchProductsOrder dto)
        {
            int                TotalItems     = 0;
            string             ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            ProductsOrderModel data           = new ProductsOrderModel()
            {
                SearchData = dto
            };

            data.ListItems = ProductsOrderService.GetListPagination(data.SearchData, API.Models.Settings.SecretId + ControllerName);


            if (data.ListItems != null && data.ListItems.Count() > 0)
            {
                TotalItems = data.ListItems[0].TotalRows;
            }
            HttpContext.Session.SetString("STR_Action_Link_" + ControllerName, Request.QueryString.ToString());
            data.Pagination = new Areas.Admin.Models.Partial.PartialPagination()
            {
                CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString()
            };


            return(View(data));
        }
        public async Task <IActionResult> CheckOut(ProductsOrder model)
        {
            var recaptcha = await _recaptcha.Validate(Request);

            if (!recaptcha.success)
            {
                ModelState.AddModelError("Recaptcha", "Mã Captcha không chính xác. Vui lòng thử lại!");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    model.Id     = 0;
                    model.Status = 0;
                    try
                    {
                        int PId = (int)(ProductsOrderService.SaveItem(model).N);

                        //Thêm detail
                        List <ProductsOrderDetail> listDT = new List <ProductsOrderDetail>();
                        //Kiem tra session
                        var str1 = HttpContext.Session.GetString("ProductOrderList");
                        if (!string.IsNullOrEmpty(str1))
                        {
                            listDT = JsonConvert.DeserializeObject <List <ProductsOrderDetail> >(str1);
                        }

                        foreach (var itemDT in listDT)
                        {
                            itemDT.ProductOrderId = PId;
                            itemDT.Id             = 0;
                            ProductsOrderDetailService.SaveItem(itemDT);
                        }

                        HttpContext.Session.SetString("ProductOrderList", "");
                        TempData["MessageSuccess"] = "Đặt hàng thành công. Chúng tôi sẽ liên hệ với bạn trong thời gian sớm nhất.";
                    }
                    catch
                    {
                        TempData["MessageError"] = "Đặt hàng thất bại. Xin vui lòng thử lại";
                    }
                    return(RedirectToAction("CheckOut"));
                }
            }

            ProductsOrderModel item = new ProductsOrderModel();

            item.ListDetail = new List <ProductsOrderDetail>();
            //Kiem tra session
            var str = HttpContext.Session.GetString("ProductOrderList");

            if (!string.IsNullOrEmpty(str))
            {
                item.ListDetail = JsonConvert.DeserializeObject <List <ProductsOrderDetail> >(str);
            }
            item.Item = model;
            return(View(item));
        }
Exemple #5
0
        public ActionResult SaveItem(ProductsOrder model)
        {
            string             ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            int                IdDC           = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString());
            ProductsOrderModel data           = new ProductsOrderModel()
            {
                Item = model
            };

            if (ModelState.IsValid)
            {
                if (model.Id == IdDC)
                {
                    model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]);
                    ProductsOrderService.SaveItem(model);
                    if (model.Id > 0)
                    {
                        TempData["MessageSuccess"] = "Cập nhật thành công";
                    }
                    else
                    {
                        TempData["MessageSuccess"] = "Thêm mới thành công";
                    }

                    string Str_Url = HttpContext.Session.GetString("STR_Action_Link_" + ControllerName);
                    if (Str_Url != null && Str_Url != "")
                    {
                        return(Redirect("/Admin/" + this.ControllerContext.RouteData.Values["controller"].ToString() + "/Index" + Str_Url));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            else
            {
                //data.ListStart = ProductsOrderService.GetListStart();
            }
            return(View(data));
        }