コード例 #1
0
        public ActionResult Edit(FullPersonViewModel fullPerson)
        {
            if (ModelState.IsValid)
            {
                PeopleDatabase.UpdateFullPerson(fullPerson);
                return(RedirectToAction("Index", "Home"));
            }

            //TODO: figure out how to send full model to web component, not just ID for it to load from.
            ViewBag.recordId = fullPerson.RecordId;
            return(View());
        }
コード例 #2
0
        public ActionResult JsonInfo(int recordId)
        {
            FullPersonViewModel myPerson = PeopleDatabase.GetOneFullPersonByRecordId(recordId) ?? new FullPersonViewModel
            {
                RecordId   = 0,
                Name       = "Not Found",
                Age        = 0,
                ContactPic = string.Empty,
                Role       = string.Empty,
                BlogPage   = string.Empty
            };

            return(Json(myPerson, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public static void UpdateFullPerson(FullPersonViewModel personDetails)
        {
            Mapper.CreateMap <FullPersonViewModel, Person>()
            .ForMember(dest => dest.RecordId, opt => opt.Ignore());

            using (var dataStore = new Store())
            {
                var originalRecord = dataStore.People.Find(personDetails.RecordId);

                if (originalRecord != null)
                {
                    originalRecord = Mapper.Map <FullPersonViewModel, Person>(personDetails, originalRecord);
                }

                dataStore.SaveChanges();
            }
        }