mirror of
https://github.com/rudollee/LearningMVC.git
synced 2026-08-11 16:32:55 +00:00
Primitive Commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using LanguageFeatures.Models;
|
||||
|
||||
namespace LanguageFeatures.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
// GET: Home
|
||||
public string Index()
|
||||
{
|
||||
return "Navigate to a URL to show an example";
|
||||
}
|
||||
|
||||
public ViewResult AutoProperty()
|
||||
{
|
||||
Product myProduct = new Product();
|
||||
myProduct.Name = "Kayak";
|
||||
string productName = myProduct.Name;
|
||||
|
||||
return View("Result", (object)string.Format("Product name: {0}", productName));
|
||||
}
|
||||
|
||||
public ViewResult CreateProduct()
|
||||
{
|
||||
Product myProduct = new Product
|
||||
{
|
||||
ProductID = 100,
|
||||
Name = "Kayak",
|
||||
Description = "A boat for one person",
|
||||
Price = 275M,
|
||||
Category = "Watersports"
|
||||
};
|
||||
|
||||
return View("Result", (object)string.Format("Category: {0}", myProduct.Category));
|
||||
}
|
||||
|
||||
public ViewResult CreateCollection()
|
||||
{
|
||||
string[] stringArray = { "apple", "oragne", "plum" };
|
||||
|
||||
List<int> intList = new List<int> { 10, 20, 30, 40 };
|
||||
|
||||
Dictionary<string, int> myDict = new Dictionary<string, int> { { "apple", 10 }, { "orange", 20 }, { "Plum", 30 } };
|
||||
|
||||
return View("Result", (object)stringArray[1]);
|
||||
}
|
||||
|
||||
public ViewResult UseExtension()
|
||||
{
|
||||
ShoppingCart cart = new ShoppingCart
|
||||
{
|
||||
Products = new List<Product>
|
||||
{
|
||||
new Product {Name = "Kayak", Price = 275M},
|
||||
new Product {Name = "Lifejacket", Price = 48.95M },
|
||||
new Product {Name = "Soccer ball", Price = 19.50M },
|
||||
new Product {Name = "Corner flag", Price = 34.95M }
|
||||
}
|
||||
};
|
||||
|
||||
decimal cartTotal = cart.TotalPrices();
|
||||
|
||||
return View("Result", (object)string.Format("Total: {0:c}", cartTotal));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user