/// <summary>
 /// Product Search Constructor
 /// </summary>
 /// <param name="configuration"></param>
 public ProductPDP(IConfiguration configuration) : base(configuration)
 {
     _configuration   = configuration;
     productLibrary   = new ProductLibrary(_configuration);
     positionLibrary  = new PositionLibrary(_configuration);
     coCommonLibrary  = new COCommonLibrary(_configuration);
     productProviders = new ProductProviders(_configuration);
 }
        public IActionResult GetProductSRPDetail(string CompanyId)
        {
            ProductsSRPViewModel model = new ProductsSRPViewModel();

            #region Get Company info
            AgentGetReq request = new AgentGetReq()
            {
                CompanyId = CompanyId
            };
            AgentGetRes response = agentProviders.GetAgentDetailedInfo(request, token).Result;
            var         product  = response.AgentDetails.Products.Where(x => x.Supplier_Id == CompanyId).FirstOrDefault();
            #endregion

            if (product != null && !string.IsNullOrWhiteSpace(product.Product_Id))
            {
                #region Get ProductSRPDetails
                ProductProviders    productProviders = new ProductProviders(_configuration);
                ProductSRPSearchReq objProdReq       = new ProductSRPSearchReq()
                {
                    ProdId = product.Product_Id
                };
                ProductSRPSearchRes objProdRes = productProviders.GetProductSRPDetails(objProdReq, token).Result;
                var productSRPDetails          = objProdRes.ProductSearchDetails.Select(a => new ProductSRPDetails
                {
                    Address           = a.Address,
                    BdgPriceCategory  = a.BdgPriceCategory,
                    Chain             = a.Chain,
                    CityName          = a.CityName,
                    CountryName       = a.CountryName,
                    DefaultSupplier   = a.DefaultSupplier,
                    HotelImageURL     = a.HotelImageURL,
                    HotelType         = a.HotelType,
                    Location          = a.Location,
                    PostCode          = a.PostCode,
                    ProdDesc          = a.ProdDesc,
                    ProdName          = a.ProdName,
                    ProductCode       = a.ProductCode,
                    ProductType       = a.ProductType,
                    StarRating        = a.StarRating,
                    Street            = a.Street,
                    VoyagerProduct_Id = a.VoyagerProduct_Id,
                    ProductType_Id    = a.ProductType_Id
                }).ToList();

                model.ProductSRPDetails = productSRPDetails;

                var userRoles = HttpContext.Request.Cookies["UserRoles"] ?? string.Join(",", UserRoles);
                if (userRoles != null && userRoles.Contains("Administrator"))
                {
                    model.PageName = "PrdSupplierMapping";
                }
            }
            return(PartialView("~/Areas/Product/Views/ProductSRP/_ProductInfo.cshtml", model));

            #endregion
        }
