示例#1
0
        public ActionResult Create(TransportBidPlanDetail transportbidplandetail)
        {
            if (ModelState.IsValid)
            {
                db.TransportBidPlanDetails.Add(transportbidplandetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BidPlanID     = new SelectList(db.TransportBidPlans, "TransportBidPlanID", "TransportBidPlanID", transportbidplandetail.BidPlanID);
            ViewBag.DestinationID = new SelectList(db.AdminUnits, "AdminUnitID", "Name", transportbidplandetail.DestinationID);
            ViewBag.SourceID      = new SelectList(db.Hubs, "HubId", "Name", transportbidplandetail.SourceID);
            ViewBag.ProgramID     = new SelectList(db.Programs, "ProgramID", "Name", transportbidplandetail.ProgramID);
            return(View(transportbidplandetail));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Age,Sex,AnimalFriendID,BreedID,LifestyleID,ColorID,PlayID,TraitsID_1,TraitsID_2,TraitsID_3,PeopleFriendID,WaterID")] Cat cat)
        {
            if (ModelState.IsValid)
            {
                db.Cats.Add(cat);
                db.SaveChanges();
            }

            ViewBag.AnimalFriendID = new SelectList(db.AnimalFriendlinesses, "ID", "Response", cat.AnimalFriendID);
            ViewBag.BreedID        = new SelectList(db.Breeds, "ID", "CatBreed", cat.BreedID);
            ViewBag.ColorID        = new SelectList(db.Colors, "ID", "CatColor", cat.ColorID);
            ViewBag.LifestyleID    = new SelectList(db.Lifestyles, "ID", "Type", cat.LifestyleID);
            ViewBag.PeopleFriendID = new SelectList(db.PeopleFriendlinesses, "ID", "Response", cat.PeopleFriendID);
            ViewBag.PlayID         = new SelectList(db.Plays, "ID", "Activity", cat.PlayID);
            ViewBag.TraitsID_1     = new SelectList(db.Traits, "ID", "Type", cat.TraitsID_1);
            ViewBag.TraitsID_2     = new SelectList(db.Traits, "ID", "Type", cat.TraitsID_2);
            ViewBag.TraitsID_3     = new SelectList(db.Traits, "ID", "Type", cat.TraitsID_3);
            ViewBag.WaterID        = new SelectList(db.Waters, "ID", "Response", cat.WaterID);
            return(RedirectToAction("Details", cat));
        }
示例#3
0
    public static void Value_converters_can_convert_nulls()
    {
        Console.WriteLine($">>>> Sample: {nameof(Value_converters_can_convert_nulls)}");
        Console.WriteLine();

        Helpers.RecreateCleanDatabase();

        using (var context = new CatsContext())
        {
            #region InsertCats
            context.AddRange(
                new Cat {
                Name = "Mac", Breed = Breed.Unknown
            },
                new Cat {
                Name = "Clippy", Breed = Breed.Burmese
            },
                new Cat {
                Name = "Sid", Breed = Breed.Tonkinese
            });

            context.SaveChanges();
            #endregion

            Console.WriteLine();
        }

        using (var context = new CatsContext())
        {
            var cats = context.Cats.ToList();

            Console.WriteLine();

            foreach (var cat in cats)
            {
                Console.WriteLine($"{cat.Name} has breed '{cat.Breed}'.");
            }
        }

        Console.WriteLine();
    }