private static void SaveBanners(EditGroup editGroup, int groupID) { var curList = GroupBanners.GetByGroupID(groupID); foreach (var banner in editGroup.Banners) { if (!curList.Any(item => item.ID == banner.ID)) { var groupBanner = Mapper.Map <GroupBanner>(banner); groupBanner.GroupID = groupID; GroupBanners.Insert(groupBanner); } else { GroupBanners.UpdateGroupBannerType(banner.ID, banner.GroupBannerType); curList.Remove(curList.Single(cls => cls.ID == banner.ID)); } } foreach (var item in curList) { GroupBanners.Delete(item.ID); } }
public ActionResult Edit(int?id) { EditGroup group; if (id.HasValue) { group = Mapper.Map <EditGroup>(Groups.GetByID(id.Value)); group.Banners = GroupBanners.GetByGroupID(group.ID); } else { group = new EditGroup(); } return(View("/Areas/Admin/Views/Groups/Edit.cshtml", group)); }