コード例 #1
0
        //GET: FoodDay/CreateFoodDay(from Profile)
        public ActionResult CreateFoodDayFromProfile(int profId)
        {
            ApplicationDbContext ctx = new ApplicationDbContext();
            var model =
                new FoodDayCreateFromProfile
            {
                UserProfileId = profId,
                ProfileTitle  = ctx.UserProfiles.Find(profId).Title,
                Date          = DateTime.Now
            };

            PopulateDateList();
            return(View(model));
        }
コード例 #2
0
ファイル: FoodDayService.cs プロジェクト: nrwehner/LogIt
        public bool CreateFoodDayFromProfile(FoodDayCreateFromProfile model)
        {
            var entity =
                new FoodDay()
            {
                UserProfileId = model.UserProfileId,
                Date          = model.Date,
                CreatedBy     = _db.Users.Find(_userId).FirstName + " " + _db.Users.Find(_userId).LastName,
                CreatedUtc    = DateTimeOffset.Now
            };

            _db.FoodDays.Add(entity);
            return(_db.SaveChanges() == 1);
        }
コード例 #3
0
        public ActionResult CreateFoodDayFromProfile(int profId, FoodDayCreateFromProfile model)
        {
            if (!ModelState.IsValid)
            {
                PopulateDateList();
                return(View(model));
            }

            if (model.UserProfileId != profId)//maybe don't want this check if you want to let the user change the profile
            //they're choosing - but would you? - also, maybe pass the parameters from the userprofile view directly into this
            //post method rather than landing on a creation screen at all - just click from userprofile link, do the save, and land on
            // the foodday index screen (NEED TO COPY THE TEMPDATACONTAINSKEYSAVERESULT CODE FROM INDEX VIEW) with a "your foodday was created" message - for failures, need to land on creation screen?
            //maybe there can't be failures since the user is not giving any input? the question will be, can i figure how to pass a
            //whole model from the userprofile link into this post method?
            //i might end up not end needing the foodday creation landing screen - you would always just pick a profile and select a date
            //those are the only parameters needed from the user - but then again, if the user isn't creating the foodday for today
            //how do i get the date parameter from them without a foodday creation landing page?
            {
                PopulateDateList();
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateFoodDayService();

            if (service.CreateFoodDayFromProfile(model))
            {
                TempData["SaveResult"] = "Your Food Day was created.";
                return(RedirectToAction("Index"));
            }
            ;

            PopulateDateList();

            ModelState.AddModelError("", "Your Food Day could not be created.");

            return(View(model));
        }