public async Task <PromotionDetailsModel> Get(string promotionId) { if (!await this.db.Promotions.AnyAsync(p => p.Id == promotionId)) { throw new ArgumentException(ErrorMessages.InvalidPromotionId); } PromotionDetailsModel promotion = this.db.Promotions .Where(p => p.Id == promotionId) .ProjectTo <PromotionDetailsModel>() .FirstOrDefault(); return(promotion); }
public object GetPromotionInformation(long productId, long promotionMasterId, int quantity) { try { var data = _entities.promotion_master.FirstOrDefault( p => p.product_id == productId && p.promotion_master_id == promotionMasterId && p.lifting_quantity_for_promotion <= quantity); if (data.promotion_type == "Product") { if (data != null) { var actualGiftQuantity = (int)(quantity / data.lifting_quantity_for_promotion); var xxx = (from pd in _entities.promotion_details join pro in _entities.products on pd.product_id equals pro.product_id join cat in _entities.product_category on pd.product_category_id equals cat.product_category_id //added mohi uddin(04.04.2017) join u in _entities.units on pro.unit_id equals u.unit_id into Tempu from u in Tempu.DefaultIfEmpty() join b in _entities.brands on pro.brand_id equals b.brand_id into Tempb from b in Tempb.DefaultIfEmpty() select new { promotion_details_id = pd.promotion_details_id, promotion_master_id = pd.promotion_master_id, product_id = pro.product_id, product_name = pro.product_name, product_category_id = cat.product_category_id, product_category_name = cat.product_category_name, gift_quantity = pd.gift_quantity, has_serial = pro.has_serial, //04.04.2017 unit_id = pro.unit_id, unit_name = u.unit_name, brand_id = pro.brand_id, brand_name = b.brand_name }).Where(p => p.promotion_master_id == promotionMasterId).ToList(); var promotionDetailsList = new List <PromotionDetailsModel>(); foreach (var item in xxx) { var promotionDetails = new PromotionDetailsModel(); promotionDetails.promotion_details_id = item.promotion_details_id; promotionDetails.promotion_master_id = item.promotion_master_id; promotionDetails.product_category_id = item.product_category_id; promotionDetails.product_category_name = item.product_category_name; promotionDetails.product_id = item.product_id; promotionDetails.product_name = item.product_name; promotionDetails.gift_quantity = item.gift_quantity * actualGiftQuantity; promotionDetails.has_serial = item.has_serial; //04.04.2017 promotionDetails.unit_id = (int?)item.unit_id; promotionDetails.unit_name = item.unit_name; promotionDetails.brand_id = (int?)item.brand_id; promotionDetails.brand_name = item.brand_name; promotionDetailsList.Add(promotionDetails); } return(promotionDetailsList); } else { return(false); } } else if (data.promotion_type == "Incentive") { return(data); } else { return(false); } } catch (Exception ex) { return(false); } }