Beispiel #1
0
        public IActionResult GetProductDetailByProductId_Linq([FromBody] ProductDetailReq req)
        {
            var res   = new SingleRsp();
            var proId = _svc.GetProductDetailByProductId_Linq(req.ProductId, req.Page, req.Size);

            res.Data = proId;

            return(Ok(res));
        }
        public async Task <ProductDetails> GetProductDetail(ProductDetailReq request)
        {
            request.Product_Id = request.Product_Id.ToLower();
            ProductDetailRes             response = new ProductDetailRes();
            FilterDefinition <mProducts> filter;

            filter = Builders <mProducts> .Filter.Empty;
            filter = filter & Builders <mProducts> .Filter.Regex(x => x.VoyagerProduct_Id, new BsonRegularExpression(new Regex(request.Product_Id, RegexOptions.IgnorePatternWhitespace)));

            var result = await _MongoContext.mProducts.Find(filter).Project(p => new ProductDetails
            {
                Location = new ProductLocation
                {
                    CountryName = p.CountryName,
                    CountryCode = p.ParentResort_Id,
                    CityName    = p.CityName,
                    CityCode    = p.Resort_Id,
                    Lat         = (p.Lat == "0.00") ? "" : p.Lat,
                    Long        = (p.Long == "0.00") ? "" : p.Long,
                    Address     = p.FullAddress,
                    PostCode    = p.PostCode
                },
                Code          = p.ProductCode ?? "",
                Description   = p.ProdDesc ?? "",
                Email         = p.Suppmail ?? "",
                Fax           = p.Suppfax ?? "",
                IsPlaceHolder = p.Placeholder ?? false,
                Name          = p.ProdName ?? "",
                Product_Id    = p.VoyagerProduct_Id,
                Telephone     = p.Supptel ?? "",
                Type          = p.ProductType ?? "",
                Website       = p.Suppweb ?? ""
            }).FirstOrDefaultAsync();

            if (result != null)
            {
                if (result.Type.ToLower() == "hotel")
                {
                    var resHotelInfo = (from h in _MongoContext.mProductHotelAdditionalInfo.AsQueryable()
                                        where h.ProductId.ToLower() == request.Product_Id.ToLower()
                                        select new HotelInfo
                    {
                        Category = h.BudgetCategory ?? "",
                        Chain = h.HotelChain ?? "",
                        HotelType = h.HotelType ?? "",
                        Location = h.Location ?? "",
                        StarRating = h.StarRating ?? "",
                        Corner = h.Corner
                    }).FirstOrDefault();
                    if (resHotelInfo != null)
                    {
                        result.Metro        = resHotelInfo.Corner;
                        resHotelInfo.Corner = null;
                        result.HotelInfo    = resHotelInfo;
                    }
                }
                var catInfo = (from c in _MongoContext.mProductCategory.AsQueryable()
                               join p in _MongoContext.mProdCatDef.AsQueryable() on c.ParentCategory_Id equals p.VoyagerDefProductCategoryId //into jp
                                                                                                                                             //from jdp in jp.DefaultIfEmpty()
                               where c.Product_Id.ToLower() == request.Product_Id.ToLower()
                               orderby c.Default, c.ProductCategoryName
                               select new ProductCategoryInfo
                {
                    Category_Id = c.VoyagerProductCategory_Id,
                    Name = c.ProductCategoryName ?? "",
                    IsDefault = c.Default,
                    ParentCategory = p.Name ?? ""
                }).ToList();

                if (catInfo.Count > 0)
                {
                    foreach (ProductCategoryInfo cat in catInfo)
                    {
                        var rngInfo = (from r in _MongoContext.mProductRange.AsQueryable()
                                       where r.ProductCategory_Id.ToLower() == cat.Category_Id.ToLower()
                                       orderby r.AdditionalYn, r.PersonType, r.ProductRangeCode
                                       select new ProductRangesInfo
                        {
                            Range_Id = r.VoyagerProductRange_Id,
                            //Capacity = ((r.Quantity ?? 0) == 0) ? "" : r.Quantity.ToString(),
                            Capacity = r.Quantity,
                            ChargeBasis = r.PersonType ?? "",
                            Description = r.ProductRangeName ?? "",
                            isSupplement = r.AdditionalYn ?? false,
                            MaxAge = r.Agemax ?? "",
                            MinAge = r.Agemin ?? "",
                            Name = r.ProductRangeCode ?? "",
                            Menu = (result.Type.ToLower() == "meal") ? r.ProductMenu_Id : null
                        }).ToList();

                        if (rngInfo.Count > 0)
                        {
                            if (result.Type.ToLower() == "meal")
                            {
                                foreach (ProductRangesInfo pr in rngInfo)
                                {
                                    if (pr.Menu != null)
                                    {
                                        var vrMenu = (from m in _MongoContext.mDefProductMenu.AsQueryable()
                                                      where m.ProductMenu_Id.ToLower() == pr.Menu.ToLower()
                                                      select new { Menu = m.ProductMenuDesc }
                                                      ).FirstOrDefault();

                                        if (vrMenu != null && vrMenu.Menu != null)
                                        {
                                            pr.Menu = vrMenu.Menu.Trim();
                                        }
                                    }
                                }
                            }
                            cat.Ranges = rngInfo;
                        }
                    }
                    result.Cateogry = catInfo;
                }


                //response.Product = result;
            }

            return(result);
        }
Beispiel #3
0
        public async Task <IActionResult> GetProductDetail([FromBody] ProductDetailReq request)
        {
            var response = new ProductDetailRes();

            try
            {
                if (!ModelState.IsValid)
                {
                    response.ResponseStatus.Status       = "Failure";
                    response.ResponseStatus.ErrorMessage = "Request is not valid";
                    return(BadRequest(response.ResponseStatus));
                }
                else
                {
                    if (request != null)
                    {
                        if (!string.IsNullOrWhiteSpace(request.Product_Id))
                        {
                            Guid Product_Id = Guid.Empty;
                            if (Guid.TryParse(request.Product_Id, out Product_Id))
                            {
                                if (!(Product_Id == Guid.Empty))
                                {
                                    var result = await _productRepository.GetProductDetail(request);

                                    if (result != null)
                                    {
                                        response.ResponseStatus.Status = "Success";
                                        response.Product = result;
                                    }
                                    else
                                    {
                                        response.ResponseStatus.Status       = "Failure";
                                        response.ResponseStatus.ErrorMessage = "No Records Found.";
                                        return(NotFound(response.ResponseStatus));
                                    }
                                }
                                else
                                {
                                    response.ResponseStatus.Status       = "Failure";
                                    response.ResponseStatus.ErrorMessage = "InValid Product Id";
                                    return(BadRequest(response.ResponseStatus));
                                }
                            }
                            else
                            {
                                response.ResponseStatus.Status       = "Failure";
                                response.ResponseStatus.ErrorMessage = "InValid Product Id";
                                return(BadRequest(response.ResponseStatus));
                            }
                        }
                        else
                        {
                            response.ResponseStatus.Status       = "Failure";
                            response.ResponseStatus.ErrorMessage = "Product Id cannot be blank";
                            return(BadRequest(response.ResponseStatus));
                        }
                    }
                    else
                    {
                        response.ResponseStatus.Status       = "Failure";
                        response.ResponseStatus.ErrorMessage = "Product Id cannot be blank.";
                        return(BadRequest(response.ResponseStatus));
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "An error occurs " + ex.Message.ToString();
                return(BadRequest(response.ResponseStatus));
            }
            return(Ok(response));
        }