public void UpdateKeyword(KeywordDetailDTO item) { p1p.Data.Keyword mdlKeyword = (p1p.Data.Keyword)P1PObjectMapper.Convert(item, typeof(p1p.Data.Keyword)); p1p.Data.Keyword match; p1p.Data.ProjectKeywordXREF xmatch; p1p.Data.ProjectKeywordXREF newxref; p1p.Data.LandingPageKeywordXREF lpxmatch; p1p.Data.LandingPageKeywordXREF newlpxref; using (P1PContext ctx = new P1PContext()) { match = ctx.Keywords.Single(k => k.Id == item.Id); mdlKeyword.InsertDate = match.InsertDate; ctx.Entry(match).CurrentValues.SetValues(mdlKeyword); xmatch = ctx.ProjectKeywordXREFs.Single(x => x.KeywordId == item.Id); newxref = xmatch; newxref.KeywordPriority = item.ProjectPriority; if (item.LandingPagePriority != 0) { lpxmatch = ctx.LandingPageKeywordXREFs.FirstOrDefault(l => l.KeywordId == item.Id && l.LandingPageId == item.LandingPageId); if (lpxmatch != null) { newlpxref = lpxmatch; newlpxref.KeywordPriority = item.LandingPagePriority; ctx.Entry(lpxmatch).CurrentValues.SetValues(newlpxref); } } ctx.SaveChanges(); } }
//TODO Don't get the ID, get the whole team and use only the ID if you need it. This is not very reusable public int GetIdByUser(string user) { EmployeeTeamXREF xref; Employee employee; int id; int teamId; using (P1PContext ctx = new P1PContext()) { employee = ctx.Employees.FirstOrDefault(e => e.Username.Equals(user)); if (employee != null) { id = employee.Id; } else { id = 0; } xref = ctx.EmployeeTeamXREFs.FirstOrDefault(x => x.EmployeeId == id); } if (xref != null) { teamId = xref.TeamId; } else { teamId = 0; } return(teamId); }
public List <LandingPageDTO> GetLandingPagesForProject(int projectId) { using (P1PContext ctx = new P1PContext()) { return((from x in ctx.ProjectLandingPageXREFs where x.ProjectId == projectId select x.LandingPage) .AsEnumerable() .Select(l => (LandingPageDTO)P1PObjectMapper.Convert(l, typeof(LandingPageDTO))).ToList <LandingPageDTO>()); } }
public List <SocialAccountDTO> GetSocialAccountsForPersona(int personaId) { using (P1PContext ctx = new P1PContext()) { return((from x in ctx.PersonaSocialAccountXREFs where x.PersonaId == personaId select x.SocialAccount) .AsEnumerable() .Select(s => (SocialAccountDTO)P1PObjectMapper.Convert(s, typeof(SocialAccountDTO))).ToList <SocialAccountDTO>()); } }
public List <PersonaDTO> GetPersonasForProject(int projectId) { using (P1PContext ctx = new P1PContext()) { return((from x in ctx.ProjectPersonaXREFs where x.ProjectId == projectId select x.Persona) .AsEnumerable() .Select(p => (PersonaDTO)P1PObjectMapper.Convert(p, typeof(PersonaDTO))).ToList <PersonaDTO>()); } }
public List <KeywordDTO> GetKeywordsForLandingPage(int landingPageId) { using (P1PContext ctx = new P1PContext()) { return((from x in ctx.LandingPageKeywordXREFs where x.LandingPageId == landingPageId select x.Keyword) .AsEnumerable() .Select(k => (KeywordDTO)P1PObjectMapper.Convert(k, typeof(KeywordDTO))).ToList <KeywordDTO>()); } }
public void RemoveKeywordFromLandingPage(int landingPageId, int keywordId) { LandingPageKeywordXREF xref; using (P1PContext ctx = new P1PContext()) { xref = ctx.LandingPageKeywordXREFs.FirstOrDefault(x => x.LandingPageId == landingPageId && x.KeywordId == keywordId); ctx.LandingPageKeywordXREFs.Remove(xref); ctx.SaveChanges(); } }
public void UpdateProfile(CustomerDTO customer) { Customer cust = (Customer)P1PObjectMapper.Convert(customer, typeof(Customer)); using (P1PContext ctx = new P1PContext()) { Customer match = ctx.Customers.Single(c => c.Username.Equals(cust.Username)); ctx.Entry(match).CurrentValues.SetValues(cust); ctx.SaveChanges(); } }
public void UpdatePersona(PersonaDTO item) { p1p.Data.Persona mdlPersona = (p1p.Data.Persona)P1PObjectMapper.Convert(item, typeof(p1p.Data.Persona)); p1p.Data.Persona match; using (P1PContext ctx = new P1PContext()) { match = ctx.Personas.Single(p => p.Id == mdlPersona.Id); mdlPersona.InsertDate = match.InsertDate; ctx.Entry(match).CurrentValues.SetValues(mdlPersona); ctx.SaveChanges(); } }
public void UpdateSocialAccount(SocialAccountDTO item) { p1p.Data.SocialAccount mdlAccount = (p1p.Data.SocialAccount)P1PObjectMapper.Convert(item, typeof(p1p.Data.SocialAccount)); p1p.Data.SocialAccount match; using (P1PContext ctx = new P1PContext()) { match = ctx.SocialAccounts.Single(s => s.Id == mdlAccount.Id); mdlAccount.InsertDate = match.InsertDate; ctx.Entry(match).CurrentValues.SetValues(mdlAccount); ctx.SaveChanges(); } }
public ProjectDTO RemoveCategoryFromProject(int projectId, int categoryId) { OrderCategoryXREF xref; using (P1PContext ctx = new P1PContext()) { xref = ctx.OrderCategoryXREFs.Single(x => x.CategoryId == categoryId && x.ProjectId == projectId); ctx.OrderCategoryXREFs.Remove(xref); ctx.SaveChanges(); } return(GetProject(projectId)); }
public TeamDTO GetByUser(string username) { using (P1PContext ctx = new P1PContext()) { return((from e in ctx.Employees join t in ctx.EmployeeTeamXREFs on e.Id equals t.EmployeeId where e.Username.Equals(username) select t.Team) .AsEnumerable() .Select(t => (TeamDTO)P1PObjectMapper.Convert(t, typeof(TeamDTO))).FirstOrDefault()); } }
public void DeletePersonaSocialAccount(int socialAccountId) { p1p.Data.SocialAccount acct; p1p.Data.PersonaSocialAccountXREF xref; using (P1PContext ctx = new P1PContext()) { xref = ctx.PersonaSocialAccountXREFs.FirstOrDefault(x => x.SocialAccountId == socialAccountId); ctx.PersonaSocialAccountXREFs.Remove(xref); acct = ctx.SocialAccounts.FirstOrDefault(a => a.Id == socialAccountId); ctx.SocialAccounts.Remove(acct); ctx.SaveChanges(); } }
public ProjectDTO AddCategoryToProject(int projectId, int categoryId) { p1p.Data.OrderCategoryXREF x = new OrderCategoryXREF() { ProjectId = projectId, CategoryId = categoryId }; using (P1PContext ctx = new P1PContext()) { ctx.OrderCategoryXREFs.Add(x); ctx.SaveChanges(); } return(GetProject(projectId)); }
public void AddPersona(PersonaDetailDTO item) { p1p.Data.Persona newPersona; p1p.Data.Persona mdlPersona = (p1p.Data.Persona)P1PObjectMapper.Convert(item, typeof(p1p.Data.Persona)); mdlPersona.InsertDate = DateTime.Now; using (P1PContext ctx = new P1PContext()) { newPersona = ctx.Personas.Add(mdlPersona); ctx.ProjectPersonaXREFs.Add(new ProjectPersonaXREF() { ProjectId = item.ProjectId, PersonaId = newPersona.Id, InsertDate = DateTime.Now }); ctx.SaveChanges(); } }
public void AddPersonaSocialAccount(SocialAccountDetailDTO item) { p1p.Data.SocialAccount newSocialAccount; p1p.Data.SocialAccount mdlSocialAccount = (p1p.Data.SocialAccount)P1PObjectMapper.Convert(item, typeof(p1p.Data.SocialAccount)); mdlSocialAccount.InsertDate = DateTime.Now; using (P1PContext ctx = new P1PContext()) { newSocialAccount = ctx.SocialAccounts.Add(mdlSocialAccount); ctx.PersonaSocialAccountXREFs.Add(new PersonaSocialAccountXREF() { PersonaId = item.PersonaId, SocialAccountId = newSocialAccount.Id, InsertDate = DateTime.Now }); ctx.SaveChanges(); } }
public void AddKeywordToLandingPage(int landingPageId, int keywordId, int priority) { using (P1PContext ctx = new P1PContext()) { if (ctx.LandingPageKeywordXREFs.FirstOrDefault(x => x.KeywordId == keywordId && x.LandingPageId == landingPageId) == null) { ctx.LandingPageKeywordXREFs.Add(new LandingPageKeywordXREF() { LandingPageId = landingPageId, KeywordId = keywordId, InsertDate = DateTime.Now, KeywordPriority = priority }); ctx.SaveChanges(); } } }
public void UpdateLandingPage(LandingPageDTO item) { p1p.Data.LandingPage mdlLandingPage = (p1p.Data.LandingPage)P1PObjectMapper.Convert(item, typeof(p1p.Data.LandingPage)); p1p.Data.LandingPage match; p1p.Data.ProjectLandingPageXREF xmatch; p1p.Data.ProjectLandingPageXREF newxref; using (P1PContext ctx = new P1PContext()) { match = ctx.LandingPages.Single(l => l.Id == item.Id); mdlLandingPage.InsertDate = match.InsertDate; ctx.Entry(match).CurrentValues.SetValues(mdlLandingPage); xmatch = ctx.ProjectLandingPageXREFs.Single(x => x.LandingPageId == item.Id); newxref = xmatch; newxref.LandingPagePriority = item.Priority; ctx.Entry(xmatch).CurrentValues.SetValues(newxref); ctx.SaveChanges(); } }
public void AddKeyword(KeywordDetailDTO item) { p1p.Data.Keyword newKeyword; p1p.Data.Keyword mdlKeyword = (p1p.Data.Keyword)P1PObjectMapper.Convert(item, typeof(p1p.Data.Keyword)); mdlKeyword.InsertDate = DateTime.Now; using (P1PContext ctx = new P1PContext()) { newKeyword = ctx.Keywords.Add(mdlKeyword); ctx.ProjectKeywordXREFs.Add(new ProjectKeywordXREF() { ProjectId = item.ProjectId, KeywordId = newKeyword.Id, KeywordPriority = item.ProjectPriority, InsertDate = DateTime.Now }); ctx.SaveChanges(); } }
public void AddLandingPage(LandingPageDetailDTO item) { p1p.Data.LandingPage newLandingPage; p1p.Data.LandingPage mdlLandingPage = (p1p.Data.LandingPage)P1PObjectMapper.Convert(item, typeof(p1p.Data.LandingPage)); mdlLandingPage.InsertDate = DateTime.Now; using (P1PContext ctx = new P1PContext()) { newLandingPage = ctx.LandingPages.Add(mdlLandingPage); ctx.ProjectLandingPageXREFs.Add(new ProjectLandingPageXREF() { ProjectId = item.ProjectId, LandingPageId = newLandingPage.Id, LandingPagePriority = item.Priority, InsertDate = DateTime.Now }); ctx.SaveChanges(); } }
public void DeletePersona(int personaId) { p1p.Data.Persona persona; p1p.Data.ProjectPersonaXREF pxref; List <p1p.Data.PersonaSocialAccountXREF> xrefs; using (P1PContext ctx = new P1PContext()) { persona = ctx.Personas.Single(p => p.Id == personaId); xrefs = ctx.PersonaSocialAccountXREFs.Where(x => x.PersonaId == personaId).ToList <p1p.Data.PersonaSocialAccountXREF>(); foreach (PersonaSocialAccountXREF x in xrefs) { ctx.PersonaSocialAccountXREFs.Remove(x); } pxref = ctx.ProjectPersonaXREFs.Single(p => p.Id == personaId); ctx.ProjectPersonaXREFs.Remove(pxref); ctx.Personas.Remove(persona); ctx.SaveChanges(); } }
public List <KeywordDTO> GetKeywordsForLandingPages(int projectId) { List <LandingPageKeywordXREF> xrefs; List <KeywordDTO> keywords = new List <KeywordDTO>(); using (P1PContext ctx = new P1PContext()) { xrefs = (from xl in ctx.ProjectLandingPageXREFs where xl.ProjectId == projectId join xk in ctx.LandingPageKeywordXREFs on xl.LandingPageId equals xk.LandingPageId select xk).ToList <LandingPageKeywordXREF>(); foreach (LandingPageKeywordXREF x in xrefs) { keywords.Add(new KeywordDTO() { Id = x.Keyword.Id, LandingPageId = x.LandingPageId, LandingPagePriority = x.KeywordPriority, Text = x.Keyword.Text }); } return(keywords); } }
public void DeleteKeyword(int keywordId) { p1p.Data.Keyword keyword; List <p1p.Data.LandingPageKeywordXREF> lxrefs; p1p.Data.ProjectKeywordXREF pxref; using (P1PContext ctx = new P1PContext()) { keyword = ctx.Keywords.Single(k => k.Id == keywordId); pxref = ctx.ProjectKeywordXREFs.Single(x => x.KeywordId == keywordId); lxrefs = (from x in ctx.LandingPageKeywordXREFs where x.KeywordId == keywordId select x).ToList <LandingPageKeywordXREF>(); if (lxrefs.Count > 0) { foreach (LandingPageKeywordXREF x in lxrefs) { ctx.LandingPageKeywordXREFs.Remove(x); } } ctx.ProjectKeywordXREFs.Remove(pxref); ctx.Keywords.Remove(keyword); ctx.SaveChanges(); } }
public void DeleteLandingPage(int landingPageId) { p1p.Data.LandingPage landingPage; p1p.Data.ProjectLandingPageXREF pxref; List <p1p.Data.LandingPageKeywordXREF> kxrefs; using (P1PContext ctx = new P1PContext()) { landingPage = ctx.LandingPages.Single(l => l.Id == landingPageId); pxref = ctx.ProjectLandingPageXREFs.Single(x => x.LandingPageId == landingPageId); kxrefs = (from x in ctx.LandingPageKeywordXREFs where x.LandingPageId == landingPageId select x).ToList <LandingPageKeywordXREF>(); if (kxrefs.Count > 0) { foreach (LandingPageKeywordXREF x in kxrefs) { ctx.LandingPageKeywordXREFs.Remove(x); } } ctx.ProjectLandingPageXREFs.Remove(pxref); ctx.LandingPages.Remove(landingPage); ctx.SaveChanges(); } }