本文整理汇总了C#中Nop.Admin.Models.Discounts.DiscountModel.ToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# DiscountModel.ToEntity方法的具体用法?C# DiscountModel.ToEntity怎么用?C# DiscountModel.ToEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Admin.Models.Discounts.DiscountModel
的用法示例。
在下文中一共展示了DiscountModel.ToEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(DiscountModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
return AccessDeniedView();
if (ModelState.IsValid)
{
var discount = model.ToEntity();
_discountService.InsertDiscount(discount);
//activity log
_customerActivityService.InsertActivity("AddNewDiscount", _localizationService.GetResource("ActivityLog.AddNewDiscount"), discount.Name);
SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = discount.Id }) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
PrepareDiscountModel(model, null);
return View(model);
}
示例2: Edit
public ActionResult Edit(DiscountModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
return AccessDeniedView();
var discount = _discountService.GetDiscountById(model.Id);
if (discount == null)
//No discount found with the specified id
return RedirectToAction("List");
if (ModelState.IsValid)
{
var prevDiscountType = discount.DiscountType;
discount = model.ToEntity(discount);
_discountService.UpdateDiscount(discount);
//clean up old references (if changed) and update "HasDiscountsApplied" properties
if (prevDiscountType == DiscountType.AssignedToCategories
&& discount.DiscountType != DiscountType.AssignedToCategories)
{
//applied to categories
discount.AppliedToCategories.Clear();
_discountService.UpdateDiscount(discount);
}
if (prevDiscountType == DiscountType.AssignedToManufacturers
&& discount.DiscountType != DiscountType.AssignedToManufacturers)
{
//applied to manufacturers
discount.AppliedToManufacturers.Clear();
_discountService.UpdateDiscount(discount);
}
if (prevDiscountType == DiscountType.AssignedToSkus
&& discount.DiscountType != DiscountType.AssignedToSkus)
{
//applied to products
var products = discount.AppliedToProducts.ToList();
discount.AppliedToProducts.Clear();
_discountService.UpdateDiscount(discount);
//update "HasDiscountsApplied" property
foreach (var p in products)
_productService.UpdateHasDiscountsApplied(p);
}
//activity log
_customerActivityService.InsertActivity("EditDiscount", _localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name);
SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));
if (continueEditing)
{
//selected tab
SaveSelectedTabName();
return RedirectToAction("Edit", new {id = discount.Id});
}
return RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
PrepareDiscountModel(model, discount);
return View(model);
}
示例3: Edit
public ActionResult Edit(DiscountModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
return AccessDeniedView();
var discount = _discountService.GetDiscountById(model.Id);
if (discount == null)
//No discount found with the specified id
return RedirectToAction("List");
if (ModelState.IsValid)
{
discount = model.ToEntity(discount);
_discountService.UpdateDiscount(discount);
//activity log
_customerActivityService.InsertActivity("EditDiscount", _localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name);
SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));
return continueEditing ? RedirectToAction("Edit", discount.Id) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
PrepareDiscountModel(model, discount);
return View(model);
}
示例4: Edit
public ActionResult Edit(DiscountModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
return AccessDeniedView();
var discount = _discountService.GetDiscountById(model.Id);
if (discount == null)
//No discount found with the specified id
return RedirectToAction("List");
if (ModelState.IsValid)
{
var prevDiscountType = discount.DiscountType;
discount = model.ToEntity(discount);
_discountService.UpdateDiscount(discount);
//clean up old references (if changed) and update "HasDiscountsApplied" properties
if (prevDiscountType == DiscountType.AssignedToCategories
&& discount.DiscountType != DiscountType.AssignedToCategories)
{
//applied to categories
//_categoryService.
var categories = _categoryService.GetAllCategoriesByDiscount(discount.Id);
//update "HasDiscountsApplied" property
foreach (var category in categories)
{
var item = category.AppliedDiscounts.Where(x => x.Id == discount.Id).FirstOrDefault();
category.AppliedDiscounts.Remove(item);
//_discountService.UpdateDiscount(discount);
//_categoryService.Update(category);
}
}
if (prevDiscountType == DiscountType.AssignedToManufacturers
&& discount.DiscountType != DiscountType.AssignedToManufacturers)
{
//applied to manufacturers
var manufacturers = _manufacturerService.GetAllManufacturersByDiscount(discount.Id);
foreach (var manufacturer in manufacturers)
{
var item = manufacturer.AppliedDiscounts.Where(x => x.Id == discount.Id).FirstOrDefault();
manufacturer.AppliedDiscounts.Remove(item);
//_manufacturerService.UpdateHasDiscountsApplied(manufacturer);
}
}
if (prevDiscountType == DiscountType.AssignedToSkus
&& discount.DiscountType != DiscountType.AssignedToSkus)
{
//applied to products
//var products = discount.AppliedToProducts.ToList();
var products = _productService.GetProductsByDiscount(discount.Id);
foreach (var p in products)
{
var item = p.AppliedDiscounts.Where(x => x.Id == discount.Id).FirstOrDefault();
p.AppliedDiscounts.Remove(item);
_productService.DeleteDiscount(item, p.Id);
_productService.UpdateHasDiscountsApplied(p.Id);
}
}
//activity log
_customerActivityService.InsertActivity("EditDiscount", discount.Id, _localizationService.GetResource("ActivityLog.EditDiscount"), discount.Name);
SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));
if (continueEditing)
{
//selected tab
SaveSelectedTabIndex();
return RedirectToAction("Edit", new {id = discount.Id});
}
return RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
PrepareDiscountModel(model, discount);
return View(model);
}