本文整理汇总了C#中ProductModel.ToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# ProductModel.ToEntity方法的具体用法?C# ProductModel.ToEntity怎么用?C# ProductModel.ToEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductModel
的用法示例。
在下文中一共展示了ProductModel.ToEntity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Edit
public ActionResult Edit(ProductModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
var product = _productService.GetProductById(model.Id);
if (product == null || product.Deleted)
//No product found with the specified id
return RedirectToAction("List");
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id)
return RedirectToAction("List");
if (ModelState.IsValid)
{
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
model.VendorId = _workContext.CurrentVendor.Id;
}
//product
product = model.ToEntity(product);
product.UpdatedOnUtc = DateTime.UtcNow;
_productService.UpdateProduct(product);
//search engine name
model.SeName = product.ValidateSeName(model.SeName, product.Name, true);
_urlRecordService.SaveSlug(product, model.SeName, 0);
//locales
UpdateLocales(product, model);
//tags
SaveProductTags(product, ParseProductTags(model.ProductTags));
//ACL (customer roles)
SaveProductAcl(product, model);
//Stores
SaveStoreMappings(product, model);
//picture seo names
UpdatePictureSeoNames(product);
//activity log
_customerActivityService.InsertActivity("EditProduct", _localizationService.GetResource("ActivityLog.EditProduct"), product.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Updated"));
return continueEditing ? RedirectToAction("Edit", new { id = product.Id }) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
PrepareTags(model, product);
PrepareCopyProductModel(model, product);
PrepareVariantsModel(model, product);
PrepareVendorsModel(model);
PrepareTemplatesModel(model);
PrepareAddSpecificationAttributeModel(model);
PrepareAddProductPictureModel(model);
PrepareCategoryMapping(model);
PrepareManufacturerMapping(model);
PrepareAclModel(model, product, true);
PrepareStoresMappingModel(model, product, true);
return View(model);
}
示例2: Create
public ActionResult Create(ProductModel model, bool continueEditing)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
if (ModelState.IsValid)
{
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
model.VendorId = _workContext.CurrentVendor.Id;
}
//product
var product = model.ToEntity();
product.CreatedOnUtc = DateTime.UtcNow;
product.UpdatedOnUtc = DateTime.UtcNow;
_productService.InsertProduct(product);
//search engine name
model.SeName = product.ValidateSeName(model.SeName, product.Name, true);
_urlRecordService.SaveSlug(product, model.SeName, 0);
//locales
UpdateLocales(product, model);
//ACL (customer roles)
SaveProductAcl(product, model);
//Stores
SaveStoreMappings(product, model);
//default product variant
var variant = model.FirstProductVariantModel.ToEntity();
variant.ProductId = product.Id;
variant.Published = true;
variant.DisplayOrder = 1;
variant.CreatedOnUtc = DateTime.UtcNow;
variant.UpdatedOnUtc = DateTime.UtcNow;
_productService.InsertProductVariant(variant);
FirstVariant_UpdateLocales(variant, model.FirstProductVariantModel);
//tags (after variant because it can effect product count)
SaveProductTags(product, ParseProductTags(model.ProductTags));
//activity log
_customerActivityService.InsertActivity("AddNewProduct", _localizationService.GetResource("ActivityLog.AddNewProduct"), product.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = product.Id }) : RedirectToAction("List");
}
//If we got this far, something failed, redisplay form
//product
model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
PrepareVendorsModel(model);
PrepareTemplatesModel(model);
PrepareAddSpecificationAttributeModel(model);
PrepareAddProductPictureModel(model);
PrepareCategoryMapping(model);
PrepareManufacturerMapping(model);
PrepareAclModel(model, null, true);
PrepareStoresMappingModel(model, null, true);
//first product variant
FirstVariant_PrepareProductVariantModel(model.FirstProductVariantModel, null, false);
return View(model);
}