public CategoryViewModelForAddEditView GetCategoryWithCategorys(int? Id)
{
CategoryViewModelForAddEditView categoryView = new CategoryViewModelForAddEditView();
if (Id == null)
{
//для возможности не выбирать категорию
Category noCategory = new Category { CategoryId = 0, Name = "------------Отсутствует----------", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now };
var listCategorys = categoryRepository.Get().ToList<Category>();
listCategorys.Add(noCategory);
categoryView.Categorys = new SelectList(listCategorys, "CategoryId", "Name", 0);
}
else
{
var category = categoryRepository.Get(Id.Value);
if (category != null)
{
categoryView = ConvertToCategoryViewModelForAddEditView(category);
//для возможности не выбирать категорию
Category noCategory = new Category { CategoryId = 0, Name = "------------Отсутствует----------", Active = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now };
var listCategorys = categoryRepository.Get().ToList<Category>();
listCategorys.Add(noCategory);
listCategorys.Remove(category);
categoryView.Categorys = new SelectList(listCategorys, "CategoryId", "Name", 0);
}
}
return categoryView;
}