Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }