本文整理汇总了C#中ProductModel.Map方法的典型用法代码示例。如果您正苦于以下问题:C# ProductModel.Map方法的具体用法?C# ProductModel.Map怎么用?C# ProductModel.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductModel
的用法示例。
在下文中一共展示了ProductModel.Map方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveProduct
public ActionResult SaveProduct(ProductModel model)
{
if (model.IsNew && !CanAdd)
{
return GetAddDeniedResult();
}
if (!model.IsNew && !CanUpdate)
{
return GetUpdateDeniedResult();
}
if (!ModelState.IsValid && GetModelStateErrorList().Any())
{
return JsonObject(false, GetModelStateErrors());
}
#region save list image
var listImagePath = new List<string>();
for (var i = 0; i < Request.Files.Count; ++i)
{
var file = Request.Files[i];
if (file != null &&
!string.IsNullOrWhiteSpace(file.FileName))
{
var extension = Path.GetExtension(file.FileName).ToStr();
if (!SiteUtils.IsImageFile(file.FileName))
{
return JsonObject(false, BackendMessage.FileTypeIsInvalid);
}
if (!SiteUtils.ImageSizeIsValid(file.ContentLength))
{
return JsonObject(false, BackendMessage.FileMaxSize5MB);
}
var imagePath = Guid.NewGuid() + extension;
listImagePath.Add(imagePath);
var filePath = PhysicalDataFilePath(imagePath);
file.SaveAs(filePath);
}
}
#endregion
var entity = model.Map<ProductModel, Product>();
if (entity.IsNew)
{
entity.InitId();
entity.CreatedDate = DateTime.UtcNow;
entity.UpdateDate = DateTime.UtcNow;
}
else
{
var oldData = ServiceHelper.Product.ExecuteDispose(s => s.GetProduct(entity.Id));
if (oldData == null)
{
return JsonObject(false, BackendMessage.CannotLoadData);
}
entity.CreatedDate = oldData.CreatedDate;
entity.UpdateDate = DateTime.UtcNow;
}
var response = ServiceHelper.Product.ExecuteDispose(s => s.SaveProduct(new SaveRequest
{
Entity = entity
}));
if (response.Success)
{
if (listImagePath.Any())
{
var listImages = new List<ProductImage>();
listImagePath.ForEach(imagePath =>
{
var image = new ProductImage
{
ImagePath = imagePath,
ProductId = entity.Id,
CreatedDate = DateTime.UtcNow,
Visible = true
};
image.InitId();
listImages.Add(image);
});
ServiceHelper.Product.ExecuteDispose(s => s.SaveListImage(listImages));
}
var indexModel = new ProductIndexModel
{
TextSearch = model.TextSearch,
//.........这里部分代码省略.........