Example #1
0
        public async Task <ActionResult> Add(Organization ogt)
        {
            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = Configuarations.Url_AddOrganization,
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = AccessToken
                },
                FormValue = Helpers.ConvertObToKeyPair(ogt)
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);

            if (responseData.Code == 200)
            {
                SystemSession.CurrentAccount.OrganizationName = ogt.OrganizationId != 0 ? ogt.Name : OrganizationName;
                return(RedirectToAction("Index", "Organization"));
            }
            else
            {
                ModelState.AddModelError("", responseData.Message);
            }

            return(View("_Add", ogt));
        }
Example #2
0
        public async Task <GridModel <ProductPrice> > GetListPricePG(RequestParams pr)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlPriceGetListPricePg + "/" + pr.PageIndex.ToString() + "/" + pr.ProductId.ToString() + "/" + pr.ProductCategoryId.ToString(),
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                }
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            GridModel <ProductPrice> listPrice = new GridModel <ProductPrice>();

            if (responseData.Code == 200)
            {
                listPrice = Helpers.Deserialize <GridModel <ProductPrice> >(responseData.Data);
            }

            return(listPrice);
        }
Example #3
0
        public async Task <PartialViewResult> ShopCart(List <Cart> cart)
        {
            if (SystemSession.ShopCart != null && SystemSession.ShopCart.Count > 0)
            {
                PaymentModel payment = new PaymentModel()
                {
                    Payment = new Payment()
                    {
                        AccountId   = SystemSession.CurrentAccount.AccountId,
                        PaymentCode = Helpers.RandomString(8, false)
                    },
                    ListPaymentDetail = SystemSession.ShopCart
                };
                string paymentString = Helpers.Serialize(payment);

                RequestInfor requestInfor = new RequestInfor()
                {
                    UrlBase   = Configuarations.Url_Shop_Payment,
                    FormValue = new List <KeyValuePair <string, string> >()
                    {
                        new KeyValuePair <string, string>("paymentString", paymentString)
                    }
                };
                var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);

                if (responseData.Code == 200)
                {
                    SystemSession.ShopCart = null;
                }
            }

            return(PartialView("_Cart", cart));
        }
Example #4
0
        public async Task <List <Product> > GetListProduct(int productCategoryId, int organizationId)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlCatalogGetListProduct + "/" + productCategoryId.ToString() + "/" + organizationId.ToString(),
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                }
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            if (responseData.Code == 200)
            {
                return(Helpers.Deserialize <List <Product> >(responseData.Data));
            }

            return(new List <Product>());
        }
Example #5
0
        public async Task <GridModel <Product> > GetListProductPG(RequestParams pr)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlCatalogGetListProductPg + "/" + pr.PageIndex.ToString() + "/" + pr.ProductCategoryId.ToString() + "/" + pr.OrganizationId.ToString(),
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                }
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            GridModel <Product> listProduct = new GridModel <Product>();

            if (responseData.Code == 200)
            {
                listProduct = Helpers.Deserialize <GridModel <Product> >(responseData.Data);
                string listProductString = Helpers.Serialize(listProduct.Data);

                requestInfor = new RequestInfor()
                {
                    UrlBase     = StaticConfig.UrlPriceGetPriceFromProduct,
                    HeaderValue = new HeaderValue()
                    {
                        AuthorizationType  = "Bearer",
                        AuthorizationValue = _accessToken
                    },
                    FormValue = new List <KeyValuePair <string, string> >()
                    {
                        new KeyValuePair <string, string>("listProductString", listProductString)
                    }
                };
                responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);

                var listProductPrice = new List <Product>();
                var oldListProduct   = listProduct.Data;
                var newListProduct   = new List <Product>();

                if (responseData.Code == 200)
                {
                    listProductPrice = Helpers.Deserialize <List <Product> >(responseData.Data);

                    foreach (var item in oldListProduct)
                    {
                        item.Price = listProductPrice.FirstOrDefault(x => x.ProductId == item.ProductId).Price;
                        newListProduct.Add(item);
                    }

                    listProduct.Data = newListProduct;
                }
            }

            return(listProduct);
        }
