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

                if (editedItem == null)
                {
                    var editedForm = AutoMapper.Mapper.Map <SuggestionEditForm>(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 <SuggestionEditForm>(newItem);
                ModelState.AddModelError("modelState", "There was an error. (The edited data could not be saved.)");
                return(View(editedForm));
            }
        }
예제 #2
0
        //#####################################################################
        //Suggestion
        public SuggestionBase EditSuggestion(SuggestionEdit newItem)
        {
            var fetchedObject = ds.Suggestions.Include("FollowUps").SingleOrDefault(a => a.Id == newItem.Id);

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

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