Exemple #1
0
        public async Task <ProductBrandSearchDetailDTO> GetBrandDetails(int?ProductBrandId)
        {
            ProductBrandSearchDetailDTO output = new ProductBrandSearchDetailDTO();
            string apiUrl       = $"/api/v1/Brand/GetBrandDetails";
            string paramRequest = $"?ProductBrandId={ProductBrandId}";
            var    response     = await _client.GetAsync(apiUrl + paramRequest);

            if (response.IsSuccessStatusCode)
            {
                string responseStream = await response.Content.ReadAsStringAsync();

                output = JsonConvert.DeserializeObject <ProductBrandSearchDetailDTO>(responseStream);
            }
            return(output);
        }
Exemple #2
0
        public async Task <ProductBrandSearchDetailDTO> GetBrandDetailByUserId()
        {
            ProductBrandSearchDetailDTO output = new ProductBrandSearchDetailDTO();
            var jwt = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.Request.Cookies["JWT"]);

            if (jwt != null)
            {
                _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt.JWT);
                string apiUrl       = $"/api/v1/Brand/GetBrandDetailByUserId";
                string paramRequest = $"?userId={jwt.UserId}";
                var    response     = await _client.GetAsync(apiUrl + paramRequest);

                if (response.IsSuccessStatusCode)
                {
                    string responseStream = await response.Content.ReadAsStringAsync();

                    output = JsonConvert.DeserializeObject <ProductBrandSearchDetailDTO>(responseStream);
                }
            }
            return(output);
        }
Exemple #3
0
        public async Task <ProductBrandSearchDetailDTO> GetBrandDetailByUserId(string userId)
        {
            var output = new ProductBrandSearchDetailDTO();

            try
            {
                var pUserId = Guid.Parse(userId);
                var result  = await _repoWrapper.Brand.FirstOrDefaultAsync(p => p.CreateBy == pUserId);

                if (result != null)
                {
                    output = _mapper.Map <ProductBrandSearchDetailDTO>(result);
                    var Location = await _repoWrapper.Location.FirstOrDefaultAsync(p => p.Location_ID == output.LocationId);

                    if (Location != null)
                    {
                        output.LocationName = Location.Name;
                    }
                    var CountryName = await _repoWrapper.Country.FirstOrDefaultAsync(p => p.Country_ID == output.Country_ID);

                    if (CountryName != null)
                    {
                        output.CountryName = CountryName.Name;
                    }
                    var district = await _repoWrapper.Location.GetDistrictByName(output.District);

                    if (district != null)
                    {
                        output.DistrictId = district.Id;
                    }
                    //Get Năm tham gia
                    output.ProductBrandYearJoin = (int)(DateTime.Now.Year - result.CreateDate?.Year);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("BrandController: GetBrandDetail: " + ex.ToString());
            }
            return(output);
        }
Exemple #4
0
        public async Task <ProductBrandSearchDetailDTO> GetBrandDetails(int ProductBrandId)
        {
            var output = new ProductBrandSearchDetailDTO();

            try
            {
                var result = await _repoWrapper.Brand.FirstOrDefaultAsync(p => p.ProductBrand_ID == ProductBrandId);

                if (result != null)
                {
                    output = _mapper.Map <ProductBrandSearchDetailDTO>(result);
                    var Location = await _repoWrapper.Location.FirstOrDefaultAsync(p => p.Location_ID == output.LocationId);

                    if (Location != null)
                    {
                        output.LocationName = Location.Name;
                    }
                    var CountryName = await _repoWrapper.Country.FirstOrDefaultAsync(p => p.Country_ID == output.Country_ID);

                    if (CountryName != null)
                    {
                        output.CountryName = CountryName.Name;
                    }
                    var district = await _repoWrapper.Location.GetDistrictByName(output.District);

                    if (district != null)
                    {
                        output.DistrictId = district.Id;
                    }
                    if (output.ProductBrandTypeId == null)
                    {
                        output.ProductBrandTypeId = 1; // Set default nhà cc nhỏ
                    }
                    //Get Năm tham gia
                    output.ProductBrandYearJoin = (int)(DateTime.Now.Year - result.CreateDate?.Year) + 1;
                    int totalDay  = 100;
                    var prodCount = await _repoWrapper.Product.CountProductByBrand(ProductBrandId);

                    var prodQty = await _repoPaymentWrapper.PaymentServcie.FirstOrDefaultAsync(p => p.ServiceId == output.ProductBrandTypeId);

                    if (prodQty != null)
                    {
                        output.NumberPostRemain = (prodQty.ProductQty - prodCount) + "/" + prodQty.ProductQty;
                        if (output.ProductBrandTypeId != null || output.ProductBrandTypeId != 1)
                        {
                            var paymentOrder = await _repoPaymentWrapper.PaymentUpgrade.GetCurrentOrderDetail(ProductBrandId, output.ProductBrandTypeId ?? 1);

                            if (paymentOrder != null)
                            {
                                var lastBeginDate   = DateTime.Parse(paymentOrder.StartDate.ToString());
                                var lastUpgradeDate = DateTime.Parse(paymentOrder.EndDate.ToString());

                                TimeSpan diffTotalDate = lastUpgradeDate - lastBeginDate;
                                TimeSpan diffDate      = DateTime.Now - lastUpgradeDate;
                                output.TimeRankBrandRemain = Math.Abs(Math.Round(diffDate.TotalDays)).ToString() + "/" + Math.Abs(Math.Round(diffTotalDate.TotalDays)).ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("BrandController: GetBrandDetail: " + ex.ToString());
            }
            return(output);
        }