public ActionResult Map(int id)
        {
           var catEntity = Context.Set<CategoryEntity>().Where(c => c.ExCatId == id && c.Status != (int)DataStatus.Deleted).FirstOrDefault();
           if (catEntity == null)
               throw new ArgumentException("id");
           var model = new CategoryViewModel().FromEntity<CategoryViewModel>(catEntity, p => {
               p.ShowCategories = new List<ShowCategoryViewModel>();
               foreach (var cmap in Context.Set<CategoryMapEntity>().Where(cm => cm.CatId == catEntity.ExCatId && cm.Status != (int)DataStatus.Deleted))
               {
                   p.ShowCategories.Add(new ShowCategoryViewModel() { 
                     ShowChannel = cmap.ShowChannel,
                      ShowCategoryId = cmap.ChannelCatId,
                       ShowCategoryName = Context.Set<TagEntity>().Find(cmap.ChannelCatId).Name,
                       Id = cmap.Id

             
                   });
                       
               }
           });
           return View(model);
        }
 public ActionResult Map(CategoryViewModel model)
 {
     if (!ModelState.IsValid) {
         return View(model);
     }
     foreach (var map in model.ShowCategories)
     {
         var entity = Context.Set<CategoryMapEntity>().Find(map.Id);
         if (entity == null && map.Status!=(int)DataStatus.Deleted)
         {
             _catmapRepo.Insert(new CategoryMapEntity()
             {
                 CatId = model.ExCatId,
                 ShowChannel = map.ShowChannel,
                  ChannelCatId= map.ShowCategoryId
                   
             });
         }
         else if (entity!=null && map.Status!=(int)DataStatus.Deleted)
         {
             entity.ChannelCatId = map.ShowCategoryId;
             entity.UpdateDate = DateTime.Now;
             _catmapRepo.Update(entity);
         }
         else if (entity != null)
         {
             entity.Status = (int)DataStatus.Deleted;
             entity.UpdateDate = DateTime.Now;
             _catmapRepo.Update(entity);
         }
     }
     return View("map", new { id = model.ExCatId });
 }