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