public void UpdatePersonViewed(string id, Rock.CRM.DTO.PersonViewed PersonViewed) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed existingPersonViewed = PersonViewedService.Get(int.Parse(id)); if (existingPersonViewed.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingPersonViewed).CurrentValues.SetValues(PersonViewed); if (existingPersonViewed.IsValid) { PersonViewedService.Save(existingPersonViewed, currentUser.PersonId); } else { throw new WebFaultException <string>(existingPersonViewed.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this PersonViewed", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.CRM.DTO.PersonViewed ApiGet(string id, string apiKey) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed PersonViewed = PersonViewedService.Get(int.Parse(id)); if (PersonViewed.Authorized("View", user)) { return(PersonViewed.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this PersonViewed", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeletePersonViewed(string id) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed PersonViewed = PersonViewedService.Get(int.Parse(id)); if (PersonViewed.Authorized("Edit", currentUser)) { PersonViewedService.Delete(PersonViewed, currentUser.PersonId); PersonViewedService.Save(PersonViewed, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this PersonViewed", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreatePersonViewed(string apiKey, Rock.CRM.DTO.PersonViewed PersonViewed) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed existingPersonViewed = new Rock.CRM.PersonViewed(); PersonViewedService.Add(existingPersonViewed, user.PersonId); uow.objectContext.Entry(existingPersonViewed).CurrentValues.SetValues(PersonViewed); if (existingPersonViewed.IsValid) { PersonViewedService.Save(existingPersonViewed, user.PersonId); } else { throw new WebFaultException <string>(existingPersonViewed.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreatePersonViewed( string apiKey, Rock.CRM.DTO.PersonViewed PersonViewed ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed existingPersonViewed = new Rock.CRM.PersonViewed(); PersonViewedService.Add( existingPersonViewed, user.PersonId ); uow.objectContext.Entry(existingPersonViewed).CurrentValues.SetValues(PersonViewed); if (existingPersonViewed.IsValid) PersonViewedService.Save( existingPersonViewed, user.PersonId ); else throw new WebFaultException<string>( existingPersonViewed.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public Rock.CRM.DTO.PersonViewed Get(string id) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed PersonViewed = PersonViewedService.Get(int.Parse(id)); if (PersonViewed.Authorized("View", currentUser)) { return(PersonViewed.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this PersonViewed", System.Net.HttpStatusCode.Forbidden); } } }
public void CreatePersonViewed( Rock.CRM.DTO.PersonViewed PersonViewed ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.PersonViewedService PersonViewedService = new Rock.CRM.PersonViewedService(); Rock.CRM.PersonViewed existingPersonViewed = new Rock.CRM.PersonViewed(); PersonViewedService.Add( existingPersonViewed, currentUser.PersonId ); uow.objectContext.Entry(existingPersonViewed).CurrentValues.SetValues(PersonViewed); if (existingPersonViewed.IsValid) PersonViewedService.Save( existingPersonViewed, currentUser.PersonId ); else throw new WebFaultException<string>( existingPersonViewed.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } }