public static PageSchemaModel GetPageModel(PageSchema page) { if (page == null) return null; var result = new PageSchemaModel {Id = page.Id, IdPerson = page.IdPerson, IdEvent = page.IdEvent, IdHall = page.IdHall, PageType = (int)page.Page}; if (result.IdPerson != null) result.Person = PersonModelHelper.GetPersonModel(page.Person); if (result.IdEvent != null) result.Event = EventModelHelper.GetEventModel(page.Event); //TODO get Hall model return result; }
public static PageSchema GetPage(PageSchemaModel model) { if (model == null) return null; var result = new PageSchema { Id = model.Id, Page = (PageTypes?)model.PageType }; if (result.Page == PageTypes.Person) result.IdPerson = model.IdPerson; if (result.Page == PageTypes.Event) result.IdEvent = model.IdEvent; if (result.Page == PageTypes.Halls) result.IdHall = model.IdHall; return result; }
private PageSchema SavePage(PageSchema page) { if (page.Id == 0) { db.Entry(page).State = EntityState.Added; } else if (page.Id > 0) { var pr = db.PageSchemas.FirstOrDefault(o => o.Id == page.Id); db.Entry(pr).CurrentValues.SetValues(page); } try { db.SaveChanges(); } catch (Exception e) { return(null); } return(page); }