Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(int?prod_id)
        {
            if (prod_id == null)
            {
                return(NotFound());
            }
            ViewData["ID"] = prod_id;

            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Products");

            if (res.IsSuccessStatusCode)
            {
                var result  = res.Content.ReadAsStringAsync().Result;
                var product = JsonConvert.DeserializeObject <IList <Product> >(result);
                ViewData["ProductID"] = new SelectList(product.Where(p => p.ID == prod_id), "ID", "ID");
            }
            res = await client.GetAsync("api/Categories");

            if (res.IsSuccessStatusCode)
            {
                var result     = res.Content.ReadAsStringAsync().Result;
                var categories = JsonConvert.DeserializeObject <IList <Category> >(result);
                ViewData["CategoryID"] = new SelectList(categories.Where(c => c.ProductCategories.All(pc => pc.ProductID != prod_id) && c.IsActive), "ID", "Name");
            }

            return(Page());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?variant_id, int?prod_id)
        {
            if (variant_id == null)
            {
                return(NotFound());
            }

            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Action/GetProductVariant/" + variant_id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Variant = JsonConvert.DeserializeObject <Variant>(result);
            }

            if (Variant == null)
            {
                return(NotFound());
            }
            res = await client.GetAsync("api/Products");

            if (res.IsSuccessStatusCode)
            {
                var result  = res.Content.ReadAsStringAsync().Result;
                var product = JsonConvert.DeserializeObject <IList <Product> >(result);
                ViewData["ProductID"] = new SelectList(product.Where(p => p.ID == prod_id), "ID", "ID");
            }

            return(Page());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Orders/" + id + "/GetAdminOrderDetails");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Order         = JsonConvert.DeserializeObject <Order>(result);
                CurrentStatus = Order.Status;
            }

            if (Order == null)
            {
                return(NotFound());
            }

            //res = await client.GetAsync("api/Members/");
            //if (res.IsSuccessStatusCode)
            //{
            //    var result = res.Content.ReadAsStringAsync().Result;
            //    var member = JsonConvert.DeserializeObject<IEnumerable<Member>>(result);
            //    ViewData["MemberID"] = new SelectList(member, "ID", "ID");
            //}
            return(Page());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync()
        {
            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Categories/GetActiveCategories");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                IEnumerable <Category> categoryList = JsonConvert.DeserializeObject <IEnumerable <Category> >(result);
                ViewData["Category"] = new SelectList(categoryList, "ID", "Name");
            }
            return(Page());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HttpClient          client  = _api.Initial();
            var                 product = new Product();
            HttpResponseMessage res     = await client.GetAsync("api/Products/" + id + "/GetAdminProductDetails");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                product = JsonConvert.DeserializeObject <Product>(result);
            }


            res = await client.GetAsync("api/Categories/GetActiveCategories");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                IEnumerable <Category> activeCategories = JsonConvert.DeserializeObject <IEnumerable <Category> >(result);

                object[] selectedValues = new object[product.ProductCategories.Count];
                ushort   i = 0;
                foreach (var item in product.ProductCategories)
                {
                    selectedValues[i++] = item.Category.ID;
                }
                SelectedCategories = new MultiSelectList(activeCategories, "ID", "Name", selectedValues);
            }

            if (product == null)
            {
                return(NotFound());
            }

            InputModel               = new ProductEditInputModel();
            InputModel.ID            = product.ID;
            InputModel.IsActive      = product.IsActive;
            InputModel.Price         = product.Price;
            InputModel.CreatedAt     = product.CreatedAt;
            InputModel.Description   = product.Description;
            InputModel.ProductName   = product.ProductName;
            InputModel.ProductImages = product.ProductImages;
            InputModel.Variants      = product.Variants;

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Products/" + id + "/GetProductDetails");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Product = JsonConvert.DeserializeObject <Product>(result);
            }

            if (Product == null)
            {
                return(NotFound());
            }

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                res = await client.GetAsync("api/Members/GetMemberByUsername/" + HttpContext.User.Identity.Name);

                if (res.IsSuccessStatusCode)
                {
                    var result = res.Content.ReadAsStringAsync().Result;
                    var member = JsonConvert.DeserializeObject <Member>(result);
                    ViewData["MemberID"] = member.ID;
                }
            }

            return(Page());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Categories/" + id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Category = JsonConvert.DeserializeObject <Category>(result);
            }

            if (Category == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 8
0
        private void RetrieveTotal(string apiUrl, string name)
        {
            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = client.GetAsync(apiUrl).Result;

            if (res.IsSuccessStatusCode)
            {
                ViewData[name + "Count"] = res.Content.ReadAsStringAsync().Result;
            }
        }
Exemplo n.º 9
0
        public async Task<IActionResult> OnGetAsync(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            HttpClient client = _api.Initial();
            HttpResponseMessage res = await client.GetAsync("api/Members/" + id);
            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Member = JsonConvert.DeserializeObject<Member>(result);
            }

            if (Member == null)
            {
                return NotFound();
            }
            return Page();
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnGetAsync()
        {
            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Members/GetMemberByUsername/" + HttpContext.User.Identity.Name);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                var member = JsonConvert.DeserializeObject <Member>(result);
                ViewData["MemberID"] = member.ID;

                res = await client.GetAsync("api/CartDetails/" + member.ID + "/GetCartDetailById");

                if (res.IsSuccessStatusCode)
                {
                    result        = res.Content.ReadAsStringAsync().Result;
                    CartDetailDTO = JsonConvert.DeserializeObject <UserCartDetailDTO>(result);
                }
            }
            return(Page());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Action/GetProductImage/" + id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                ProductImage = JsonConvert.DeserializeObject <ProductImage>(result);
            }

            if (ProductImage == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 12
0
        public async Task OnGetAsync(int?pageNumber, string orderBy)
        {
            CurrentSort = orderBy;
            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Orders/GetOrdersByPagination?PageNumber=" + (pageNumber ?? 1) + "&PageSize=" + 5 + "&orderBy=" + orderBy);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                PaginationFilter = JsonConvert.DeserializeObject <PaginationFilter <Order> >(result);
                Order            = PaginationFilter.PagedData;
            }
        }
