public ActionResult EditPromotion(string id, PromotionModel promotion, string productsString) { string[] productsId = productsString.Split(','); List <ProductModel> products = new List <ProductModel>(); for (int i = 0; i < productsId.Length; i++) { var target = productsId[i]; var product = ProductController.Instance.GetProduct(target); products.Add(product); } promotion.products = products; var filter = Builders <PromotionModel> .Filter.Eq("_id", ObjectId.Parse(id)); var update = Builders <PromotionModel> .Update .Set("PromotionName", promotion.PromotionName) .Set("DiscountAmount", promotion.discountAmount) .Set("Products", products) .Set("InitDate", promotion.InitDate) .Set("EndDate", promotion.EndDate); var result = promotionCollection.UpdateOne(filter, update); return(null); }
public PromotionModel GetPromotionForMembership() { PromotionModel promotion = null; try { promotion = promotionRepository .FindBy(p => p.IsActive == true && p.OnlyMembership == true && p.StartDate <= DateTime.Now && p.EndDate >= DateTime.Now) .OrderByDescending(p => p.StartDate) .Select(p => new PromotionModel { Id = p.Id, Name = p.Name, StartDate = p.StartDate, EndDate = p.EndDate, Saleoff = p.Saleoff, OnlyMembership = p.OnlyMembership, }).FirstOrDefault(); } catch (Exception ex) { throw ex; } return(promotion); }
protected void Page_Load(object sender, EventArgs e) { if (Common.CheckPermission(Common.Module_Promotion, Common.Permission_View, HttpContext.Current)) { string idstr = Request.QueryString["id"]; int id = 0; int.TryParse(idstr, out id); if (id > 0) { PromotionBLL pb = new PromotionBLL(); int total = 0; List <PromotionModel> list = new List <PromotionModel>(); pb.GetPromotionList(1, 1, id, null, null, null, out total, out list); if (list.Count == 1) { PromotionModel model = list[0]; title_txt.Text = model.Title; content_txt.Text = model.Content; date_txt.Text = string.Format("{0:yyyy-MM-dd}", model.CreateTime); } } } else { Response.Redirect("nopermission.aspx"); } }
public ActionResult Create(PromotionModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePromotions)) { return(AccessDeniedView()); } if (model.PictureId == 0) { ModelState.AddModelError("PictureId", "Picture is required"); } if (ModelState.IsValid) { model.PictureUrl = _pictureService.GetPictureUrl(model.PictureId); //model.LanguageName = _languageService.GetLanguageByCulture(model.LanguageCulture).Name; MediaHelper.UpdatePictureTransientState(0, model.PictureId, true); model.Active = model.Published; Promotion promo = model.ToEntity(); promo.CreationDate = DateTime.Now; promo.CreatedBy = User.Identity.Name; _promotionService.InsertPromotion(promo); NotifySuccess("Promotion created successfully"); return(continueEditing ? RedirectToAction("Edit", new { id = promo.Id }) : RedirectToAction("List")); } this.InitCreateEdit(); //If we got this far, something failed, redisplay form PreparePromotionModel(null, true, model); return(View(model)); }
public ActionResult Index() { var m = new PromotionModel(); UpdateModel(m); return(View(m)); }
public void AddPromotion(PromotionModel model) { try { var promotion = new Entity.Promotion { IsActive = model.IsActive, OnlyMembership = model.OnlyMembership, DiscountQuantity = model.DiscountQuantity, RequiredQuantity = model.RequiredQuantity, PromotionTypeId = model.PromotionTypeId, Saleoff = model.Saleoff, StartDate = model.StartDate, EndDate = model.EndDate, ProductPromotions = model.Products.Select(p => new Entity.ProductPromotion { IsActive = true, ProductId = p.Id }).ToList() }; promotionRepository.Insert(promotion); } catch (Exception ex) { throw ex; } }
/// <summary> /// Method to update contact details /// </summary> /// <param name="model"></param> /// <returns></returns> public PromotionModel GetCalPromotion(string Name) { PromotionModel model = new PromotionModel(); model = Mapper.Map <PromotionModel>(_context.tblBasePromotions.Where(x => x.PromotionName == Name).FirstOrDefault()); return(model); }
public IHttpActionResult GetLatestPromotion(int Type) { PromotionModel promotion = null; try { using (AppDBContext context = new AppDBContext()) { var p = new PromotionRepository(context).GetLatestPromotion(Type); if (p != null) { promotion = new PromotionModel { Id = p.Id, Title = p.Title, Header = p.Header, Description = p.Description, CreatedDate = p.CreatedDate?.ToString(Constant.DateFormatType.YYYYMMDD), Status = p.Status ?? 0, Type = ((p.Type ?? 0) == Constant.PromotionType.OFFER) ? "Offers" : "Promotions" }; } } } catch (Exception ex) { Logger.Log(typeof(PromotionController), ex.Message + ex.StackTrace, LogType.ERROR); return(InternalServerError(ex)); } return(Ok(promotion)); }
/// <summary> /// 更新促销信息 /// </summary> /// <param name="oPModel"></param> /// <returns></returns> public string SetPromotionInfo(PromotionModel oPModel) { string ret = Config.Fail; try { ret = pd.SetPromotionInfo(oPModel); int Id = 0; bool flag = Int32.TryParse(ret, out Id); if (flag && Id > 0) { if (oPModel.DealerIdList != null && oPModel.DealerIdList.Count > 0) { pd.RemovePromotionDealerInfo(oPModel.PromotionId); foreach (int dealerId in oPModel.DealerIdList) { pd.AddPromotionDealerInfo(oPModel.PromotionId, dealerId); } } return(Config.Success); } } catch (Exception ex) { WriteLog.WriteExceptionLog("PromotionBLL.SetPromotionInfo()", ex); return(Config.ExceptionMsg); } return(ret); }
public List <PromotionModel> GetPromotionList() { PromotionModel bdm; List <PromotionModel> lbdm = new List <PromotionModel>(); using (MySqlConnection conn = new MySqlConnection(constr)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = conn; cmd.CommandText = "SELECT * FROM promotion ORDER BY Id ASC"; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { bdm = new PromotionModel(); bdm.Id = Convert.ToInt32(reader["id"]); bdm.PromotionName = reader["promotionname"].ToString(); bdm.PromotionDetails = reader["promotiondetails"].ToString(); lbdm.Add(bdm); } } conn.Close(); } } return(lbdm); }
/// <summary> /// Method returns contact details /// </summary> /// <param name="id"></param> /// <returns></returns> public PromotionModel GetByNo(int id) { PromotionModel model = new PromotionModel(); model = Mapper.Map <PromotionModel>(_context.tblBasePromotions.Find(id)); return(model); }
public ActionResult List() { var m = new PromotionModel(); UpdateModel(m); return(PartialView("List", m)); }
public PromotionCommand(PromotionModel model, PromotionAction action) { this.PromotionModel = model; this.promotionAction = action; this.promotionService = new PromotionService(); this.productService = new ProductService(); }
public async Task <HttpResponseMessage> GetByIdAsync(PromotionModel _params) { var Res = Request.CreateResponse(); var Result = new Res(); try { var data = await Task.Run(() => _promotionService.GetById(_params)); if (data != null) { Result.Data = data; Result.Status = true; Result.Message = "Call API Success"; Result.StatusCode = HttpStatusCode.OK; } else { Result.Data = null; Result.Status = false; Result.Message = "Không tìm thấy dữ liệu"; Result.StatusCode = HttpStatusCode.InternalServerError; } Res.Content = new StringContent(JsonConvert.SerializeObject(Result)); return(Res); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <HttpResponseMessage> DeleteAsync(PromotionModel _param) { var Res = Request.CreateResponse(); var Result = new Res(); try { if (_param != null) { await Task.Run(() => _promotionService.Delete(_param)); Result.Status = true; Result.Message = "Xóa thành công"; Result.StatusCode = HttpStatusCode.OK; } else { Result.Status = false; Result.Message = "Xóa thất bại"; Result.StatusCode = HttpStatusCode.BadRequest; } Res.Content = new StringContent(JsonConvert.SerializeObject(Result)); return(Res); } catch (Exception ex) { Result.Status = false; Result.Message = "Có lỗi xảy ra trong quá trình xóa " + ex.Message; Result.StatusCode = HttpStatusCode.BadRequest; throw new Exception(ex.Message); } }
public void AddItemPromotionTest_addDuplicatePromotion_exceptionExpected() { PromotionModel model = new PromotionModel(new string[0]); Item item = new Item("Apple"); Dictionary<Item, Promotion> existingDictionary = new Dictionary<Item, Promotion>(); existingDictionary.Add(item, new QuantityPricePromotion(item, "[email protected]")); model.AddItemPromotion(existingDictionary, "Apple,QtyPromoPrice,[email protected]"); }
public DiscountModel(PromotionModel promotion, decimal regularItemPrice) { ThresholdQuantity = promotion.Quantity; decimal normalPrice = ThresholdQuantity * regularItemPrice; DiscountAmount = normalPrice - promotion.SalePrice; }
public async Task AddPromotion(PromotionModel model) { var entity = Mapper.Map <PromotionModel, Promotion>(model); await this.BlazorRestaurantDbContext.AddAsync(entity); await this.BlazorRestaurantDbContext.SaveChangesAsync(); }
public ActionResult AssignPending() { var m = new PromotionModel(); UpdateModel(m); m.AssignPending(); return(RedirectToAction("Index")); }
static void RunPromotionManagementProcess() { PromotionModel model = new PromotionModel(); ICommandHandler handler = new CommandHandler(); PromotionCommand promotionCmd = new PromotionCommand(model, ConsoleApp.Action.PromotionAction.ManagePromotion); CommonUtils.ExecuteCommand(handler, promotionCmd); }
public void PromotionModelConstructorTest_multipleEntries_oneEntryIsEmptyString_expectedPricingsCreated() { string[] promotions = new string[] { "Apple,QtyPromoPrice,[email protected]", " " }; PromotionModel promotionModel = new PromotionModel(promotions); Assert.AreEqual(1, promotionModel.CountOfPromotions); }
public ActionResult Export() { var m = new PromotionModel(); UpdateModel(m); return(new ExcelResult { Data = m.Export(), FileName = "promotion.xls" }); }
public void AddItemPromotionTest_addPromotion_itemAddedToDictionary() { PromotionModel model = new PromotionModel(new string[0]); Item item = new Item("Apple"); Dictionary<Item, Promotion> existingDictionary = new Dictionary<Item, Promotion>(); model.AddItemPromotion(existingDictionary, "Apple,QtyPromoPrice,[email protected]"); Assert.AreEqual(1, existingDictionary.Count); Assert.IsTrue(existingDictionary.ContainsKey(item)); Assert.IsTrue(existingDictionary[item] is QuantityPricePromotion); }
public void PromotionModelConstructorTest_multipleEntries_oneEntryIsDuplicated_expectedPricingsCreated() { string[] promotions = new string[] { "Apple,QtyPromoPrice,[email protected]", "Apple,QtyPromoPrice,[email protected]", }; PromotionModel promotionModel = new PromotionModel(promotions); Assert.AreEqual(1, promotionModel.CountOfPromotions); Assert.IsTrue(promotionModel.HasPromotionForItem(new Item("Apple"))); }
/// <summary> /// 添加促销信息 /// </summary> /// <param name="oPModel"></param> /// <returns></returns> public string AddPromotionInfo(PromotionModel oPModel) { List <SqlParameter> sqlparameterlist = new List <SqlParameter>(); SqlParameter _op = new SqlParameter("@op", "Add"); _op.Direction = ParameterDirection.Input; sqlparameterlist.Add(_op); SqlParameter _PromotionId = new SqlParameter("@PromotionId", (Object)DBNull.Value); _PromotionId.Direction = ParameterDirection.Input; sqlparameterlist.Add(_PromotionId); SqlParameter _Title = new SqlParameter("@Title", oPModel.Title == null ? (Object)DBNull.Value : oPModel.Title); _Title.Direction = ParameterDirection.Input; sqlparameterlist.Add(_Title); SqlParameter _Content = new SqlParameter("@Content", oPModel.Content == null ? (Object)DBNull.Value : oPModel.Content); _Title.Direction = ParameterDirection.Input; sqlparameterlist.Add(_Content); SqlParameter _Image = new SqlParameter("@Image", oPModel.Image == null ? (Object)DBNull.Value : oPModel.Image); _Image.Direction = ParameterDirection.Input; sqlparameterlist.Add(_Image); SqlParameter _URL = new SqlParameter("@URL", oPModel.URL == null ? (Object)DBNull.Value : oPModel.URL); _URL.Direction = ParameterDirection.Input; sqlparameterlist.Add(_URL); SqlParameter _CreatorId = new SqlParameter("@CreatorId", oPModel.CreatorId); _CreatorId.Direction = ParameterDirection.Input; sqlparameterlist.Add(_CreatorId); SqlParameter _DealerId = new SqlParameter("@DealerId", oPModel.CreatorId); _DealerId.Direction = ParameterDirection.Input; sqlparameterlist.Add(_DealerId); SqlParameter _result = new SqlParameter("@result", SqlDbType.VarChar, 10); _result.Direction = ParameterDirection.Output; sqlparameterlist.Add(_result); SqlActuator.ExecuteNonQuery("sp_PromotionInfo", sqlparameterlist, Config.ConnectionString); return(_result.Value.ToString()); }
public ActionResult SaveUpdatePromotion(PromotionModel model) { try { return(Json(new { Msg = (new PromotionModel().SaveUpdatePromotion(model)) }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Msg = ex.Message }, JsonRequestBehavior.AllowGet)); } }
/*==Get By Id==*/ public PromotionModel GetById(PromotionModel _params) { var data = _uow.PromotionRepo.SQLQuery <PromotionModel>("sp_Promotion_GetById " + "@Promotion_ID", new SqlParameter("Promotion_ID", SqlDbType.Int) { Value = _params.Promotion_ID }).FirstOrDefault(); return(data); }
/// <summary> /// Gets all asynchronous. /// </summary> /// <param name="model">The Promotion Is.</param> /// <returns> /// GetAllAsync /// </returns> public async Task <int?> UpdatePromotion(PromotionModel model) { try { return(await this.promotionRepository.UpdateAsync(model)); } catch (Exception ex) { string msg = ex.ToString(); return(null); } }
public void Init() { _apple = new ItemModel { ItemName = "Apple", ItemId = 1, ItemPrice = 1.5M }; _orange = new ItemModel { ItemName = "Orange", ItemId = 2, ItemPrice = 2 }; _banana = new ItemModel { ItemName = "Banana", ItemId = 3, ItemPrice = 1 }; _appleDiscount = new PromotionModel { PromotionId = 1, ItemId = 1, SalePrice = 1, Quantity = 1, Description = "50 cents off regular priced apples." }; _orangeBuyOneGetOneHalfOff = new PromotionModel { PromotionId = 2, ItemId = 2, SalePrice = 3, Quantity = 2, Description = "Buy an Orange get the second 50% off." }; _bananaGroupDiscountOnThree = new PromotionModel { PromotionId = 3, ItemId = 3, SalePrice = 2, Quantity = 3, Description = "Buy 3 Banana's for $2.00" }; _appleGroupDiscount = new PromotionModel { PromotionId = 4, ItemId = 1, SalePrice = 1.5M, Description = "Buy an apple ge the second free.", Quantity = 2, }; }
public IActionResult ShowFormAddPromotion() { DatabaseContext databaseContext = new DatabaseContext(); var products = databaseContext.product; PromotionModel promotionModel = new PromotionModel(); string promotion_code = promotionModel.generatePromotionCode(); ViewBag.products = products; ViewBag.promotion_code = promotion_code; return(View("~/Views/Admin/CreatePromotion.cshtml")); }
//create public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePromotions)) { return(AccessDeniedView()); } this.InitCreateEdit(); var model = new PromotionModel(); PreparePromotionModel(null, false, model); return(View(model)); }
public ActionResult DeletePromotion(string id, PromotionModel promotion) { try { var filter = Builders <PromotionModel> .Filter.Eq("_id", ObjectId.Parse(id)); promotionCollection.DeleteOne(filter); return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// Get promotion setting by promotion master id /// </summary> /// <param name="promotionMasterId"></param> /// <returns>returns promotion model that includes promotion master, promotion details and promotion channels for</returns> public PromotionModel GetPromotionSetup(long promotionMasterId) { try { var promotionModel = new PromotionModel(); // PROMOTION MASTER promotionModel.PromotionMasterData = _entities.promotion_master.Find(promotionMasterId); // PROMOTION DETAILS var promotionDetailsList = _entities.promotion_details .Join(_entities.products, jp => jp.product_id, p => p.product_id, (jp, p) => new { jp, p }) .Join(_entities.product_category, jcat => jcat.jp.product_category_id, cat => cat.product_category_id, (jcat, cat) => new { jcat, cat }) .Where(w => w.jcat.jp.promotion_master_id == promotionMasterId) .OrderBy(o => o.jcat.jp.promotion_details_id) .Select(i => new PromotionDetailsModel { promotion_details_id = i.jcat.jp.promotion_details_id, promotion_master_id = i.jcat.jp.promotion_master_id, product_category_id = i.jcat.p.product_category_id, product_id = i.jcat.jp.product_id, gift_quantity = i.jcat.jp.gift_quantity, product_category_name = i.cat.product_category_name, product_name = i.jcat.p.product_name, has_serial = i.jcat.p.has_serial }).ToList(); promotionModel.PromotionDetailsList = promotionDetailsList; // PROMOTION CHANNEL MAPPING var promotionChannelList = _entities.promotion_channel_mapping .Join(_entities.party_type, jc => jc.channel_id, c => c.party_type_id, (jc, c) => new { jc, c }) .Where(w => w.jc.promotion_master_id == promotionMasterId) .OrderBy(o => o.c.party_type_id) .Select(i => new PromotionChannelMappingModel { promotion_channel_mapping_id = i.jc.promotion_channel_mapping_id, promotion_master_id = i.jc.promotion_master_id, channel_id = i.jc.channel_id, is_active = i.jc.is_active, channel_name = i.c.party_type_name }).ToList(); promotionModel.PromotionChannelMappingList = promotionChannelList; return(promotionModel); } catch (Exception ex) { throw ex; } }
public static int SaveCouponRuleInfo(PromotionModel PromotionModel, string action, string[] shoptypes, string[] shopids, string[] categorys, string[] brands, string[] pids) { PromotionModel.ConfigType = ((categorys ?? new string[] { }).Any() ? 1 : 0) + ((brands ?? new string[] { }).Any() ? 2 : 0) + ((pids ?? new string[] { }).Any() ? 4 : 0) + ((shoptypes ?? new string[] { }).Any() ? 8 : 0) + ((shopids ?? new string[] { }).Any() ? 16 : 0); switch (action) { case "add": return(DALPromotion.SaveCouponRuleInfo(PromotionModel, shoptypes, shopids, categorys, brands, pids)); case "update": #region 链接信息处理 //APP if (PromotionModel.CustomSkipPage == "{{TempProductListRouteLink}}") { PromotionModel.CustomSkipPage = "/searchResult?ruleid=" + PromotionModel.PKID + "&s="; } else if (PromotionModel.CustomSkipPage == "{{GroupBuyingProductLink}}") { PromotionModel.CustomSkipPage = "/webView?url=https%3A%2F%2Fwx.tuhu.cn%2Fvue%2FGroupBuy%2Fpages%2Fsearch%2Fsearch%3FruleId%3D" + PromotionModel.PKID; } //小程序 if (PromotionModel.WxSkipPage == "{{TempProductListRouteLink}}") //商品列表 { PromotionModel.WxSkipPage = "/pages/search/search?flag=coupon&ruleId=" + PromotionModel.PKID; } else if (PromotionModel.WxSkipPage == "{{GroupBuyingProductLink}}") //拼团商品列表 { PromotionModel.WxSkipPage = "/pages/search/search?appid=wx25f9f129712845af&ruleId=" + PromotionModel.PKID; } //H5 if (PromotionModel.H5SkipPage == "{{TempProductListRouteLink}}") { PromotionModel.H5SkipPage = "http://wx.tuhu.cn/ChePin/CpList?ruleId=" + PromotionModel.PKID; } else if (PromotionModel.H5SkipPage == "{{GroupBuyingProductLink}}") { PromotionModel.H5SkipPage = "https://wx.tuhu.cn/vue/GroupBuy/pages/search/search?ruleId=" + PromotionModel.PKID; } #endregion return(DALPromotion.UpdateCouponRuleInfo(PromotionModel, shoptypes, shopids, categorys, brands, pids)); default: throw new Exception($"action={action}没有对应的处理方法"); } }
public void GetPromotionForItem_itemNotInLookup_returnsNull() { PromotionModel model = new PromotionModel(new string[] { "Apple,QtyPromoPrice,[email protected]" }); Item item = new Item("Bananas"); Promotion promotion = model.GetPromotionForItem(item); Assert.IsNull(promotion); }
public void CreatePromotionTest_invalidPromotionFormat_notRecognizedPromotionType_exceptionExpected() { PromotionModel model = new PromotionModel(new string[0]); model.CreatePromotion("Apple,Unknown,[email protected]"); }
public void PromotionModelConstructorTest_nullPromotionsParameter_emptyModelCreated() { PromotionModel model = new PromotionModel(null); Assert.AreEqual(0, model.CountOfPromotions); }
public void PromotionModelConstructorTest_noPromotions_emptyModelCreated() { PromotionModel model = new PromotionModel(new string[0]); Assert.AreEqual(0, model.CountOfPromotions); }
public void CreatePromotionTest_validPromotionFormat_buyGetDiscountPromotion_returnsQuantityPromotion() { PromotionModel model = new PromotionModel(new string[0]); Promotion promotion = model.CreatePromotion("Apple,BuyGetDiscountPromo,2:[email protected]"); Assert.IsTrue(promotion is BuyGetDiscountPromotion); }
public void GetPromotionForItem_itemInLookup_returnsPromotion() { PromotionModel model = new PromotionModel(new string[] { "Apple,QtyPromoPrice,[email protected]" }); Item item = new Item("Apple"); Promotion promotion = model.GetPromotionForItem(item); Assert.IsNotNull(promotion); Assert.IsTrue(promotion is QuantityPricePromotion); }
public PricingController(string[] pricings, string[] promotions) { pricingModel = new PricingModel(pricings); promotionModel = new PromotionModel(promotions); }
public void CreatePromotionTest_invalidPromotionFormat_invalidNumberOfParameters_exceptionExpected() { PromotionModel model = new PromotionModel(new string[0]); model.CreatePromotion("Apple Something Missing"); }
public void CreatePromotionTest_validPromotionFormat_quantityPromotion_returnsQuantityPromotion() { PromotionModel model = new PromotionModel(new string[0]); Promotion promotion = model.CreatePromotion("Apple,QtyPromoPrice,[email protected]"); Assert.IsTrue(promotion is QuantityPricePromotion); }