public ResponseDetail saveOfferDynamicNew(Offer offerDetail) { ResponseDetail objResponse = new ResponseDetail(); try { using (var entity = new InventoryEntities(enttConstr)) { VisionOffer offer = new VisionOffer(); if (offerDetail.ActionName.ToLower() == "edit") { offer = (from r in entity.VisionOffers where r.OfferId == offerDetail.AID select r).FirstOrDefault(); } var SplitDate = offerDetail.OfferFromDtStr.Split('-'); string NewDate = SplitDate[1] + "/" + SplitDate[0] + "/" + SplitDate[2]; offer.OfferFromDt = Convert.ToDateTime(DateTime.ParseExact(NewDate, "MM/dd/yyyy", CultureInfo.InvariantCulture)); SplitDate = offerDetail.OfferToDtStr.Split('-'); NewDate = SplitDate[1] + "/" + SplitDate[0] + "/" + SplitDate[2]; offer.OfferToDt = Convert.ToDateTime(DateTime.ParseExact(NewDate, "MM/dd/yyyy", CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(offerDetail.IdDateStr)) { SplitDate = offerDetail.IdDateStr.Split('-'); NewDate = SplitDate[1] + "/" + SplitDate[0] + "/" + SplitDate[2]; offer.IdDate = Convert.ToDateTime(DateTime.ParseExact(NewDate, "MM/dd/yyyy", CultureInfo.InvariantCulture)); } offer.ActiveStatus = offerDetail.ActiveStatus; offer.OfferExceptSubCat = "0"; offer.OfferBillType = offerDetail.OfferBillType; offer.OfferOnBV = offerDetail.OfferOnBV ?? 0; offer.OfferOnValue = offerDetail.OfferOnValue; offer.IsPVApplicable = offerDetail.ExtraPVApplicable; if (offer.IsPVApplicable == "Y") { offer.ExtraPV = offerDetail.PVValue; } else { offer.ExtraPV = 0; } offer.ForNewIds = offerDetail.ForNewIds; offer.IdStaus = string.IsNullOrEmpty(offerDetail.IdStaus)?"A": offerDetail.IdStaus; offer.OfferType = offerDetail.OfferType; offer.IdDays = offerDetail.IdDays; offer.OfferBillType = offerDetail.OfferBillType; offer.OfferName = offerDetail.OfferName; offer.ConfFreeProdIDs = ""; offer.ConfFreeProdQtys = ""; offer.FreeProdIDs = ""; offer.Remarks = offerDetail.Remark; offer.ContinueForMonth = offerDetail.ForMonth; offer.CheckFirstBillWith = string.IsNullOrEmpty(offerDetail.checkBillWith) ?"A" : offerDetail.checkBillWith; offer.CombineWithOffer = offerDetail.CombineWithOffer; offer.CBAmount = offerDetail.CBAmount ?? 0; offer.OfferFrequency = offerDetail.OfferFrequncy; if (offer.OfferBillType.ToLower() == "all") { offer.SortFirstBy = "V"; } else { offer.SortFirstBy = "B"; } offer.OfferDatePart = offerDetail.OfferDatePart; if (offerDetail.OfferDatePart == "D") { offer.OfferStartDay = offerDetail.OfferStartDay; offer.OfferEndDay = offerDetail.OfferEndDay; } else { offer.OfferStartDay = 1; offer.OfferEndDay = 31; } int maxaid = 0; if (offerDetail.ActionName.ToLower() == "add") { maxaid = (from r in entity.VisionOffers select r.OfferId).DefaultIfEmpty(0).Max(); maxaid += 1; offer.OfferId = maxaid; entity.VisionOffers.Add(offer); } else { maxaid = offerDetail.AID; List <VisionOfferProduct> offerproduct = (from r in entity.VisionOfferProducts where r.OfferID == maxaid select r).ToList(); foreach (var record in offerproduct) { entity.VisionOfferProducts.Remove(record); } } foreach (var product in offerDetail.objProductList) { VisionOfferProduct prod = new VisionOfferProduct(); prod.ProdID = product.ProductCode.ToString(); prod.ProdName = product.ProductName.ToString(); prod.Qty = product.Qty; prod.OfferID = maxaid; prod.OfferPV = product.PVValue; prod.OfferPVPer = product.PVPer; prod.RectimeStamp = DateTime.Now; prod.ActiveStatus = "Y"; prod.IsConfirm = product.Confirm ?? "N"; prod.IsBuyProduct = product.IsParent ? "Y" : "N"; prod.OnMRP = product.OnMRP ?? "N"; prod.IsBVApplied = product.IsBvApplied ?? "N"; prod.scheme = product.Scheme; prod.discount = product.Discount; prod.discountPer = product.DiscountPer; prod.ForRupee = product.Rupee; prod.IncludeInOffer = product.IncludeInOffer; entity.VisionOfferProducts.Add(prod); } int i = entity.SaveChanges(); if (i > 0) { objResponse.ResponseMessage = "Saved Successfully!"; objResponse.ResponseStatus = "OK"; } else { objResponse.ResponseMessage = "Something went wrong!"; objResponse.ResponseStatus = "FAILED"; } } } catch (Exception ex) { objResponse.ResponseMessage = "Something went wrong!"; objResponse.ResponseStatus = "FAILED"; } return(objResponse); }
public ResponseDetail CheckForOfferNew(DistributorBillModel objModel) { ResponseDetail objResponse = new ResponseDetail(); try { VisionOffer monthOfferList = new VisionOffer(); VisionOffer EarlyRiserOffer = null; VisionOffer FirstBillOffer = null; var CurrentDate = DateTime.Now; using (var entity = new InventoryEntities(enttConstr)) { string OfferDatePart = ""; int OfferID = 0; string FreeProdIDs = ""; string FreeProdQtys = ""; string confProdIDs = ""; string ConfProdQtys = ""; string offerbillvalue = "0"; //if (objModel.objCustomer.IsFirstBill) //{ if (!string.IsNullOrEmpty(objModel.objCustomer.Doj)) { DateTime dateofjoining = Convert.ToDateTime(objModel.objCustomer.Doj); DateTime checkDate = dateofjoining.AddDays(30); //if (CurrentDate <= checkDate) //{ //FirstBillOffer = (from r in entity.VisionOffers where r.OfferType.ToUpper() == "OFFERONVALUE" && r.OfferBillType.ToUpper()=="FIRSTBILL" && r.ActiveStatus.ToUpper() == "Y" && r.SortFirstBy.ToLower() == "B" && r.OfferOnValue <= objModel.objProduct.TotalNetPayable && r.OfferOnBV <= objModel.objProduct.TotalBV select r).OrderByDescending(o => o.OfferOnBV).FirstOrDefault(); FirstBillOffer = (from r in entity.VisionOffers where r.OfferType.ToUpper() == "OFFERONVALUE" && r.ActiveStatus.ToUpper() == "Y" && r.SortFirstBy.ToUpper() == "B" && r.OfferOnValue <= objModel.objProduct.TotalNetPayable && r.OfferOnBV <= objModel.objProduct.TotalBV select r).OrderByDescending(o => o.OfferOnBV).FirstOrDefault(); if (FirstBillOffer != null) { if (CurrentDate.Date >= FirstBillOffer.OfferFromDt.Date && CurrentDate.Date <= FirstBillOffer.OfferToDt.Date) { objResponse.ResponseStatus = "Success"; } OfferDatePart = FirstBillOffer.OfferDatePart; OfferID = FirstBillOffer.OfferId; FreeProdIDs = FirstBillOffer.FreeProdIDs; FreeProdQtys = FirstBillOffer.FreeProdQtys.ToString(); confProdIDs = FirstBillOffer.ConfFreeProdIDs; ConfProdQtys = FirstBillOffer.ConfFreeProdQtys; offerbillvalue = FirstBillOffer.OfferOnValue.ToString(); } //} } //} if (FirstBillOffer == null) { EarlyRiserOffer = (from r in entity.VisionOffers where r.OfferType.ToUpper() == "OFFERONVALUE" && r.ActiveStatus.ToUpper() == "Y" && r.SortFirstBy.ToUpper() != "B" && r.OfferDatePart == "D" && r.OfferOnValue <= objModel.objProduct.TotalNetPayable && r.OfferOnBV <= objModel.objProduct.TotalBV select r).OrderByDescending(o => o.OfferOnValue).FirstOrDefault(); if (EarlyRiserOffer != null) { if (CurrentDate.Date >= EarlyRiserOffer.OfferFromDt.Date && CurrentDate.Date <= EarlyRiserOffer.OfferToDt.Date) { if (CurrentDate.Date.Day >= EarlyRiserOffer.OfferStartDay && CurrentDate.Date.Day <= EarlyRiserOffer.OfferEndDay) { objResponse.ResponseStatus = "Success"; OfferDatePart = EarlyRiserOffer.OfferDatePart; OfferID = EarlyRiserOffer.OfferId; FreeProdIDs = EarlyRiserOffer.FreeProdIDs; FreeProdQtys = EarlyRiserOffer.FreeProdQtys.ToString(); confProdIDs = EarlyRiserOffer.ConfFreeProdIDs; ConfProdQtys = EarlyRiserOffer.ConfFreeProdQtys; offerbillvalue = EarlyRiserOffer.OfferOnValue.ToString(); } } } else { monthOfferList = (from r in entity.VisionOffers where r.OfferType.ToUpper() == "OFFERONVALUE" && r.ActiveStatus.ToUpper() == "Y" && r.SortFirstBy.ToUpper() != "B" && r.OfferDatePart == "R" && r.OfferOnValue <= objModel.objProduct.TotalNetPayable && r.OfferOnBV <= objModel.objProduct.TotalBV select r).OrderByDescending(o => o.OfferOnValue).FirstOrDefault(); if (monthOfferList != null) { if (CurrentDate.Date >= monthOfferList.OfferFromDt.Date && CurrentDate.Date <= monthOfferList.OfferToDt.Date) { objResponse.ResponseStatus = "Success"; } OfferDatePart = monthOfferList.OfferDatePart; OfferID = monthOfferList.OfferId; FreeProdIDs = monthOfferList.FreeProdIDs; FreeProdQtys = monthOfferList.FreeProdQtys.ToString(); confProdIDs = monthOfferList.ConfFreeProdIDs; ConfProdQtys = monthOfferList.ConfFreeProdQtys; offerbillvalue = monthOfferList.OfferOnValue.ToString(); } } } if (objResponse.ResponseStatus == "Success") { var freeproduct = FreeProdIDs.Split(','); string productList = string.Empty; //string Quant = string.Empty; foreach (var prod in freeproduct) { if (prod != "") { var product = (from r in entity.M_ProductMaster where r.ProdId == prod select r.ProductName).FirstOrDefault(); productList += product + "~" + prod + ","; } } if (productList.Length > 0) { productList = productList.Substring(0, productList.Length - 1); } string confproductList = ""; string confproductQtyList = ""; if (confProdIDs != "") { string[] confproduct = confProdIDs.Split(','); string[] confproductQty = ConfProdQtys.Split(','); for (int i = 0; i < confproduct.Length; i++) { string ProdID_ = confproduct[i]; var product = (from r in entity.M_ProductMaster where r.ProdId == ProdID_ select r.ProductName).FirstOrDefault(); confproductList += product + "~" + confproduct[i] + ","; confproductQtyList += confproductQty[i].ToString() + ","; } confproductList = confproductList.Substring(0, confproductList.Length - 1); } objResponse.ResponseMessage = OfferDatePart + "δ" + OfferID.ToString() + "δ" + productList + "δ" + FreeProdQtys.ToString() + "δ" + confproductList + "δ" + confproductQtyList + "δ" + offerbillvalue; } else { objResponse.ResponseMessage = "NoOffer"; } } } catch (Exception ex) { objResponse.ResponseStatus = "FAILED"; objResponse.ResponseMessage = "Something went wrong"; } return(objResponse); }