コード例 #1
0
        // GET: Birthday/Edit/5
        public ActionResult Edit(int id)
        {
            BirthdayTrackerDataAccess _birthdayTrackerDataAccess = new BirthdayTrackerDataAccess();

            var birthday       = _birthdayTrackerDataAccess.GetSingleSavedBirthday(id);
            var mappedBirthday = new BirthdayInputViewModel();

            mappedBirthday.BirthdayId = birthday.BirthdayId;
            mappedBirthday.FirstName  = birthday.FirstName;
            mappedBirthday.LastName   = birthday.LastName;
            mappedBirthday.BirthDay   = birthday.ConvertedDateTime.Day;
            mappedBirthday.BirthMonth = birthday.ConvertedDateTime.Month;
            mappedBirthday.BirthYear  = birthday.ConvertedDateTime.Year;


            return(View(mappedBirthday));
        }
コード例 #2
0
        public ActionResult Edit(int id, BirthdayInputViewModel birthdayInput)
        {
            BirthdayTrackerDataAccess _birthdayTrackerDataAccess = new BirthdayTrackerDataAccess();

            try
            {
                var mappedBirthday = new Birthday();
                mappedBirthday.FirstName         = birthdayInput.FirstName;
                mappedBirthday.LastName          = birthdayInput.LastName;
                mappedBirthday.ConvertedDateTime = new DateTime(birthdayInput.BirthYear, birthdayInput.BirthMonth, birthdayInput.BirthDay);

                _birthdayTrackerDataAccess.UpdateBirthday(mappedBirthday, id);

                TempData["Message"] = "Birthday Updated!!!";

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public ActionResult Create(BirthdayInputViewModel birthdayInput)
        {
            BirthdayTrackerDataAccess _birthdayTrackerDataAccess = new BirthdayTrackerDataAccess();

            try
            {
                var birthday = new Birthday();
                birthday.FirstName         = birthdayInput.FirstName;
                birthday.LastName          = birthdayInput.LastName;
                birthday.ConvertedDateTime = new DateTime(birthdayInput.BirthYear, birthdayInput.BirthMonth, birthdayInput.BirthDay);

                _birthdayTrackerDataAccess.SaveBirthday(birthday);

                TempData["Message"] = "Birthday Saved!!!";

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