本文整理汇总了C#中ProductModel类的典型用法代码示例。如果您正苦于以下问题:C# ProductModel类的具体用法?C# ProductModel怎么用?C# ProductModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProductModel类属于命名空间,在下文中一共展示了ProductModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(ProductModel model)
{
bool isNotExist = _productRepo.FindDuplicateByName(model.Name);
if (isNotExist)
{
Categories category = _categoryRepo.Get(Int32.Parse(model.Category));
Manufacturers manufacturer = _manufacturersRepo.Get(Int32.Parse(model.Manufacturer));
var product = new Products(model.Name, model.Description,
Convert.ToDecimal(model.Price, CultureInfo.InvariantCulture), category, manufacturer,
Int32.Parse(model.Quantity), model.IsFeatured, model.IsRecent, model.IsBestSeller, model.ShortDescription);
try
{
_productRepo.Save(product);
TempData["success"] = "Pomyślnie dodano nowy towar.";
return RedirectToAction("index");
}
catch (Exception)
{
TempData["error"] = "Wystąpił problem z połączeniem do bazy danych.";
return RedirectToAction("Create");
}
}
TempData["error"] = "Towar o podanej nazwie już istnieje";
return RedirectToAction("Create");
}
示例2: Get
public GridResponseModel<ProductModel> Get(GridRequestModel gridRequestModel, ProductModel searchModel)
{
var query = _unitOfWork.ProductRepository.Queryable;
if (searchModel != null)
{
if (searchModel.ProductTypeId > 0)
query = query.Where(p => p.ProductType.Id == searchModel.ProductTypeId);
if (searchModel.SupplierId > 0)
query = query.Where(p => p.Supplier != null && p.Supplier.Id == searchModel.SupplierId);
if (!string.IsNullOrWhiteSpace(searchModel.Name))
query = query.Where(p => p.Name.Contains(searchModel.Name));
}
switch (gridRequestModel.Sidx)
{
default:
case "Name":
query = query.OrderBy(p => p.Name, gridRequestModel.IsSortAsending);
break;
}
var dbModel = query.ToPagingResult(gridRequestModel);
var model = dbModel.Rows.Select(m => Mapper.Map<ProductModel>(m)).ToArray();
var gridData = new GridResponseModel<ProductModel>(gridRequestModel, dbModel.RowCount, model);
return gridData;
}
示例3: MainViewResult
public ViewResult MainViewResult()
{
var viewResult = new ViewResult();
viewResult.ViewName = "Index";
var userProducts = new ProductModel(Domain.User.Products);
userProducts.Refresh();
var userAccount = new AccountModel(Domain.User.Account);
userAccount.Refresh();
var vmProducts = new ProductModel(Domain.VM.Products);
vmProducts.Refresh();
var vmBankAccount = new AccountModel(Domain.VM.BankAccount);
vmBankAccount.Refresh();
viewResult.ViewBag.UserProducts = userProducts;
viewResult.ViewBag.UserAccount = userAccount;
viewResult.ViewBag.VMProducts = vmProducts;
viewResult.ViewBag.VMBankAccount = vmBankAccount;
viewResult.ViewBag.VMUserAccount = Domain.VM.UserAccount;
return viewResult;
}
示例4: FillPage
private void FillPage()
{
//Get selected product's data
if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
int id = Convert.ToInt32(Request.QueryString["id"]);
ProductModel productModel = new ProductModel();
Product product = productModel.GetProduct(id);
ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
//Fill Page with data
lblColor.Text = " " + product.Color;
lblPrice.Text = " $" + product.Price;
lblTitle.Text = product.Name;
lblDescription.Text = product.Description;
lblProductNum.Text = "Product Number: "+ id.ToString();
imgProdcut.ImageUrl = "~/Image/Products/" + product.Image;
//Retrieve supplier
int supplierId = product.SupplierID;
Supplier supplier = db.Suppliers.Find(supplierId);
lblSupplier.Text = "By " + supplier.Name;
//Fille amount dropdown list with numbers 1-30;
int[] quantity = Enumerable.Range(1, 30).ToArray();
ddlQuantity.DataSource = quantity;
ddlQuantity.AppendDataBoundItems = true;
ddlQuantity.DataBind();
}
}
示例5: VmShouldUseResourceNameEditEntity
public void VmShouldUseResourceNameEditEntity()
{
var model = new ProductModel();
var viewModel = GetViewModel<ProductEditorViewModel>();
viewModel.InitializeEntity(model, false);
Assert.AreEqual(viewModel.DisplayName, UiResources.ProductEditDisplayName);
}
示例6: ManyToManyUpdateTest
public void ManyToManyUpdateTest()
{
using (EasySession easySession = new EasySession())
{
///[Test Update] - many-to-many relationship
ProductModelIllustration productModelIllustration = new ProductModelIllustration();
int resultCount = productModelIllustration.Count(easySession);
Assert.AreEqual(5, resultCount);
ProductModel productModel = new ProductModel();
resultCount = productModel.Count(easySession);
Assert.AreEqual(129, resultCount);
productModel.ProductModelID = 47;
ProductModel resultList = productModel.Find(easySession, EasyLoad.Simple);
//resultList.Illustration.RemoveAt(0);
bool result = resultList.Update(easySession);
resultCount = resultList.Count(easySession);
Assert.AreEqual(129, resultCount);
resultCount = productModelIllustration.Count(easySession);
Assert.AreEqual(5, resultCount);
}
}
示例7: GetProduct
//GET api/products/{productId}
public HttpResponseMessage GetProduct(int productId, [ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
{
var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
() =>
{
using (var context = new StoreContext())
{
this.ValidateSessionKey(sessionKey);
var product = context.Products.Include("Category").FirstOrDefault(p => p.Id == productId);
if (product == null)
{
throw new ArgumentException("Product not found");
}
var resultProductModel = new ProductModel
{
Id = product.Id,
Name = product.Name,
Price = product.Price,
CategoryName = product.Category.Name,
CategoryId = product.Category.Id,
Description = product.Description,
ImageSource = product.ImageSource,
Quantity = product.Quantity
};
var response = this.Request.CreateResponse(HttpStatusCode.OK,
resultProductModel);
return response;
}
});
return responseMsg;
}
示例8: getProduct
public List<ProductModel> getProduct(IEnumerable<Product> data)
{
var list = new List<ProductModel>();
if (data != null)
{
foreach (var model in data)
{
var prod = new ProductModel();
if (model != null)
{
prod.CategoryId = model.CategoryId;
prod.Discontinued = model.Discontinued;
prod.Name = model.Name;
prod.ProductCategory = getCategory(model.ProductCategory);
prod.ProductId = model.ProductId;
prod.ProductSupplier = getSupplier(model.ProductSupplier);
prod.QuantityPerUnit = model.QuantityPerUnit;
prod.ReorderLevel = model.ReorderLevel;
prod.SupplierId = model.SupplierId;
prod.UnitPrice = model.UnitPrice;
prod.UnitsInStock = model.UnitsInStock;
prod.UnitsOnOrder = model.UnitsOnOrder;
}
list.Add(prod);
}
}
return list;
}
示例9: Create
public void Create(ProductModel model)
{
var dbModel = Mapper.Map<Product>(model);
dbModel.ProductType = _unitOfWork.ProductTypeRepository.Get(model.ProductTypeId);
dbModel.Supplier = _unitOfWork.SupplierRepository.Get(model.SupplierId);
_unitOfWork.ProductRepository.Create(dbModel);
}
示例10: SaveProduct
public ActionResult SaveProduct(ProductModel model)
{
if(model != null)
{
model.SupplierId = 1;
_service.SaveProduct(model);
}
return new HttpStatusCodeResult(201, "Created Successfully");
}
示例11: Index
public ActionResult Index(string id)
{
var products = _unitOfWork.ProductRepository.Get().ToList();
var product = _unitOfWork.ProductRepository.GetById(new Guid(id));
if (product == null)
{
return View("Error");
}
var image800x640Paths = product.Image800x640Paths.ToList();
var imageAdditional = GetImageAdditionalModels(image800x640Paths);
var relatedProductIds = _unitOfWork.RelatedProductRepository.Get(i=>i.ProductId==new Guid(id)).Select(r=>r.RelatedProductId);
var relatedProducts = _unitOfWork.ProductRepository.Get(p => relatedProductIds.Contains(p.Id)).ToList();
var relatedProductBlocks = GetRelatedProductBlocks(relatedProducts);
var categoryViewModels = GetCategories(product, products);
var specialProduct = products.First(i => i.Id == new Guid("CD4879A0-C210-4DAA-A6DE-A59E9CC153BF"));
var specialProductViewModel = new SpecialProductViewModel
{
Id = specialProduct.Id.ToString(),
Name = specialProduct.Name,
OldPrice = specialProduct.OldPrice.HasValue ? specialProduct.OldPrice.Value.ToString("C") : string.Empty,
NewPrice = specialProduct.NewPrice.ToString("C"),
RatingImagePath = specialProduct.RatingImagePath,
Image240x192Path = specialProduct.Image240x192Path
};
var productInfo = new ProductInfo
{
Id = product.Id.ToString(),
Name = product.Name,
DefaultImage = image800x640Paths.First(i => i.IsActive).Path,
OldPrice = product.OldPrice.HasValue ? product.OldPrice.Value.ToString("C") : string.Empty,
NewPrice = product.NewPrice.ToString("C"),
ExTax = (product.NewPrice - product.NewPrice*.15m).ToString("C"),
Brand = product.Brand.Name,
BrandId = product.Brand.Id.ToString(),
Description = product.Description,
ImageAdditionals = imageAdditional,
Availability = "In Stock"
};
var productModel = new ProductModel
{
ProductInfo=productInfo,
RelatedProductBlocks = relatedProductBlocks,
RelatedProductCount=relatedProducts.Count,
CategoryViewModels=categoryViewModels,
SpecialProductViewModel=specialProductViewModel
};
return View(productModel);
}
示例12: Create
public ActionResult Create(ProductModel model)
{
if (this.ModelState.IsValid)
{
_productService.Create(model);
return RedirectToAction("Index");
}
return View(model);
}
示例13: CreateOrUpdate
public ActionResult CreateOrUpdate(ProductModel productModel)
{
if (ModelState.IsValid && productModel.IsValid())
{
this.productModelTasks.CreateOrUpdate(productModel);
return this.RedirectToAction(x => x.Index());
}
return View(productModel);
}
示例14: FillPage
//FillPage() method
private void FillPage(int id)
{
ProductModel pModel = new ProductModel();
Product product = pModel.GetProduct(id);
descriptionTextBox.Text = product.Description;
nameTextBox.Text = product.Name;
priceTextBox.Text = product.Price.ToString();
imageDropDownList.SelectedValue = product.Image;
typeDropDownList.SelectedValue = product.Type.ToString();
quantityTextBox.Text = product.Quantity.ToString();
}
示例15: AddBook
public ActionResult AddBook(HttpPostedFileBase file, AddProductViewModel model)
{
Session["Username"] = "Admin";
var userName = Session["Username"];
var imagePath = CreateMD5(model.Title + DateTime.Now + DateTime.Now.Millisecond + model.Detail) ;
var addViewModel = new ProductModel();
addViewModel.Title = model.Title;
addViewModel.Author = model.Author;
addViewModel.Image = imagePath;
addViewModel.Detail = model.Detail;
addViewModel.Balance = model.Balance;
addViewModel.Isbn = model.Isbn;
addViewModel.Price = model.Price;
addViewModel.CategoryId = model.CategoryId;
addViewModel.CreateBy = userName.ToString();
addViewModel.CreateTime = DateTime.Now;
addViewModel.UpdateBy = "Test Admin";
addViewModel.UpdateTime = DateTime.Now;
addViewModel.IsActive = true;
bool uploadImageIsComplete = true;
if (file != null && file.ContentLength > 0)
try
{
var fileName = imagePath + ".jpg";
var path = Path.Combine(Server.MapPath("~/Content/images/Product/"), fileName);
file.SaveAs(path);
}
catch (Exception ex)
{
uploadImageIsComplete = false;
}
else
{
uploadImageIsComplete = false;
}
if (uploadImageIsComplete)
{
ProductService productService = new ProductService();
if (productService.Save(addViewModel))
{
// return RedirectToRoute("~Success");
}
else
{
// return RedirectToRoute("~Error");
}
}
return RedirectToAction("ManageProductView", "ManageProduct");
}