Example #6
0
        public async Task <Organization> GetInforOrganizationFromAcc(int accountId)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlCatalogGetInforOrganizationFromAcc + "/" + accountId.ToString(),
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                }
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            if (responseData.Code == 200)
            {
                return(Helpers.Deserialize <Organization>(responseData.Data));
            }

            return(new Organization()
            {
                OrganizationId = -1
            });
        }
Example #7
0
        public async Task <List <ProductCategory> > GetListProductCategory()
        {
            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase = StaticConfig.UrlCatalogGetListProductCategory
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            if (responseData.Code == 200)
            {
                return(Helpers.Deserialize <List <ProductCategory> >(responseData.Data));
            }

            return(new List <ProductCategory>());
        }
Example #8
0
        public async Task <Account> GetInforAccount(string email)
        {
            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase = Configuarations.Url_GetInforAccount + "/" + email
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            if (responseData.Code == 200)
            {
                return(Helpers.Deserialize <Account>(responseData.Data));
            }

            return(new Account());
        }
Example #9
0
        public async Task DeleteProduct(int productId)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlCatalogDeleteProduct + "/" + productId.ToString(),
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                }
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.DELETE);
        }
Example #10
0
        public async Task UpdatePrice(ProductPrice productPrice)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlPriceUpdatePrice,
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                },
                FormValue = Helpers.ConvertObToKeyPair(productPrice)
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);
        }
Example #11
0
        public void AddOrganization(Organization ogt)
        {
            if (Request.Headers.TryGetValue("Authorization", out _authorizationToken))
            {
                this._accessToken = _authorizationToken.ToString().Substring("Bearer ".Length);
            }

            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = StaticConfig.UrlCatalogAddOrganization,
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = _accessToken
                },
                FormValue = Helpers.ConvertObToKeyPair(ogt)
            };
            var responseData = ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);
        }
Example #12
0
        public async Task <ActionResult> LoadContent(int productCategoryId, int pageIndex)
        {
            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase = Configuarations.Url_Shop_GetListProductPrice + "/" + pageIndex.ToString() + "/" + productCategoryId.ToString()
            };

            GridModel <Product> listProduct = new GridModel <Product>();
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            if (responseData.Code != 200)
            {
                ViewBag.ResultData = null;
                return(View("index"));
            }

            listProduct = Helpers.Deserialize <GridModel <Product> >(responseData.Data);

            return(PartialView("_Content", listProduct));
        }
Example #13
0
        public async Task <PartialViewResult> ViewHistory()
        {
            var listHistory = new GridModel <Payment>();

            if (SystemSession.CurrentAccount != null)
            {
                RequestInfor requestInfor = new RequestInfor()
                {
                    UrlBase = Configuarations.Url_Shop_ViewHistory + "/0" + "/" + SystemSession.CurrentAccount.AccountId.ToString()
                };
                var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

                if (responseData.Code == 200)
                {
                    listHistory = Helpers.Deserialize <GridModel <Payment> >(responseData.Data);
                }
            }

            return(PartialView("_History", listHistory));
        }
Example #14
0
        public async Task <PartialViewResult> LoadContent(int pageIndex)
        {
            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase     = Configuarations.Url_MyOrder_GetListProduct + "/" + pageIndex.ToString() + "/" + OrganizationId.ToString(),
                HeaderValue = new HeaderValue()
                {
                    AuthorizationType  = "Bearer",
                    AuthorizationValue = AccessToken
                },
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            var listProduct = new GridModel <Product>();

            if (responseData.Code == 200)
            {
                listProduct = Helpers.Deserialize <GridModel <Product> >(responseData.Data);
            }

            return(PartialView("_Content", listProduct));
        }
