本文整理汇总了C#中CategoryModel.ToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# CategoryModel.ToEntity方法的具体用法?C# CategoryModel.ToEntity怎么用?C# CategoryModel.ToEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel.ToEntity方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Edit
public ActionResult Edit(CategoryModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
return AccessDeniedView();
var category = _categoryService.GetCategoryById(model.Id);
if (category == null || category.Deleted)
//No category found with the specified id
return RedirectToAction("List");
if (ModelState.IsValid)
{
int prevPictureId = category.PictureId;
category = model.ToEntity(category);
category.UpdatedOnUtc = DateTime.UtcNow;
_categoryService.UpdateCategory(category);
//search engine name
model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
_urlRecordService.SaveSlug(category, model.SeName, 0);
//locales
UpdateLocales(category, model);
//discounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
{
//new role
if (category.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0)
category.AppliedDiscounts.Add(discount);
}
else
{
//removed role
if (category.AppliedDiscounts.Count(d => d.Id == discount.Id) > 0)
category.AppliedDiscounts.Remove(discount);
}
}
_categoryService.UpdateCategory(category);
//update "HasDiscountsApplied" property
_categoryService.UpdateHasDiscountsApplied(category);
//delete an old picture (if deleted or updated)
if (prevPictureId > 0 && prevPictureId != category.PictureId)
{
var prevPicture = _pictureService.GetPictureById(prevPictureId);
if (prevPicture != null)
_pictureService.DeletePicture(prevPicture);
}
//update picture seo file name
UpdatePictureSeoNames(category);
//ACL
SaveCategoryAcl(category, model);
//Stores
SaveStoreMappings(category, model);
//activity log
_customerActivityService.InsertActivity("EditCategory", _localizationService.GetResource("ActivityLog.EditCategory"), category.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Updated"));
if (continueEditing)
{
//selected tab
SaveSelectedTabIndex();
return RedirectToAction("Edit", category.Id);
}
else
{
return RedirectToAction("List");
}
}
//If we got this far, something failed, redisplay form
//templates
PrepareTemplatesModel(model);
//categories
PrepareAllCategoriesModel(model);
//discounts
PrepareDiscountModel(model, category, true);
//ACL
PrepareAclModel(model, category, true);
//Stores
PrepareStoresMappingModel(model, category, true);
return View(model);
}
示例2: Create
public ActionResult Create(CategoryModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
return AccessDeniedView();
if (ModelState.IsValid)
{
var category = model.ToEntity();
category.CreatedOnUtc = DateTime.UtcNow;
category.UpdatedOnUtc = DateTime.UtcNow;
_categoryService.InsertCategory(category);
//search engine name
model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
_urlRecordService.SaveSlug(category, model.SeName, 0);
//locales
UpdateLocales(category, model);
//discounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
category.AppliedDiscounts.Add(discount);
}
_categoryService.UpdateCategory(category);
//update "HasDiscountsApplied" property
_categoryService.UpdateHasDiscountsApplied(category);
//update picture seo file name
UpdatePictureSeoNames(category);
//ACL (customer roles)
SaveCategoryAcl(category, model);
//Stores
SaveStoreMappings(category, model);
//activity log
_customerActivityService.InsertActivity("AddNewCategory", _localizationService.GetResource("ActivityLog.AddNewCategory"), category.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
//templates
PrepareTemplatesModel(model);
//categories
PrepareAllCategoriesModel(model);
//discounts
PrepareDiscountModel(model, null, true);
//ACL
PrepareAclModel(model, null, true);
//Stores
PrepareStoresMappingModel(model, null, true);
return View(model);
}
示例3: Edit
public ActionResult Edit(CategoryModel model, bool continueEditing, FormCollection form)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var category = _categoryService.GetCategoryById(model.Id);
if (category == null || category.Deleted)
return RedirectToAction("List");
if (ModelState.IsValid)
{
int prevPictureId = category.PictureId.GetValueOrDefault();
category = model.ToEntity(category);
category.UpdatedOnUtc = DateTime.UtcNow;
_categoryService.UpdateCategory(category);
//search engine name
model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
_urlRecordService.SaveSlug(category, model.SeName, 0);
//locales
UpdateLocales(category, model);
//discounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
{
//new role
if (category.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() == 0)
category.AppliedDiscounts.Add(discount);
}
else
{
//removed role
if (category.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() > 0)
category.AppliedDiscounts.Remove(discount);
}
}
_categoryService.UpdateCategory(category);
//update "HasDiscountsApplied" property
_categoryService.UpdateHasDiscountsApplied(category);
//delete an old picture (if deleted or updated)
if (prevPictureId > 0 && prevPictureId != category.PictureId)
{
var prevPicture = _pictureService.GetPictureById(prevPictureId);
if (prevPicture != null)
_pictureService.DeletePicture(prevPicture);
}
//update picture seo file name
UpdatePictureSeoNames(category);
//ACL
SaveCategoryAcl(category, model);
//Stores
_storeMappingService.SaveStoreMappings<Category>(category, model.SelectedStoreIds);
_eventPublisher.Publish(new ModelBoundEvent(model, category, form));
//activity log
_customerActivityService.InsertActivity("EditCategory", _localizationService.GetResource("ActivityLog.EditCategory"), category.Name);
NotifySuccess(_localizationService.GetResource("Admin.Catalog.Categories.Updated"));
return continueEditing ? RedirectToAction("Edit", category.Id) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
//parent categories
if (model.ParentCategoryId.HasValue)
{
var parentCategory = _categoryService.GetCategoryById(model.ParentCategoryId.Value);
if (parentCategory != null && !parentCategory.Deleted)
model.ParentCategoryBreadcrumb = parentCategory.GetCategoryBreadCrumb(_categoryService);
else
model.ParentCategoryId = 0;
}
//templates
PrepareTemplatesModel(model);
PrepareCategoryModel(model, category, true);
//ACL
PrepareAclModel(model, category, true);
//Stores
PrepareStoresMappingModel(model, category, true);
return View(model);
}
示例4: Edit
public ActionResult Edit(CategoryModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var category = _categoryService.GetCategoryById(model.Id);
if (category == null || category.Deleted)
//No category found with the specified id
return RedirectToAction("List");
if (ModelState.IsValid)
{
int prevPictureId = category.PictureId;
category = model.ToEntity(category);
category.UpdatedOnUtc = DateTime.UtcNow;
_categoryService.UpdateCategory(category);
//locales
UpdateLocales(category, model);
//discounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
{
//new role
if (category.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() == 0)
category.AppliedDiscounts.Add(discount);
}
else
{
//removed role
if (category.AppliedDiscounts.Where(d => d.Id == discount.Id).Count() > 0)
category.AppliedDiscounts.Remove(discount);
}
}
_categoryService.UpdateCategory(category);
//update "HasDiscountsApplied" property
_categoryService.UpdateHasDiscountsApplied(category);
//delete an old picture (if deleted or updated)
if (prevPictureId > 0 && prevPictureId != category.PictureId)
{
var prevPicture = _pictureService.GetPictureById(prevPictureId);
if (prevPicture != null)
_pictureService.DeletePicture(prevPicture);
}
//update picture seo file name
UpdatePictureSeoNames(category);
//activity log
_customerActivityService.InsertActivity("EditCategory", _localizationService.GetResource("ActivityLog.EditCategory"), category.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Updated"));
return continueEditing ? RedirectToAction("Edit", category.Id) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
//parent categories
model.ParentCategories = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
if (model.ParentCategoryId > 0)
{
var parentCategory = _categoryService.GetCategoryById(model.ParentCategoryId);
if (parentCategory != null && !parentCategory.Deleted)
model.ParentCategories.Add(new DropDownItem { Text = parentCategory.GetCategoryBreadCrumb(_categoryService), Value = parentCategory.Id.ToString() });
else
model.ParentCategoryId = 0;
}
//templates
PrepareTemplatesModel(model);
//discounts
PrepareDiscountModel(model, category, true);
return View(model);
}
示例5: Create
public ActionResult Create(CategoryModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
if (ModelState.IsValid)
{
var category = model.ToEntity();
category.CreatedOnUtc = DateTime.UtcNow;
category.UpdatedOnUtc = DateTime.UtcNow;
_categoryService.InsertCategory(category);
//locales
UpdateLocales(category, model);
//disounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
category.AppliedDiscounts.Add(discount);
}
_categoryService.UpdateCategory(category);
//update "HasDiscountsApplied" property
_categoryService.UpdateHasDiscountsApplied(category);
//update picture seo file name
UpdatePictureSeoNames(category);
//activity log
_customerActivityService.InsertActivity("AddNewCategory", _localizationService.GetResource("ActivityLog.AddNewCategory"), category.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
//templates
PrepareTemplatesModel(model);
//parent categories
model.ParentCategories = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
if (model.ParentCategoryId > 0)
{
var parentCategory = _categoryService.GetCategoryById(model.ParentCategoryId);
if (parentCategory != null && !parentCategory.Deleted)
model.ParentCategories.Add(new DropDownItem { Text = parentCategory.GetCategoryBreadCrumb(_categoryService), Value = parentCategory.Id.ToString() });
else
model.ParentCategoryId = 0;
}
//discounts
PrepareDiscountModel(model, null, true);
return View(model);
}
示例6: Create
public ActionResult Create(CategoryModel model, bool continueEditing, FormCollection form)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
if (ModelState.IsValid)
{
var category = model.ToEntity();
category.CreatedOnUtc = DateTime.UtcNow;
category.UpdatedOnUtc = DateTime.UtcNow;
MediaHelper.UpdatePictureTransientStateFor(category, c => c.PictureId);
_categoryService.InsertCategory(category);
//search engine name
model.SeName = category.ValidateSeName(model.SeName, category.Name, true);
_urlRecordService.SaveSlug(category, model.SeName, 0);
//locales
UpdateLocales(category, model);
//disounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToCategories, null, true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
category.AppliedDiscounts.Add(discount);
}
_categoryService.UpdateCategory(category);
//update "HasDiscountsApplied" property
_categoryService.UpdateHasDiscountsApplied(category);
//update picture seo file name
UpdatePictureSeoNames(category);
//ACL (customer roles)
SaveCategoryAcl(category, model);
//Stores
_storeMappingService.SaveStoreMappings<Category>(category, model.SelectedStoreIds);
_eventPublisher.Publish(new ModelBoundEvent(model, category, form));
//activity log
_customerActivityService.InsertActivity("AddNewCategory", _localizationService.GetResource("ActivityLog.AddNewCategory"), category.Name);
NotifySuccess(_localizationService.GetResource("Admin.Catalog.Categories.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
//templates
PrepareTemplatesModel(model);
//parent categories
if (model.ParentCategoryId.HasValue)
{
var parentCategory = _categoryService.GetCategoryById(model.ParentCategoryId.Value);
if (parentCategory != null && !parentCategory.Deleted)
model.ParentCategoryBreadcrumb = parentCategory.GetCategoryBreadCrumb(_categoryService);
else
model.ParentCategoryId = 0;
}
PrepareCategoryModel(model, null, true);
//ACL
PrepareAclModel(model, null, true);
//Stores
PrepareStoresMappingModel(model, null, true);
return View(model);
}