public ActionResult Edit(int id, FollowUpEdit newItem)
        {
            //What is this single & means?
            if (ModelState.IsValid & id == newItem.Id)
            {
                var editedItem = m.EditFollowUp(newItem);

                if (editedItem == null)
                {
                    var editedForm = AutoMapper.Mapper.Map <FollowUpEditForm>(newItem);
                    ModelState.AddModelError("modelState", "There was an error. (The edited data could not be saved.)");
                    return(View(editedForm));
                }
                else
                {
                    return(RedirectToAction("details", new { id = editedItem.Id }));
                }
            }
            else
            {
                var editedForm = AutoMapper.Mapper.Map <FollowUpEditForm>(newItem);
                ModelState.AddModelError("modelState", "There was an error. (The edited data could not be saved.)");
                return(View(editedForm));
            }
        }
Beispiel #2
0
        public FollowUpBaseWithSuggestionAndImage EditFollowUp(FollowUpEdit newItem)
        {
            var fetchedObject = ds.FollowUps.Include("Suggestion").SingleOrDefault(a => a.Id == newItem.Id);

            if (fetchedObject == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(fetchedObject).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                return(Mapper.Map <FollowUpBaseWithSuggestionAndImage>(fetchedObject));
            }
        }