Example #15
0
        public async Task <GridModel <Product> > MyOrder_GetListProduct(RequestParams pr)
        {
            RequestInfor requestInfor = new RequestInfor()
            {
                UrlBase = StaticConfig.UrlPaymentMyOrderGetListProduct + "/" + pr.PageIndex.ToString() + "/" + pr.OrganizationId.ToString()
            };
            var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

            var listProduct = new GridModel <Product>();

            if (responseData.Code == 200)
            {
                listProduct = Helpers.Deserialize <GridModel <Product> >(responseData.Data);
                string listProductString = Helpers.Serialize(listProduct.Data);

                //Get infor product
                requestInfor = new RequestInfor()
                {
                    UrlBase   = StaticConfig.UrlCatalogShopGetListProduct,
                    FormValue = new List <KeyValuePair <string, string> >()
                    {
                        new KeyValuePair <string, string>("listProductString", listProductString)
                    }
                };
                responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);

                if (responseData.Code == 200)
                {
                    var listProductInfor = Helpers.Deserialize <List <Product> >(responseData.Data);

                    var newListProduct = new List <Product>();
                    foreach (var item in listProduct.Data)
                    {
                        item.Code = listProductInfor.FindLast(x => x.ProductId == item.ProductId).Code;
                        item.Name = listProductInfor.FindLast(x => x.ProductId == item.ProductId).Name;
                        newListProduct.Add(item);
                    }

                    listProduct.Data = newListProduct;
                }

                //Get infor account
                string listAccountString = Helpers.Serialize(listProduct.Data.Select(x => x.AccountId).Distinct().ToList());
                requestInfor = new RequestInfor()
                {
                    UrlBase   = StaticConfig.UrlMyOrderGetListInforAccount,
                    FormValue = new List <KeyValuePair <string, string> >()
                    {
                        new KeyValuePair <string, string>("listAccountString", listAccountString)
                    }
                };
                responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);

                if (responseData.Code == 200)
                {
                    var listAccountInfor = Helpers.Deserialize <List <Account> >(responseData.Data);

                    var newListProduct = new List <Product>();
                    foreach (var item in listProduct.Data)
                    {
                        var account = listAccountInfor.FindLast(x => x.AccountId == item.AccountId);
                        item.AccountName = account.Firstname + " " + account.LastName;
                        item.Phone       = account.Phone;
                        newListProduct.Add(item);
                    }

                    listProduct.Data = newListProduct;
                }
            }

            return(listProduct);
        }
Example #16
0
        public async Task <ActionResult> Register(Account acc)//async Task<ActionResult>
        {
            bool isValid = true;

            //Validate form data
            if (acc.Password != acc.RePassword)
            {
                isValid = false;
                ModelState.AddModelError("RePassword", "Nhập lại Password chưa đúng");
            }

            //Validate logic data
            if (acc.AccountId == 0)
            {
                RequestInfor requestInfor = new RequestInfor()
                {
                    UrlBase = Configuarations.Url_CheckExistAccount + "/" + acc.Email
                };
                var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.GET);

                if (responseData.Code == 200 && bool.Parse(responseData.Data ?? "False"))
                {
                    isValid = false;
                    ModelState.AddModelError("Email", "Tài khoản của bạn đã được đăng ký trên hệ thống");
                }

                if (responseData.Code != 200)
                {
                    isValid = false;
                    ModelState.AddModelError("", "Hệ thống đang bảo trì kỹ thuật, xin vui lòng quay lại sau!");
                }
            }

            if (isValid)
            {
                acc.Password = acc.Password != "......" ? Helpers.EncryptPassWord(acc.Password) : "";

                RequestInfor requestInfor = new RequestInfor()
                {
                    UrlBase   = Configuarations.Url_CreateAccount,
                    FormValue = Helpers.ConvertObToKeyPair(acc)
                };

                var responseData = await ConnectAPI.ConnectRestAPI(requestInfor, MethodType.POST);

                if (responseData.Code != 200)
                {
                    ModelState.AddModelError("", "Hệ thống đang bảo trì kỹ thuật, xin vui lòng quay lại sau!");
                }
                else if (acc.AccountId == 0)
                {
                    var tokenInfor = await GetAccessToken(acc.Email, acc.Password);

                    if (tokenInfor.Code != 200)
                    {
                        return(await CreateSessionAccount(acc.Email, ""));
                    }

                    return(await CreateSessionAccount(acc.Email, tokenInfor.Data));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View("_Register", acc));
        }