Exemplo n.º 13
0
        public async Task OnGetAsync()
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                HttpClient          client = _api.Initial();
                HttpResponseMessage res    = await client.GetAsync("api/Orders/" + HttpContext.User.Identity.Name + "/GetOrderByUsername");

                if (res.IsSuccessStatusCode)
                {
                    var result = res.Content.ReadAsStringAsync().Result;
                    Order = JsonConvert.DeserializeObject <IList <Order> >(result);
                }
            }
        }
Exemplo n.º 14
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.GetAsync("api/Action/GetProductVariants/" + id);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Variant = JsonConvert.DeserializeObject <IList <Variant> >(result);
            }

            ViewData["ProductID"] = id;

            return(Page());
        }
Exemplo n.º 15
0
        public async Task OnGetAsync(int?pageNumber)
        {
            HttpClient client = _api.Initial();

            HttpResponseMessage res = await client.GetAsync("api/Products/GetProductImagesAndCategoriesByPagination?PageNumber=" + (pageNumber ?? 1) + "&PageSize=" + 8);

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                PaginationFilter = JsonConvert.DeserializeObject <PaginationFilter <Product> >(result);
                Product          = PaginationFilter.PagedData;
            }

            res = await client.GetAsync("api/Categories/GetActiveCategories");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                Category = JsonConvert.DeserializeObject <IList <Category> >(result);
            }
        }
Exemplo n.º 16
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Category.CreatedAt = DateTime.Now;

            HttpClient          client = _api.Initial();
            HttpResponseMessage res    = await client.PostAsync("api/Categories", new StringContent(
                                                                    JsonConvert.SerializeObject(Category), Encoding.UTF8, MediaTypeNames.Application.Json));

            if (res.IsSuccessStatusCode)
            {
                var      result       = res.Content.ReadAsStringAsync().Result;
                Category tempCategory = JsonConvert.DeserializeObject <Category>(result);
                _logger.LogInformation("{user} has created a new category [ID: {category_id}].", HttpContext.User.Identity.Name, tempCategory.ID);
                return(RedirectToPage("./Index"));
            }

            ViewData["Error"] = "Failed to insert record";
            return(Page());
        }