Forum Moderators: open
/// <summary>
/// this class contains all of the data for the cateogry data it also handles the error detection and correction
/// </summary>
public class CategoryViewModel
{
public int categoryId { get; set; }
[Required(ErrorMessage="Please enter a category name")]
public string categoryName { get; set; }
[Required(ErrorMessage = "Please select a category type")]
public int? categoryType { get; set; }
[Required(ErrorMessage = "No parent category")]
public Dictionary<int, string>parentCategory { get; set; }
[Required(ErrorMessage = "Please select a category color")]
public string color { get; set; }
[Required(ErrorMessage = "Please enter a category order")]
public int? order { get; set; }
public bool deleted { get; set; }
public string message { get; set; }
}//CategoryViewModel
public ActionResult Edit(int id)
{
var category = DataAccess.GetCategoryById(id);
var allCats = DataAccess.GetActiveCategories();
CategoryViewModel cat = new CategoryViewModel
{
categoryName = category.Name,
categoryType = category.CategoryType,
order = category.sortOrder,
parentCategory = allCats.Where(c=> c.CategoryId != id).ToDictionary(x => x.CategoryId, y => y.Name),
color = category.color
};
if (category == null)
{
return View("NotFound");
}//if
else
{
return View(cat);
}//if category == null
}//Edit
AutoMapper.Mapper.Map(Category, CategoryViewModel);
Mapper.CreateMap<Category, CategoryViewModel>().ForMember(c => c.parentCategory = allCats.Where(c=> c.CategoryId != id).ToDictionary(x => x.CategoryId, y => y.Name);