public void UpdateDesign(LayoutEntity item) { if (item.Page != null && item.Page.ID.IsNotNullAndWhiteSpace()) { if (item.Zones != null) { var zones = _zoneService.GetByPage(new PageEntity { ID = item.Page.ID, LayoutId = item.ID }); item.Zones.Where(m => zones.All(n => n.ID != m.ID)).Each(m => { m.LayoutId = item.ID; m.PageId = item.Page.ID; _zoneService.Add(m); }); zones.Each(m => { var changeZone = item.Zones.FirstOrDefault(z => z.ID == m.ID); if (changeZone != null) { m.LayoutId = item.ID; m.PageId = item.Page.ID; m.Title = changeZone.Title; m.ZoneName = changeZone.ZoneName; _zoneService.Update(m); } }); zones.Where(m => item.Zones.All(n => n.ID != m.ID)).Each(m => _zoneService.Remove(m.ID)); } if (item.Html != null) { _layoutHtmlService.Remove(m => m.PageId == item.Page.ID); item.Html.Each(m => { m.LayoutId = item.ID; m.PageId = item.Page.ID; _layoutHtmlService.Add(m); }); } } else { if (item.Zones != null) { var zones = _zoneService.Get(m => m.LayoutId == item.ID); item.Zones.Where(m => zones.All(n => n.ID != m.ID)).Each(m => { m.LayoutId = item.ID; _zoneService.Add(m); }); zones.Each(m => { var changeZone = item.Zones.FirstOrDefault(z => z.ID == m.ID); if (changeZone != null) { m.LayoutId = item.ID; m.Title = changeZone.Title; m.ZoneName = changeZone.ZoneName; _zoneService.Update(m); } }); zones.Where(m => item.Zones.All(n => n.ID != m.ID)).Each(m => _zoneService.Remove(m.ID)); } if (item.Html != null) { _layoutHtmlService.Remove(m => m.LayoutId == item.ID); item.Html.Each(m => { m.LayoutId = item.ID; _layoutHtmlService.Add(m); }); } } }
public IHttpActionResult Get(int id) { return(Ok(_zoneService.Get(id))); }