コード例 #1
0
ファイル: PhonesController.cs プロジェクト: nikki-thn/INT422
        public PhonesController()
        {
            Phones = new List <PhoneBase>();

            var iPhone = new PhoneBase
            {
                Id           = 1,
                PhoneName    = "iPhone 8",
                Manufacturer = "Apple",
                DateReleased = new DateTime(2017, 7, 1),
                MSRP         = 849,
                ScreenSize   = 5.5
            };

            var galaxy = new PhoneBase
            {
                Id           = 2,
                PhoneName    = "Galaxy Note 8",
                Manufacturer = "Samsung",
                DateReleased = new DateTime(2017, 8, 1),
                MSRP         = 749,
                ScreenSize   = 5.7
            };

            Phones.Add(iPhone);
            Phones.Add(galaxy);
        }
コード例 #2
0
ファイル: PhonesController.cs プロジェクト: nikki-thn/INT422
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                var newItem = new PhoneBase();

                //Confugure the unique identifier
                newItem.Id = Phones.Count + 1;

                //Configure the string properties
                newItem.PhoneName    = collection["PhoneName"];
                newItem.Manufacturer = collection["Manufacturer"];

                //Configure the date; it comes into the method as string
                newItem.DateReleased = Convert.ToDateTime(collection["DateReleased"]);

                //Configure the numbers; they come into the method as strings
                int    msrp;
                double ss;
                bool   isNumber;

                //MSRP first...
                isNumber     = Int32.TryParse(collection["MSRP"], out msrp);
                newItem.MSRP = msrp;

                //Next, the Screensize....
                isNumber           = double.TryParse(collection["ScreenSize"], out ss);
                newItem.ScreenSize = ss;

                //Add to the Phones collection
                Phones.Add(newItem);

                //Show the results, using the existing Details view
                return(View("Details", newItem));

                //return RedirectToAction("Index");
            }
            catch
            {
                return(View());
            }
        }