public JsonResult SetPositionPrices(PositionPricesViewModel model) { PositionPriceSetReq request = new PositionPriceSetReq(); PositionPriceSetRes response = new PositionPriceSetRes(); if (model.StandardPrice) { var ProdRangeList = model.PositionPricesData.Select(a => new { a.ProductRangeId }).Distinct().ToList(); foreach (var item in ProdRangeList) { var data = model.PositionPricesData.Where(a => a.Period.ToUpper() == "ALL" && a.ProductRangeId == item.ProductRangeId).FirstOrDefault(); model.PositionPricesData.Where(a => a.Period.ToUpper() != "ALL" && a.ProductRangeId == item.ProductRangeId).ToList() .ForEach(y => y.BudgetPrice = data.BudgetPrice); } //var res = model.PositionPricesData.Where(x => x.Period.ToUpper() == "ALL").FirstOrDefault(); //model.PositionPricesData.Where(x => x.Period.ToUpper() != "ALL").ToList().ForEach(y => y.BudgetPrice = res.BudgetPrice); } List <mPositionPrice> lstPositionPrices = new List <mPositionPrice>(); foreach (var objModel in model.PositionPricesData.Where(x => x.Period.ToUpper() != "ALL")) { var obj = new mPositionPrice { PositionPriceId = objModel.PositionPriceId, BudgetPrice = objModel.BudgetPrice, PositionId = objModel.PositionId, CreateUser = ckUserEmailId, EditUser = ckUserEmailId }; if (objModel.Period == null || Convert.ToDateTime(objModel.Period) == DateTime.MinValue) { obj.Period = null; } else { obj.Period = Convert.ToDateTime(objModel.Period); } lstPositionPrices.Add(obj); } request.StandardPrice = model.StandardPrice; request.PositionPrice = lstPositionPrices; request.IsClone = model.IsClone; request.QRFID = model.QRFID; request.VoyagerUserID = ckLoginUser_Id; response = positionProviders.SetPostionPrices(request, token).Result; if (response != null) { if (response.ResponseStatus.Status.ToLower() == "success") { return(Json(new { status = "success", positionid = response.PositionId, productid = response.ProductId, positionname = response.PositionName })); } } return(Json(new { status = "failure", positionid = "", productid = "", positionname = "" })); }
public ActionResult GetPositionPricesPartView(PositionPriceGetReq request) { PositionPriceGetRes response = new PositionPriceGetRes(); request.LoginUser = ckUserEmailId; response = positionProviders.GetPostionPrices(request, token).Result; var contractId = response.PositionPrice.Where(a => !string.IsNullOrEmpty(a.ContractId)).Select(b => b.ContractId).FirstOrDefault(); if (!string.IsNullOrEmpty(contractId)) { ViewBag.IsContractExist = true; } var dateRangeCount = response.PositionPrice.Select(b => b.DepartureId).Distinct().ToList().Count(); if (dateRangeCount > 1) { ViewBag.IsMultipleDateExist = dateRangeCount; } #region commented //foreach (var ProdRange in ProdRangeList) //{ // model.PositionPricesData.Add(new PositionPricesData // { // QRFID = request.QRFID, // PositionId = request.PositionId, // DepartureId = request.DepartureId, // Period = "ALL", // PaxSlab = "ALL", // Type = "ALL", // ProductCategory = "ALL", // BudgetPrice = ProdRange.BudgetPrice, // ContractPrice = ProdRange.ContractPrice, // BuyCurrency = ProdRange.BuyCurrency, // ProductRange = ProdRange.ProductRange, // ProductRangeId = ProdRange.ProductRangeId, // ProductRangeCode = ProdRange.ProductRangeCode // }); //} //foreach (var objModel in response.PositionPrice) //{ // //if (model.StandardPrice && model.PositionPricesData.Count > 0 && model.PositionPricesData[0].BudgetPrice == 0.00) // // model.PositionPricesData[0].BudgetPrice = objModel.BudgetPrice; // var obj = new PositionPricesData // { // PositionPriceId = objModel.PositionPriceId, // QRFID = objModel.QRFID, // PositionId = objModel.PositionId, // DepartureId = objModel.DepartureId, // Period = objModel.Period.ToString(), // PaxSlabId = objModel.PaxSlabId, // PaxSlab = objModel.PaxSlab, // Type = objModel.Type, // RoomId = objModel.RoomId, // IsSupplement = objModel.IsSupplement, // SupplierId = objModel.SupplierId, // Supplier = objModel.Supplier, // ProductCategoryId = objModel.ProductCategoryId, // ProductCategory = objModel.ProductCategory, // ProductRangeId = objModel.ProductRangeId, // ProductRange = objModel.ProductRange, // ProductRangeCode = objModel.ProductRangeCode, // ContractPrice = objModel.ContractPrice, // ContractId = objModel.ContractId, // BuyCurrencyId = objModel.BuyCurrencyId, // BuyCurrency = objModel.BuyCurrency, // BudgetPrice = objModel.BudgetPrice, // BuyPrice = objModel.BuyPrice, // MarkupAmount = objModel.MarkupAmount, // SellCurrencyId = objModel.SellCurrencyId, // SellCurrency = objModel.SellCurrency, // SellNetPrice = objModel.SellNetPrice, // TaxAmount = objModel.TaxAmount, // SellPrice = objModel.SellPrice, // ExchangeRateId = objModel.ExchangeRateId, // ExchangeRatio = objModel.ExchangeRatio // }; // model.PositionPricesData.Add(obj); //} #endregion PositionPricesViewModel model = new PositionPricesViewModel { StandardPrice = (response.StandardPrice == null || response.StandardPrice == true) ? true : false }; var ProdRangeList = response.PositionPrice.Select(a => new { a.ProductRange, a.ProductRangeId }).Distinct().ToList(); foreach (var ProdRange in ProdRangeList) { var IsExist = model.PositionPricesData.Where(a => a.ProductRangeId == ProdRange.ProductRangeId).FirstOrDefault(); if (IsExist == null) { var PriceList = response.PositionPrice.Where(a => a.ProductRangeId == ProdRange.ProductRangeId).Select(a => new { a.ProductRange, a.ProductRangeId, a.BudgetPrice, a.ContractPrice, a.ContractId, a.BuyCurrency, a.ProductRangeCode }).Distinct().ToList(); if (PriceList?.Count == 1) { model.PositionPricesData.AddRange(PriceList.Select(a => new PositionPricesData { QRFID = request.QRFID, PositionId = request.PositionId, DepartureId = request.DepartureId, Period = "ALL", PaxSlab = "ALL", Type = "ALL", ProductCategory = "ALL", BudgetPrice = a.BudgetPrice, ContractPrice = a.ContractPrice, IsContractExist = string.IsNullOrEmpty(a.ContractId) ? false : true, BuyCurrency = a.BuyCurrency, ProductRange = a.ProductRange, ProductRangeId = a.ProductRangeId, ProductRangeCode = a.ProductRangeCode })); } else { model.PositionPricesData.Add(new PositionPricesData { QRFID = request.QRFID, PositionId = request.PositionId, DepartureId = request.DepartureId, Period = "ALL", PaxSlab = "ALL", Type = "ALL", ProductCategory = "ALL", BudgetPrice = 0, ContractPrice = 0, IsContractExist = string.IsNullOrEmpty(PriceList[0].ContractId) ? false : true, BuyCurrency = PriceList[0].BuyCurrency, ProductRange = PriceList[0].ProductRange, ProductRangeId = PriceList[0].ProductRangeId, ProductRangeCode = PriceList[0].ProductRangeCode }); } } } model.PositionPricesData.AddRange(response.PositionPrice.Select(a => new PositionPricesData { PositionPriceId = a.PositionPriceId, QRFID = a.QRFID, PositionId = a.PositionId, DepartureId = a.DepartureId, Period = a.Period.ToString(), PaxSlabId = a.PaxSlabId, PaxSlab = a.PaxSlab, Type = a.Type, RoomId = a.RoomId, IsSupplement = a.IsSupplement, SupplierId = a.SupplierId, Supplier = a.Supplier, ProductCategoryId = a.ProductCategoryId, ProductCategory = a.ProductCategory, ProductRangeId = a.ProductRangeId, ProductRange = a.ProductRange, ProductRangeCode = a.ProductRangeCode, ContractPrice = a.ContractPrice, IsContractExist = string.IsNullOrEmpty(a.ContractId) ? false : true, ContractId = a.ContractId, BuyCurrencyId = a.BuyCurrencyId, BuyCurrency = a.BuyCurrency, BudgetPrice = a.BudgetPrice, BuyPrice = a.BuyPrice, MarkupAmount = a.MarkupAmount, SellCurrencyId = a.SellCurrencyId, SellCurrency = a.SellCurrency, SellNetPrice = a.SellNetPrice, TaxAmount = a.TaxAmount, SellPrice = a.SellPrice, ExchangeRateId = a.ExchangeRateId, ExchangeRatio = a.ExchangeRatio })); model.IsSalesOfficeUser = response.IsSalesOfficeUser; return(PartialView("_PositionPrices", model)); }