public void UpdateServiceLog(string id, Rock.Core.DTO.ServiceLog ServiceLog) { 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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog existingServiceLog = ServiceLogService.Get(int.Parse(id)); if (existingServiceLog.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingServiceLog).CurrentValues.SetValues(ServiceLog); if (existingServiceLog.IsValid) { ServiceLogService.Save(existingServiceLog, currentUser.PersonId); } else { throw new WebFaultException <string>(existingServiceLog.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this ServiceLog", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiDeleteServiceLog(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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog ServiceLog = ServiceLogService.Get(int.Parse(id)); if (ServiceLog.Authorized("Edit", user)) { ServiceLogService.Delete(ServiceLog, user.PersonId); ServiceLogService.Save(ServiceLog, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this ServiceLog", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.Core.DTO.ServiceLog 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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog ServiceLog = ServiceLogService.Get(int.Parse(id)); if (ServiceLog.Authorized("View", user)) { return(ServiceLog.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this ServiceLog", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteServiceLog(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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog ServiceLog = ServiceLogService.Get(int.Parse(id)); if (ServiceLog.Authorized("Edit", currentUser)) { ServiceLogService.Delete(ServiceLog, currentUser.PersonId); ServiceLogService.Save(ServiceLog, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this ServiceLog", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateServiceLog(string apiKey, Rock.Core.DTO.ServiceLog ServiceLog) { 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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog existingServiceLog = new Rock.Core.ServiceLog(); ServiceLogService.Add(existingServiceLog, user.PersonId); uow.objectContext.Entry(existingServiceLog).CurrentValues.SetValues(ServiceLog); if (existingServiceLog.IsValid) { ServiceLogService.Save(existingServiceLog, user.PersonId); } else { throw new WebFaultException <string>(existingServiceLog.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.Core.DTO.ServiceLog 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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog ServiceLog = ServiceLogService.Get(int.Parse(id)); if (ServiceLog.Authorized("View", currentUser)) { return(ServiceLog.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this ServiceLog", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateServiceLog( string apiKey, Rock.Core.DTO.ServiceLog ServiceLog ) { 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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog existingServiceLog = new Rock.Core.ServiceLog(); ServiceLogService.Add( existingServiceLog, user.PersonId ); uow.objectContext.Entry(existingServiceLog).CurrentValues.SetValues(ServiceLog); if (existingServiceLog.IsValid) ServiceLogService.Save( existingServiceLog, user.PersonId ); else throw new WebFaultException<string>( existingServiceLog.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void CreateServiceLog( Rock.Core.DTO.ServiceLog ServiceLog ) { 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.Core.ServiceLogService ServiceLogService = new Rock.Core.ServiceLogService(); Rock.Core.ServiceLog existingServiceLog = new Rock.Core.ServiceLog(); ServiceLogService.Add( existingServiceLog, currentUser.PersonId ); uow.objectContext.Entry(existingServiceLog).CurrentValues.SetValues(ServiceLog); if (existingServiceLog.IsValid) ServiceLogService.Save( existingServiceLog, currentUser.PersonId ); else throw new WebFaultException<string>( existingServiceLog.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } }