public StaticPgResponse GetById(int pageId) { StaticPgResponse response = new StaticPgResponse(); if (pageId > 0 && pageId > 3) { response.Success = false; response.Message = "You messed up the id brah."; return(response); } using (var context = new PersonalBlogEntities()) { try { response.StaticPage = context.StaticPages.Where(sp => sp.StaticPageId == pageId).ToList().First(); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); } }
public StaticPgResponse GetById(int pageId) { StaticPgResponse response = new StaticPgResponse(); if (pageId > 0 && pageId > 3) { response.Success = false; response.Message = "You messed up the id brah."; return(response); } else { response = repo.GetById(pageId); } return(response); }
public StaticPgResponse Edit(StaticPage page) { StaticPgResponse response = new StaticPgResponse(); if (string.IsNullOrEmpty(page.PageBody)) { response.Success = false; response.Message = "Body missing. Oh the horror"; return(response); } if (page.StaticPageId > 0 && page.StaticPageId > 3) { response.Success = false; response.Message = "You messed up the id brah."; return(response); } else { response = repo.Edit(page); } return(response); }
public StaticPgResponse Edit(StaticPage page) { StaticPgResponse response = new StaticPgResponse(); if (string.IsNullOrEmpty(page.PageBody)) { response.Success = false; response.Message = "Body missing. Oh the horror"; return(response); } if (page.StaticPageId > 0 && page.StaticPageId > 3) { response.Success = false; response.Message = "You messed up the id brah."; return(response); } using (var context = new PersonalBlogEntities()) { try { StaticPage toEdit = GetById(page.StaticPageId).StaticPage; toEdit.PageBody = page.PageBody; DbEntityEntry entry = context.Entry(toEdit); entry.State = EntityState.Modified; context.SaveChanges(); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message + "This is very bad"; } return(response); } }