Beispiel #3
0
        public IActionResult ProductSearchResultPage(ProductSRPFilters filters)
        {
            ProductsSRPViewModel productsSRPViewModel = new ProductsSRPViewModel();
            ProductProviders     productProviders     = new ProductProviders(_configuration);
            ProductSRPSearchReq  objQRFAgentRequest   = new ProductSRPSearchReq()
            {
                ProdType       = filters.ProductType,
                ProdName       = filters.ProdName,
                ProdCode       = filters.ProdCode,
                CityName       = filters.CityName,
                Location       = filters.Location == "Select" ? null : filters.Location,
                BudgetCategory = filters.BudgetCategory == "Select" ? null : filters.BudgetCategory,
                Chain          = filters.Chain,
                StarRating     = filters.StarRating,
                Status         = filters.Status
            };
            ProductSRPSearchRes objProposalRes = productProviders.GetProductSRPDetails(objQRFAgentRequest, token).Result;

            productsSRPViewModel.ProductSRPDetails = objProposalRes.ProductSearchDetails.Select(a => new ProductSRPDetails
            {
                Address           = a.Address,
                BdgPriceCategory  = a.BdgPriceCategory,
                Chain             = a.Chain,
                CityName          = a.CityName,
                CountryName       = a.CountryName,
                DefaultSupplier   = a.DefaultSupplier,
                DefaultSupplierId = a.DefaultSupplierId,
                HotelImageURL     = a.HotelImageURL != null ? a.HotelImageURL.Replace("resources/", "ImageResources/") : a.HotelImageURL,
                HotelType         = a.HotelType,
                Location          = a.Location,
                PostCode          = a.PostCode,
                ProdDesc          = a.ProdDesc,
                ProdName          = a.ProdName,
                ProductCode       = a.ProductCode,
                ProductType       = a.ProductType,
                StarRating        = a.StarRating,
                Street            = a.Street,
                VoyagerProduct_Id = a.VoyagerProduct_Id,
                ProductType_Id    = a.ProductType_Id
            }).ToList();

            var userRoles = HttpContext.Request.Cookies["UserRoles"] ?? string.Join(",", UserRoles);

            if (userRoles != null && userRoles.Contains("Administrator"))
            {
                productsSRPViewModel.PageName = "PrdSupplierMapping";
            }

            return(PartialView("_ProductInfo", productsSRPViewModel));
        }
        public IActionResult Accomodation()
        {
            string QRFID = Request.Query["QRFId"].ToString();
            AccomodationAmendmentVM model = new AccomodationAmendmentVM();

            model.MenuViewModel.QRFID    = QRFID;
            model.MenuViewModel.MenuName = "Accomodation";

            #region Get Costing Officer Tour Info Header By QRFId
            NewQuoteViewModel modelQuote = new NewQuoteViewModel {
                QRFID = QRFID
            };
            model.COHeaderViewModel = coCommonLibrary.GetCOTourInfoHeader(ref modelQuote, token);
            //model.MenuViewModel.EnquiryPipeline = modelQuote.mdlMenuViewModel.EnquiryPipeline;
            #endregion

            ProductProviders      productProviders = new ProductProviders(_configuration);
            ProductSRPHotelGetRes response         = productProviders.GetProductSRPHotelDetails(new ProductSRPHotelGetReq()
            {
                QRFID = QRFID
            }, token).Result;
            model.ProductSRPRouteInfo = response.ProductSRPRouteInfo;
            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> Update([FromBody] UpdateProductViewModel model)
        {
            string strRuta = _config["ProductAvatar"];

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model.Id <= 0)
            {
                return(BadRequest());
            }

            var modelo = await _context.Products.Where(x => x.Id == model.Id).Include(x => x.ProductPriceLists).Include(x => x.ProductProviders).FirstOrDefaultAsync();

            if (modelo == null)
            {
                return(BadRequest("Producto inexistente"));
            }

            modelo.Awaiting           = model.Awaiting;
            modelo.BrandId            = model.BrandId;
            modelo.CategoryId         = model.CategoryId;
            modelo.CheckStock         = model.CheckStock;
            modelo.Codigo             = model.Codigo;
            modelo.Cost               = model.Cost;
            modelo.Description        = model.Description;
            modelo.Discount           = model.Discount;
            modelo.ExchangeCurrencyId = model.ExchangeCurrencyId;
            modelo.Gain               = model.Gain;
            modelo.InStock            = model.InStock;
            modelo.LocationId         = model.LocationId;
            modelo.Name               = model.Name;
            modelo.NameShort          = model.NameShort;
            modelo.OutOfStock         = model.OutOfStock;
            modelo.Price              = model.Price;
            modelo.Stock              = model.Stock;
            modelo.StockMin           = model.StockMin;
            modelo.SubCategoryId      = model.SubCategoryId;



            var providerToBeAdded = model.Providers.Where(a => modelo.ProductProviders.All(
                                                              b => b.ProviderId != a));


            var providerToBeDeleted = modelo.ProductProviders.Where(a => model.Providers.All(
                                                                        b => b != a.ProviderId));


            foreach (var prov in providerToBeDeleted)
            {
                modelo.ProductProviders.Remove(prov);
            }

            foreach (var prov in providerToBeAdded)
            {
                ProductProviders productProviders = new ProductProviders
                {
                    ProviderId = prov,
                    ProductId  = modelo.Id
                };

                modelo.ProductProviders.Add(productProviders);
            }


            foreach (var price in model.ProductPriceLists)
            {
                //Nuevos
                if (price.IsNew && price.IsRemoved == false)
                {
                    ProductPriceLists productPriceLists = new ProductPriceLists
                    {
                        PriceListId = price.PriceList,
                        ProductId   = modelo.Id,
                        Price       = price.Price
                    };
                    modelo.ProductPriceLists.Add(productPriceLists);
                }
                else
                {
                    if (!price.IsNew)
                    {
                        ProductPriceLists productPriceLists = modelo.ProductPriceLists.Where(x => x.Id == price.Id).FirstOrDefault();
                        //Borrados

                        if (price.IsNew == false && price.IsRemoved)
                        {
                            modelo.ProductPriceLists.Remove(productPriceLists);
                        }
                        else
                        {
                            //Actualizo
                            productPriceLists.Price       = price.Price;
                            productPriceLists.PriceListId = price.PriceList;
                        }
                    }
                }
            }

            ////Guardo el avatar
            if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo)))
            {
                strRuta = strRuta + "//" + modelo.Id.ToString() + "//" + model.LogoName;
                System.IO.FileInfo file = new System.IO.FileInfo(strRuta);
                file.Directory.Create();
                System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1)));
                modelo.Logo = strRuta;
            }


            _context.Entry(modelo).State = EntityState.Modified;

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                //Guardar Exception
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
Beispiel #6
0
        public async Task <IActionResult> Create([FromBody] CreateProductViewModel model)
        {
            string strRuta = _config["ProductAvatar"];


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!string.IsNullOrEmpty(model.Codigo))
            {
                //Verifico si el codigo existe
                if (_context.Products.Where(x => x.Codigo == model.Codigo.ToUpper().Trim()).Any())
                {
                    return(BadRequest(new { Message = "Código repetido" }));
                }
            }



            Product modelo = new Product
            {
                Awaiting           = model.Awaiting ?? false,
                BrandId            = model.BrandId,
                CategoryId         = model.CategoryId,
                Codigo             = model.Codigo?.ToUpper().Trim(),
                CompanyId          = model.CompanyId,
                Cost               = model.Cost,
                DateInitial        = DateTime.Now,
                Description        = model.Description,
                Discount           = model.Discount ?? 0,
                Enabled            = true,
                ExchangeCurrencyId = model.ExchangeCurrencyId,
                Gain               = model.Gain,
                InStock            = model.InStock ?? false,
                LocationId         = model.LocationId,
                Name               = model.Name?.Trim(),
                NameShort          = model.NameShort?.Trim(),
                OutOfStock         = model.OutOfStock ?? false,
                Price              = model.Price ?? 0,
                Stock              = model.Stock,
                StockMin           = model.StockMin,
                SubCategoryId      = model.SubCategoryId,
                CheckStock         = model.CheckStock ?? false,
                ProductProviders   = new List <ProductProviders>(),
                ProductPriceLists  = new List <ProductPriceLists>()
            };

            foreach (var prov in model.Providers)
            {
                ProductProviders productProviders = new ProductProviders
                {
                    ProviderId = prov,
                    ProductId  = modelo.Id
                };

                modelo.ProductProviders.Add(productProviders);
            }

            foreach (var price in model.ProductPriceLists)
            {
                ProductPriceLists productPriceLists = new ProductPriceLists
                {
                    PriceListId = price.PriceList,
                    ProductId   = modelo.Id,
                    Price       = price.Price
                };
                modelo.ProductPriceLists.Add(productPriceLists);
            }

            _context.Products.Add(modelo);
            try
            {
                await _context.SaveChangesAsync();



                if (modelo.Id > 0)
                {
                    //Codigo
                    if (string.IsNullOrEmpty(modelo.Codigo))
                    {
                        modelo.Codigo = modelo.Id.ToString();
                    }

                    //Guardo el avatar
                    if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo)))
                    {
                        strRuta = strRuta + "//" + modelo.Id.ToString() + "//" + model.LogoName;
                        System.IO.FileInfo file = new System.IO.FileInfo(strRuta);
                        file.Directory.Create();
                        System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1)));
                        modelo.Logo = strRuta;
                    }
                }

                _context.Entry(modelo).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }