private UserPageCategory SaveUserPageCategory(UserPageCategory cat) { if (cat == null) { return(null); } if (cat.Id == 0) { db.Entry(cat).State = EntityState.Added; } else if (cat.Id > 0) { var pr = db.UserPageCategories.FirstOrDefault(o => o.Id == cat.Id); db.Entry(pr).CurrentValues.SetValues(cat); } else { return(null); } try { db.SaveChanges(); } catch (Exception e) { return(null); } return(cat); }
/// <see cref="IEventRepository.SaveDescriptionSchema" /> public bool SaveDescriptionSchema(int id, PageBlock pageBlock, UserPageCategory cat, int eventId) { cat = SaveUserPageCategory(cat); var page = SavePage(pageBlock.Page); if (page == null) { return(false); } pageBlock.IdPage = page.Id; var pageblock = SavePageBlock(pageBlock); if (pageblock == null) { return(false); } var desc = db.EventDescriptions.FirstOrDefault(o => o.Id == id); if (desc == null) { desc = new EventDescription { IdType = 1, IdEvent = eventId }; db.Entry(desc).State = EntityState.Added; } desc.IdBlock = pageblock.Id; desc.IdUserPageCategory = cat?.Id; try { db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }