public string GetProductById([FromQuery] int productId)
        {
            ProductDetailResponse response = new ProductDetailResponse();

            try
            {
                //Try and find a product using the provided id
                Product product = _context.Product
                                  .Include(p => p.ProductCategory)
                                  .Where(p => p.ProductId == productId)
                                  .FirstOrDefault();

                //Add to response
                response.Product      = product;
                response.Success      = product != null;
                response.ErrorMessage = product != null ? null : $"The product with the ID {productId} could not be found";
            }
            catch (Exception e)
            {
                response.Success      = false;
                response.ErrorMessage = e.Message;
            }

            //Serialize and return
            return(JsonConvert.SerializeObject(response, Formatting.Indented,
                                               new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));
        }
        /// <summary>
        /// Get Product Details
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currencyCode"></param>
        /// <param name="excludeTourGradeAvailability"></param>
        /// <param name="showUnavailable"></param>
        /// <returns></returns>
        public async Task <ProductDetailResponse> GetProductDetailInfo(ProductDetailRequest productDetailModel, ViatorSetting setting = null)
        {
            var    uri      = $"service/product";
            string finalURL = $"{GenerateBaseURL(uri, setting)}&{GenerateQueryString(productDetailModel)}";
            var    response = await _httpClient.GetStringAsync(finalURL);

            var result = ProductDetailResponse.FromJson(response);

            return(result);
        }
        public ActionResult Detail(int id)
        {
            HomePageViewModel model = new HomePageViewModel();

            HttpClient client2 = new HttpClient();

            client2.BaseAddress = new Uri(SystemConstants.webApiBaseAddress);
            HttpResponseMessage result2 = client2.PostAsJsonAsync("api/Basket/List", (Session["User"] as User) == null ? new User {
                ID = 0
            } : (Session["User"] as User)).Result;

            if (result2.StatusCode == HttpStatusCode.OK)
            {
                string resultString = result2.Content.ReadAsStringAsync().Result;
                if (resultString != "{\"Products\":null}")
                {
                    GetBasketResponse basketResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <GetBasketResponse>(resultString);
                    if (basketResponse.Code == 1 || basketResponse.Code == 2)
                    {
                        model.BasketResponse = basketResponse;
                    }
                    else
                    {
                        return(View("SystemError"));
                    }
                }
            }

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(SystemConstants.webApiBaseAddress);
            HttpResponseMessage result = client.PostAsJsonAsync("api/Product/Detail", new Product
            {
                ID = id
            }).Result;

            if (result.StatusCode == HttpStatusCode.OK)
            {
                string resultString = result.Content.ReadAsStringAsync().Result;
                if (resultString != "{\"Product\":null}")
                {
                    ProductDetailResponse product = Newtonsoft.Json.JsonConvert.DeserializeObject <ProductDetailResponse>(resultString);
                    model.ProductDetailResponse = product;
                    if (product.Code == 1)
                    {
                        return(View("Detail", model));
                    }
                    if (product.Code == 2)
                    {
                        return(View("NotFound"));
                    }
                }
            }
            return(View("SystemError"));
        }
        public IActionResult GetDetail(int?id)
        {
            if (id == null)
            {
                return(BadRequest(new Exception("Invalid Product")));
            }
            var product = _context.Product
                          .Include(x => x.Holding)
                          .Include(x => x.Company)
                          .Include(x => x.User)
                          .Include(x => x.FotoUpload)
                          .Include(x => x.Category)
                          .Include(x => x.Interaction)
                          .FirstOrDefault(x => x.Id == id);
            var comment = _context.Interaction.Where(x => x.ProductId == id).Include(x => x.CommentUser).ToList();

            if (product == null)
            {
                return(NotFound(new Exception("Product not found")));
            }
            return(Ok(ProductDetailResponse.FromData(product, comment)));
        }
Example #5
0
        public ProductDetailResponse GetProductDetail(Product product)
        {
            ProductDetailResponse response = new ProductDetailResponse();

            using (MyDb db = new MyDb())
            {
                try
                {
                    response.Product = db.Products.FirstOrDefault(x => x.ID == product.ID);
                    if (response.Product == null)
                    {
                        response.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND);
                    }
                    else
                    {
                        try
                        {
                            response.productImageGalleries = db.ImageGalleries.Where(x => x.Product.ID == product.ID).ToList();
                            if (response.productImageGalleries != null)
                            {
                                response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL);
                            }
                            else
                            {
                                response.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND);
                            }
                        }catch (Exception ex)
                        {
                            response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR);
                        }
                    }
                }
                catch (Exception ex)
                {
                    response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR);
                }
                return(response);
            }
        }
        public IEnumerable <ProductDetailResponse> GetSubCategoryList(string catId)
        {
            catId = System.Net.WebUtility.UrlDecode(catId);

            catId = catId.Replace("+", "%20");
            catId = System.Net.WebUtility.UrlDecode(catId);
            catId = catId.Replace(" ", "+");

            bool ret = default(bool);
            IEnumerable <ProductDetail> categoryData = null;
            int ProductTypeId = 0;
            IList <ProductDetailResponse> responsedata = new List <ProductDetailResponse>();

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];

                    if (string.IsNullOrEmpty(catId))
                    {
                        ProductDetailResponse response = new ProductDetailResponse();
                        response.Status = ResponseStatus.Failed;
                        response.Error  = "Parameter mismatch";
                        responsedata.Add(response);
                    }
                    else
                    {
                        ProductTypeId = Convert.ToInt32(EncryptionHelper.AesDecryption(Convert.ToString(catId), EncryptionKey.LOG));
                        var connectionString = "AggieGlobal";
                        var repo             = new ProductManager(connectionString);
                        categoryData = repo.GetSubCategoryList(ProductTypeId, sessionObject._userId);
                        if (categoryData != null && categoryData.Count() > default(int))
                        {
                            foreach (ProductDetail detail in categoryData)
                            {
                                ProductDetailResponse response = new ProductDetailResponse();
                                response.ProductName          = detail.ProductName.Trim();
                                response.ProductTypeName      = detail.ProductTypeName.Trim();
                                response.ProductImageLocation = detail.ProductImageLocation; //fileurl(detail.ProductName.Trim());
                                response.ProductTypeName      = detail.ProductTypeName.Trim();
                                response.ProductId            = EncryptionHelper.AesEncryption(Convert.ToString(detail.ProductId), EncryptionKey.LOG);
                                response.catImageName         = detail.catImageName;
                                response.prodImageName        = detail.prodImageName;
                                response.Status = ResponseStatus.Successful;
                                if (detail.CategoryID == ProductType.Crop.GetHashCode())
                                {
                                    response.prodType = ProductType.Crop;
                                }
                                else if (detail.CategoryID == ProductType.LiveStock.GetHashCode())
                                {
                                    response.prodType = ProductType.LiveStock;
                                }
                                else if (detail.CategoryID == ProductType.Resource.GetHashCode())
                                {
                                    response.prodType = ProductType.Resource;
                                }
                                responsedata.Add(response);
                            }
                        }
                        else
                        {
                            ProductDetailResponse response = new ProductDetailResponse();
                            response.Error  = "Failed to retreive data";
                            response.Status = ResponseStatus.Failed;
                            responsedata.Add(response);
                        }
                        repo.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                ProductDetailResponse response = new ProductDetailResponse();
                response.Status = ResponseStatus.Failed;
                response.Error  = "Failed to retreive data";
                responsedata.Add(response);
                AggieGlobalLogManager.Fatal("ProductController :: GetCategoryList failed :: " + ex.Message);
            }
            return(responsedata);
        }