Ejemplo n.º 1
0
        public void ApiCreateNote( string apiKey, Rock.Core.DTO.Note Note )
        {
            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.NoteService NoteService = new Rock.Core.NoteService();
                    Rock.Core.Note existingNote = new Rock.Core.Note();
                    NoteService.Add( existingNote, user.PersonId );
                    uow.objectContext.Entry(existingNote).CurrentValues.SetValues(Note);

                    if (existingNote.IsValid)
                        NoteService.Save( existingNote, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingNote.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Ejemplo n.º 2
0
        public void CreateNote( Rock.Core.DTO.Note Note )
        {
            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.NoteService NoteService = new Rock.Core.NoteService();
                Rock.Core.Note existingNote = new Rock.Core.Note();
                NoteService.Add( existingNote, currentUser.PersonId );
                uow.objectContext.Entry(existingNote).CurrentValues.SetValues(Note);

                if (existingNote.IsValid)
                    NoteService.Save( existingNote, currentUser.PersonId );
                else
                    throw new WebFaultException<string>( existingNote.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
            }
        }